light on a cube made up of plane

Software: Away3D 4.x

Hikkyu, Newbie
Posted: 19 February 2015 09:59 PM   Total Posts: 11

Hello everyone smile

I have some (big) difficulties to add light to my animation

Each cube’s face is a plane with his own texture, here, an example :

texture = new TextureMaterial(Cast.bitmapTexture(Ttop));
 
texture.specularMap Cast.bitmapTexture(light);
 
face1 =  new Mesh(faceGeometrytexture );
 
face1.scaleX size;
 
face1.scaleZ size;
 
face1.rotationX 0;
 
face1.size 1.5

(light and top are .gif)
and here, the light’s code :

dLight = new DirectionalLight();
 
dLight.direction = new Vector3D(0, -10);
 
dLight.color 0xFFFFFF;
 
dLight.ambient 0.1;
 
dLight.diffuse 0.7;
   
 
scene.addChild(dLight); 

Result : nothing,no light, no shadow :/

each plane is added on a ObjectContainer3D.

My questions :
- Have i add light on my ObjectContainer3D?
- Is there an error in my code? If yes, where is it?

I will be very grateful if you help me m(_ _)m

Thanks in advance (not the gameboy)

Hikkyu

   

Pierce, Jr. Member
Posted: 19 February 2015 11:28 PM   Total Posts: 40   [ # 1 ]

you have to specifically assign the light to the objects it is meant to affect. lights actually affect the material of a mesh, so on your texturematerial add a staticlightpicker with the light assigned to it. look at the materialBase class in the documentation for the lightpicker property.

 

   

Hikkyu, Newbie
Posted: 19 February 2015 11:42 PM   Total Posts: 11   [ # 2 ]

Thank for response smile

If i understand, i add a lightpicker to each faces.

Just, one more question :

The light is defined in an other file (main.as) and the cube is an object called in main.as.

I need a light that follow a camera rotating around my cube (Depending on the position of the mouse, the rotation is more or less fast).

Will the solution you proposed be compatible with my problem.

I join my current animation, you will have a global vision of it.

again, thank a lot m(_ _)m

 

File Attachments
cube.swf  (File Size: 308KB - Downloads: 193)
   

Pierce, Jr. Member
Posted: 19 February 2015 11:56 PM   Total Posts: 40   [ # 3 ]

create one lightpicker with your light assigned to it. assign that lightpicker to every material you want the light to affect. in the scene, parent the light to the camera to keep their relationship fixed.

 

   

Hikkyu, Newbie
Posted: 19 February 2015 11:58 PM   Total Posts: 11   [ # 4 ]

you’re the best dude *-*

i’ll test that tomorow !

Thank you !

 

   

Pierce, Jr. Member
Posted: 20 February 2015 12:12 AM   Total Posts: 40   [ # 5 ]

no problem. oh and on a usability note, you might try reversing the direction of the rotations. currently you have to move the mouse in the opposite direction of the face you want and then move back to click it. if it’s intended for touch screens that works really well, or if you have to hold the mouse down to rotate. for just a mouse though, it could be preferable to invert the rotations so that rather than rolling the cube with the mouse, the nearest face seems to seeks out the mouse and rotate to the front. that way you can select the face you want as soon as it comes into view. just something to play with, maybe you can try it and see how it feels.

 

   

Hikkyu, Newbie
Posted: 01 March 2015 04:05 PM   Total Posts: 11   [ # 6 ]

Hello and thanks a lot smile

 

   

Hikkyu, Newbie
Posted: 01 March 2015 04:13 PM   Total Posts: 11   [ # 7 ]

Hello, it’s me, again ^^’

I managed to lighten the cube one week later, thanks Pierce.

I am trying currently to make light follow the position and direction of the camera, without success…

A hoverController is used and the light is a direction light. I’ve tested to get x,y and z of the hoverController, the forwardVector, to set a vector3D with the cosinus and sinus of the current angle, without good result…

Can someone tell me what is the best way to resolve my problem? I follow some tutorials but no one helped me u_u

Light instanciation :

dLight = new DirectionalLight();
dLight.direction = new Vector3D(1,0,1);
dLight.color 0xFFFFFF;
dLight.ambient 0.7;
dLight.diffuse =0.7;
dLight.specular 0

definition of the position (without my test, just actual render) :

private function render(e:Event):void{
     
var vitesse 0.015;
      var 
X:Number mouseX stage.stageWidth 0.5;
   var 
Y:Number mouseY stage.stageHeight 0.5;
   
dLight.direction = new Vector3D(Math.sin(getTimer()/750)*2000001000Math.cos(getTimer()/750)*200000);
   if(
rotate)
   
{
    degY 
+= int(X*vitesse);
    
degX += int(Y*vitesse);
    if(
cameraController.tiltAngle 55 || cameraController.tiltAngle < -345)
    
{
     degX 
-= int(Y*vitesse);
     
Y=0;
    
}
    
else if(cameraController.tiltAngle 345 || cameraController.tiltAngle < -55)
    
{
     degX 
-= int(Y*vitesse);
     
Y=0;
    
}
    
    cameraController
.panAngle += int(X*vitesse);//rotateX
    
cameraController.tiltAngle += int(Y*vitesse);//rotateY
         //dLight.directi 
    
if(cameraController.distance 2500)
    
{
     cameraController
.distance += 25;
     
camera.lens.far +=25;
    
}
   }
   else{
   
if(cameraController.distance 2000)
    
{
     cameraController
.distance -= 25;
     
camera.lens.far -=25;
    
}
   }
   view
.render();
      

Thanks for reading smile

 

File Attachments
Cube.swf  (File Size: 231KB - Downloads: 218)
   

Pierce, Jr. Member
Posted: 01 March 2015 09:13 PM   Total Posts: 40   [ # 8 ]

It’s very unclear what you are trying to accomplish. It seems that you want the directional source of light to be revolving around the cube. Are you trying to alter the axis of revolution to be at a fixed angle to the camera? It’s also difficult to tell exactly what direction the light is pointing in. It seems like the normals of the corners are reversed or you are rendering their back faces, as they are brighter when the surrounding edges and faces are darker.

To get more help and to help yourself, we all need a clearer picture of what is really happening in the scene. The first thing I suggest you do while working on this is to soften/blend all your normals and add specularity to the light. By rounding out the surfaces the precise direction of the light and correct interaction with all the faces should be much clearer. The second thing I suggest is that you use some physical object to represent the direction/“position” of the light in the scene. You can do this by using an unlit, textured (or colored and wireframed) cone positioned at the center of your cube, align it with the direction of the light, slide it backwards along it’s local axis by a fixed amount slightly greater than the radius of your cube, render, and then reposition it to the center every frame. You could additionally use a very short cylinder with a radius matching the distance of the cone to represent a circular plane perpendicular to the axis you want your light source to revolve around. If everything works correctly, then the orientation of the cylinder will always be fixed in relation to either the camera or the cube (whichever you are trying to do), and the cone should always be bisected by the cylinder as it revolves around its edge. If these geometric guidelines and the apparent light source aren’t matching up or behaving how you want, then you can ignore the light itself and instead focus on getting your guides to move correctly, and then work backwards by setting the transform of the light based on the guides.

I expect that by doing this you will be able to see in detail exactly how the light is behaving and accordingly work it out for yourself, but if not, and it comes down to needing maths help or something that you’ve hit a wall with, everyone else can see precisely what is happening, and you will have some visual touchstones to communicate the behavior you want to see but are not getting. With a clear idea of how things should be working and a clear display of how they are failing, someone should definitely be able to sort it out.

 

   

Hikkyu, Newbie
Posted: 02 March 2015 08:49 PM   Total Posts: 11   [ # 9 ]

Well, just before i’ll test what you suggested, this is what i nedd :

- a beveled cube already formed with multiple planes
=> done

- a camera that rotate around the cube (hoverController used). If the mouse is on the right of the viewport, the cube spin around his y axis in a clockwise direction. Same principle for reverse rotation and the rotation around the x axis.

=> done

- Finaly, i need a light ont the top right front corner that illuminates slightly the cube.I think that the light must follow the camera position for that we have the impression that it is all the time in the same corner

=> here my problem. I don’t know how i can do that.

I’ll prepare some picture to show where are my problems as Pierce said before.

Thanls a lot Pierce for your help and your patience, if i can, when my project will be finished, i’ll send you cookies ^^

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X