XML Scene Decription 0.1 for PV3D

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.

Leave a Reply


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