Archive for the ‘Extending PaperVision3D’ Category

Extended setter methods for DisplayObject3D (PV3D 1.5)

Friday, January 4th, 2008

We have extended a little bit PV3D 1.5 DisplayObject3D.as code to have some handy methods to set position and orientation for scene objects. You can insert this snippet at about 927th line of DisplayObject3D.as.

// IFS Upgrade
public function setPos(_x:Number, _y:Number, _z:Number, rotX:Number=NaN, rotY:Number=NaN, rotZ:Number=NaN):void {
this.x = _x;
this.y = _y;
this.x = _z;
if (isNaN(rotX)) { } else {
this.rotationX = rotX;
this.rotationY = rotY;
this.rotationZ = rotZ;
}

}

setPos function simply set xyz and rotation variables of particular DisplayObject3D instance.

public function posFromStr(input:String):void {
var tmpArr:Array = input.split(”,”);

this.x = Number(tmpArr[0]);
this.y = Number(tmpArr[1]);
this.z = Number(tmpArr[2]);

if (tmpArr.length > 3) {

this.rotationX = Number(tmpArr[0]);
this.rotationY = Number(tmpArr[1]);
this.rotationZ = Number(tmpArr[2]);

}

}

We added this function in order to make setting position and rotate params from XML easier. Function uses setting from string formatet like: “49,50,30,30,40,20″ - where first 3 params are coords and second 3 rotation per axis.

public function getPos():Number3D {
return new Number3D(this.x, this.y, this.z);
}

getPos return Number3D object with position of object

public function setRotation3D(input:Number3D, axis:String=”xyz”):void {

if (axis.indexOf(”x”) > -1) {
this.rotationX = input.x; }

if (axis.indexOf(”y”) > -1) {
this.rotationY = input.y; }

if (axis.indexOf(”z”) > -1) {
this.rotationZ = input.z; }

}
//////////////

SetRotation3D sets rotation of object using values from Number3D. in axis input you’re choosing on which axis to apply change…

I simply couldn’t surrve developing without these methods, they are simple but usefull.
I’m distributing it to you in this form to make it easier to integrate in future versions of PV3D/Away3D.

XML Scene Decription 0.1 for PV3D

Friday, January 4th, 2008

Here comes just first version of code that we’re using to describe PV3D scene in our own XML format.

public function sceneSetup(myXML:XML, sceneType:String=”Scene3D”):void
{
// new scene creation based on sceneType param
switch (sceneType) {
case “Scene3D”:
mainScene = new Scene3D(mainDisplay);
break;
case “MovieScene3D”:
mainScene = new MovieScene3D(mainDisplay);
break;
}

var entry:XML;

// materials creation
for each (entry in myXML.mats.ent) {

var tmpMat:MaterialObject3D;
var tmpType:String = entry.@type;

switch (tmpType) {

case “ColorMaterial” :
tmpMat = new ColorMaterial(Number(entry.@color), Number(entry.@alpha));
materialsArray.push(tmpMat);
mainScene.materials.addMaterial(tmpMat, entry.@name);
break;

case “BitmapFileMaterial” :
tmpMat = new BitmapFileMaterial(entry.@url);
materialsArray.push(tmpMat);
mainScene.materials.addMaterial(tmpMat, entry.@name);
break;

}

}

// creation 3D objects
for each (entry in myXML.genObj.ent) {

var tmpMat:MaterialObject3D = mainScene.materials.getMaterialByName(entry.@mName);
var tmpArr:Array = entry.@size.split(”,”);
var tmpArrSeg:Array = entry.@segs.split(”,”);

var tmpObj:DisplayObject3D;
var tmpType:String = entry.@type;

// type switch structure
switch (tmpType) {

case “plane” :
tmpObj = new Plane(tmpMat, Number(tmpArr[0]), Number(tmpArr[1]), Number(tmpArrSeg[0]), Number(tmpArrSeg[1]));
break;

case “cube” :
tmpObj = new Cube(tmpMat, Number(tmpArr[0]), Number(tmpArr[1]), Number(tmpArr[2]), Number(tmpArrSeg[0]), Number(tmpArrSeg[1]), Number(tmpArrSeg[2]));
break;

}

mainScene.addChild(tmpObj, entry.@name);

}

}

This function is part of our RTS interface class that we are using for TheFirstExodus development (http://tesslabs.com/blog/2008/01/04/thefirstexodus-rts-flash-webbased-lunar-simulation/) and it has mainScene as public veriable:

public var mainScene:Scene3D;

XML description file looks like this:

<root>
<genObj>
  <ent type=”plane” mName=”ground” size=”1000,1000″ segs=”1,1″ pos=”0,0,0″ name=”podloga” />
  <ent type=”cube” mName=”cube” size=”200,200,200″ segs=”1,1,1″ pos=”0,0,0″ name=”kocka” />
 </genObj>
 <mats>
  <ent type=”ColorMaterial” name=”ground” color=”0×336633″ alpha=”1″ />
  <ent type=”ColorMaterial” name=”cube” color=”0×666666″ alpha=”1″ />
 </mats>
</root>

this version supports only BitmapMaterial and ColorMaterial as well as Plane and Cube Objects.
this is only to give you idea. Today I’ve started to learn Away3D
(I simple missed until today info that PV3D has sistem project… :( so now I have to pass whole code again )

and I’ll create same solution for all Away3D supported object and materials.


tesseractstudio.org | all rights reserved 2005-2008. | tesseractstudio ltd, Serbia
omnetwork.net | tutorialautomated.info | osgamer.org | freeflashscripts.com | tesslabs.com | thefirstexodus.com | thefirstexodus.com