Wednesday, August 27, 2008

as3 geom as class mirror property

Here's a small bit of code I pasted into an as3 geom class to ave the option of inverting the mesh either x,y or z. the uvs work fine

replace function 'v' with:

but first create a mirror var:

public var mirror :String;

private function v(x:Number,y:Number,z:Number):void
{
switch (mirror){
case "x":
verts.push(new Vertex3D(-x,y,z));
break;

case "y":
verts.push(new Vertex3D(x,-y,z));
break;

case "z":
verts.push(new Vertex3D(x,y,-z));
break;

default:
verts.push(new Vertex3D(x,y,z));
break;
}
}


pass the var into the constructor
when you initiate your object
either "x","y","z"

public function coccyx( material:MaterialObject3D=null,mirror:String="", initObject:Object=null )
{
//--\\
//---\\
//---//
this.mirror = mirror


even better would be code for a combination of all three

download th as3 geom class exporter here

Monday, August 25, 2008

papervision 3d

Have loaded a complex model using the as3 geom exporter, which compiles the model information on export, embedding it with the flash swf, avoids parsing the file later on like collada.
Also coded 3d camera movement around the object. I had the object rotating, but want later on to rotate the parts of the object separately. Had trouble finding examples of even camera movement around the object.
It might take a moment to load, will build that in later

Here is the example with markers to show your how the sin() works
also learnt how to UVW unwrap on the way, this example is a box unwrap, hence the shadows. There are not lights in this scene so it needs baked on lights to show the form.
here is the code for the camera movement

sh = stage.stageWidth;
Pi = Math.PI/180;
mY = ((mouseY/sh)*180) * Pi;
mX = ((mouseX/(sh/2))*180) * Pi;
radY1 =mY+1.8;
radY2 =mY+3.2;
radX1 =mX+1.8;
radZ =mX+3.3;


closY1 = 100*Math.sin(radY1);
closY2 = 100*Math.sin(radY2);
closX1 = 100*Math.sin(radX1);
closZ = 100*Math.sin(radZ);

camX = (1*(closX1 * ((-closY2)/100)));
camZ = closZ* ((-closY2)/100);
///


default_camera.x=camX;
default_camera.y=closY1;
default_camera.z=camZ

default_camera.lookAt (objectArray[0]);