Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Point light cast no shadow?

ddabrahim
Registered User
Quote
2017-12-24 00:00:06

Hi.

I'm trying to do a day 'n night cycle in my level and I figured the most simple way would be if I would circle the light object around the terrain. But moving around the terrain seems to have no effect on the directional light. Regardless where the direction light is in 3D space, it doesn't actually effect the lighting in the scene. or direction of the shadows.

I tried then rotating the scene node but it didn't change anything either.

What I haven't tried yet is to rotate the actual light by changing the direction of the light but I don't know yet how to do that since rotating the scene node does not actually seem to change the direction of the light.

So I decided to try to do the same thing using a point light. It is working as far as day 'n night cycle goes but it doesn't cast shadows. I set the light to dynamic, but nothing.

Anyone could help me please with either cast shadow with point light or change direction of directional light? How would you go about making a day and night cycle?

Thanks.


techno-valley
Registered User
Quote
2017-12-24 00:19:33

Did you try the Day/Night cycle Script under the Scripted Actions, Behaviors and Plugins for CopperCube ?

http://www.ambiera.com/coppercub...

You may check this thread below as well :

http://www.ambiera.com/forum.php...


ddabrahim
Registered User
Quote
2017-12-24 00:28:11

No, I haven't tried the plugin. Thanks for mentioning. I'll give it a try but I would like to do as much as possible from scratch so I have a better understanding of how everything works and have full control.

For example, I tried to use this code to change the direction property of the light but it doesn't work:

var sun = ccbGetSceneNodeFromName("sun");

var direction = ccbGetSceneNodeProperty(sun, "Direction");
direction += 10;

ccbSetSceneNodeProperty(sun, "Direction", direction);


I get no error message, so in theory everything is fine but the shadows doesn't change :(

I'm not sure what else I can try, the plugin is nice thanks again, but I would like to find a solution to this.


ddabrahim
Registered User
Quote
2017-12-24 00:34:41

Ah, okay, now I have something. The direction property actually returning Vec3 with that in mind, this code sort of works:

var sun = ccbGetSceneNodeFromName("sun");

var direction = ccbGetSceneNodeProperty(sun, "Direction");
direction.x += 0.01;

ccbSetSceneNodeProperty(sun, "Direction", direction.x, direction.y, direction.z);


But once it get dark, it remain dark. So the light doesn't actually seem to rotate around on the X axis as I hoped...

I'm trying to debug what is going on by displaying the value of direction.x but I cannot. I tried alert(), console.log() but it is not displaying.

Anyone could tell me please how to display something in the CopperCube debug window?

Thanks


ddabrahim
Registered User
Quote
2017-12-24 01:27:44

Ok
To print something in to the debug window I can use the print() command, but with the direction of the light I don't really understand what is happening. According to print(direction.x), the light is rotating on the x axis from -0.2 up to 1.01 and then stop. I tried to work around with this code:


var sun = ccbGetSceneNodeFromName("sun");

var direction = ccbGetSceneNodeProperty(sun, "Direction");
if(direction.x <= 1.0){direction.x += 0.01}

ccbSetSceneNodeProperty(sun, "Direction", direction.x, direction.y, direction.z);

if(direction.x >1.0){ direction.x = -0.2}
print(direction.x);


But the only thing happening the light rotate from -0.2 up to 1.0 and than change to -0.2 and stop. I can't figure out why is the light stop rotating :(

So I'm not too sure what is happening here.

I would appreciate any help.
Thanks.


ddabrahim
Registered User
Quote
2017-12-24 01:49:56

I tried the plugin, it doesn't work on Windows, I get an error message in the debug window saying Direction and Color properties does not exist while in WebGL seems to work, though the shadows does not look exactly as I would like it. I want it to sort of rotate as the sun raise and rest.
But it a good starting point to see how niko done it.

Thanks for the link and the plugin.

EDIT:// solved the problem on Windows by renaming the light, apparently it seems like the engine does not like it if the name is between () :)

Looks great, I only need to figure out now why is the plugin works and why my code is not :P


techno-valley
Registered User
Quote
2017-12-24 09:00:54

You did a a great efforts !

I've tried your code, and i can see some minor errors that might be due to the case sensitivity, so:

1. Always make sure what is your object name in the editor
2. Use the Properties as it appears exactly so 'Direction' not 'direction' :)

I've re-modified your script so that you may give it a try.


var sun = ccbGetSceneNodeFromName("Sun");

var Direction = ccbGetSceneNodeProperty(sun, "Direction");
Direction.x += 0.01;

if(Direction.x <= 1.0)
{
Direction.x += 0.01
} else if (Direction.x > 1.0)
{
Direction.x = -0.2
}
ccbSetSceneNodeProperty(sun, "Direction", Direction.x, Direction.y, Direction.z);

print(Direction.x);


Hints :
- As you did before always use print to follow variables and statuses. You can also use the alert command only in the editor.
- Always variables are case sensitive in JavaScript
- You can use the Notepad++ editor and adapt it under language menu to show JavaScript format this will be very helpful





ddabrahim
Registered User
Quote
2017-12-24 12:55:46

Thanks a lot for the code and the hints :)

Though, I was not sure why is you code working so I reverted your code slowly piece by piece back in to my version and it seems like the problem was that I used my if statement after setting the Direction property of the Node.

I'm not sure why maybe it got something to do with the scopes in JS that I don't understand fully to be honest, but it seems like if I was using both if statement before I set the Direction property of the node it is solved the problem on it own:

if(direction.x <= 1.0) {direction.x += 0.01} 
if(direction.x > 1.0) {direction.x = -0.2}
ccbSetSceneNodeProperty(sun, "Direction", direction.x, direction.y, direction.z);


I know using if-elseif is more cleaner but I was just curious why.
But, It is solved the problem only on Windows.

In WebGL I get this error message in the console:
XML Parsing Error: not well-formed
Location: http://....../Temp/copperlichtdata/coppercube.ccbjs
Line Number 1, Column 530:
coppercube.ccbjs:1:530
Error: NaN


And the scene is dark right from the start.
Any idea why that is?


techno-valley
Registered User
Quote
2017-12-25 05:31:09


Though, I was not sure why is you code working so I reverted your code slowly piece by piece back in to my version and it seems like the problem was that I used my if statement after setting the Direction property of the Node.


I think you're right

Regarding the problem while using the WebGL, did you try to clear the cache and remove the older output files ?

Did you check the syntax in line 1 column 530 ?

Are you using the simple output HTML file generated by CopperCube?


ddabrahim
Registered User
Quote
2017-12-25 15:21:42

Hi.

Yes, I have cleared the cache and deleted the old files
Unfortunately, I can't check the syntax at line 1 because the file is encrypted I guess, if I open it this is what I see:
ZmxjZTA1NjAAAAAAAQALTRoA7AMEAAAAAAAAABQAMwEAAAIAAAAXAAAAQ29wcGVyQ3ViZSBU


Yes I'm using the HTML generated by CC.
I have solved the error with copperlicht.js
Error: ma/< http://....copperlicht.js:6:254

By removing the print() command from the code, it seems not being supported by copperlicht.

But I could not figure out what is wrong with changing the direction of the light, niko seems to be using the same methods to get and set the Direction property in the day 'n night behaviour so I have no clue. Maybe it got something to do with scopes again, I hate scopes it always mess me up.
It also could be an error with the XML parser as the error is coming from there. Maybe nothing wrong with the code at line 1 only the parser is bugged...


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inte?national" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact