Jiglibflash DAE, Shading and Physics

Ok sounds a little mixed bag I know, but really I wanted to get a few ideas up.  In this demo I am loading a DAE, applying shading to my funky material coated ball and also doing some fun math with the 2 objects as they relate to each other. So the bit that took me a while to track down was the shading of material on a sphere. I thought maybe I was to use the CompositeMaterial class, but alas, that did not work and seems better suited to mesh, color cominations then MovieMaterials or BitmapMaterials with shading. Some cruising through the shaders classes though relvealed the answers:

 var ballMat:MovieAssetMaterial=new MovieAssetMaterial("paws_mat");
ballMat.tiled=true;
var ballShader : GouraudShader = new GouraudShader(mylight,  0xFFFFFF,0x404040);
var ballShadedMat:ShadedMaterial = new ShadedMaterial(ballMat, ballShader);

As for the DAE, it was a straight forward load as usual in PV3D and then capturing the load event for the DAE file. Then I was able to add it to the scene. What I did however was mapped it to the positions of my funky shaded sphere to allow it to sit on top. Yeah it looks kinda nuts right now, but it will become the basis for a sweet character shortly. To give it a little extra cool it also leans a little with the speed of the ball, the faster it moves the more it slides around on top. All the goodness about positions and velocities can be found by accessing the CurrentState of a body in the physics model. Give me a buzz if you need more details. Peace.



Drag and Drop 3D Objects in JigLibFlash

Finally got some time to dive into the new classes in JigLibFlash. If you’ve grabbed the latest rev, 192 or later, you will see some changes to streamline things a bit. Have a look here for the run down covered in a few posts. It is now easier to pick your flavor of 3D engine by declaring the appropriate physics class (see plugin folder for away3D, sandy3D and papervision3D). Also API docs are available now which is killer nice too.

Drag and Drop 3D Objects in JigLibFlash

Anyway, I put together this little demo, which I aim to revise and do more with in coming days. I added the new mouseConstraint class to this one to show how it looks in action. Click and drag on the little blue cubes to turf them around the room.

Code bits that are noteworthy:

Declaring new class:

physics = new Papervision3DPhysics(scene, 8);

Creating objects, for example ground:

ground = physics.createGround(yourMaterial, 500, 0);

Adding listener for Mouse interactions:

boxes[i].skin.mesh.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, handleMousePress);

Check out the latest examples in the latest rev for examples on how to handle these events. More to come…

Creating a room in Jiglibflash

Alright, so I finally got a few hours to nail down my first demo with jiglibflash. This one shows a room with 4 walls and a floor to contain the ball. I left in some “debris” to knock around. This could be the basics for a racket ball game or similar. The set up is pretty straight forward. I grabbed the current rev from here which was rev 25. I read through as much of the class code as I could quickly get my head around and dove in.

Space bar to jump, arrows to move ball around.

So the first thing to realize when setting up walls is that the code is well a little funky.

plane3.MoveTo(new JNumber3D(-250, 300,0),JMatrix3D.rotationY(90  * Math.PI/180));

Ok so whats this do? Well, this is using the MoveTo method of the JPlane class to position in the world. (Yeah the syntax could use some help). So there are 2 tricks:

1. the second parameter of MoveTo uses the SetOrientation method which expects a JMatrix3D value. Some examples are JMatrix3D.IDENTITY and then various rotations (rotationX,rotationY,rotationZ) The thing to remember is these are radians. The easiest way to convert degress to radians is: degrees * (Math.PI /180)So step 1, get the walls oriented correctly. You need 2 rotated about the X-axis and 2 rotated about the Y.
2. position objects for the first parameter by their centers. In my example above you see, I have set that wall to be the wall on the left at -250 on the x and at 0 on the Z. The opposite wall is at 250 on the x and 0 on the Z.

That’s about it, nothing too fancy; my version of a quick hello jiglibgflash.