Hello,
The code I am trying to achieve is to use the values ??of an affine chart display object from file. Obj.
My code looks like this one:
/Objet
var mapVillage:Array = new Array();
mapVillage[0] = [0, 0, 'bat01', 'bat03', 0, 0, 0, 0, 0, 0];
mapVillage[1] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
mapVillage[2] = [0, 0, 0, 0, 'bat01', 0, 0, 'bat03', 0, 0];
mapVillage[3] = [0, 0, 'bat01', 'bat02', 'bat01', 0, 0, 0, 0, 0];
mapVillage[4] = [0, 0, 0, 0, 'bat01', 0, 0, 0, 0, 0];
var test:Class3dObject = new Class3dObject( mapVillage );
data.scene.addChild(test);
Class3dObject.as
package
{
import away3d.containers.ObjectContainer3D;
public class Class3dObject extends ObjectContainer3D
{
public var cptI:int = new int,
cptJ:int = new int,
content:ObjectContainer3D = new ObjectContainer3D;
public function Class3dObject(map:Array)
{
for ( cptI = 0; cptI < 9; cptI++){
for ( cptJ = 0; cptJ < 9; cptJ++){
if (map[cptI][cptJ] != 0) {
trace('Class3dObject("' + map[cptI][cptJ] + '")');
var param:String = map[cptI][cptJ] + ';' + cptI + ';' +cptJ;
var test:Class3dObjectInit = new Class3dObjectInit( param );
content.addChild(test);
}
}
}
addChild(content);
}
}
}
Class3dObjectInit.as
package
{
import away3d.containers.ObjectContainer3D;
import away3d.entities.Mesh;
import away3d.loaders.Loader3D;
import away3d.materials.methods.BasicDiffuseMethod;
import away3d.materials.methods.BasicSpecularMethod;
import away3d.materials.methods.FresnelSpecularMethod;
import away3d.materials.methods.SubsurfaceScatteringDiffuseMethod;
import away3d.materials.TextureMaterial;
import away3d.library.*;
import away3d.library.assets.*;
import away3d.events.AssetEvent;
import flash.utils.getDefinitionByName;
public class Class3dObjectInit extends ObjectContainer3D
{
private var data:ClassData;
//scene objects 3ds
public var loader:Loader3D;
//material objects obj
public var subsurfaceMethod:SubsurfaceScatteringDiffuseMethod;
public var fresnelMethod:FresnelSpecularMethod;
public var diffuseMethod:BasicDiffuseMethod;
public var specularMethod:BasicSpecularMethod;
//Objet
//Batiments
//bat01
public var bat01:Mesh;
public var bat01x:int = 5;
public var bat01y:int = 3;
[Embed(source="embed/bat01.obj", mimeType="application/octet-stream")]
public var Modelbat01:Class;
//bat02
public var bat02:Mesh;
public var bat02x:int = 5;
public var bat02y:int = 3;
[Embed(source="embed/bat02.obj", mimeType="application/octet-stream")]
public var Modelbat02:Class;
//bat03
public var bat03:Mesh;
public var bat03x:int = 7;
public var bat03y:int = 5;
[Embed(source="embed/bat03.obj", mimeType="application/octet-stream")]
public var Modelbat03:Class;
public var obj:Array = new Array;
public function Class3dObjectInit(objet:String)
{
data = new ClassData();
obj = objet.split(';');
trace('nom : ' + obj[0] + ' - X : ' + obj[1] + ' - Y : ' + obj[2]);
AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);
switch( obj[0] ) {
case "bat01":
trace("asset bat01");
AssetLibrary.loadData( new Modelbat01() );
break;
case "bat02":
trace("asset bat02");
AssetLibrary.loadData( new Modelbat02() );
break;
case "bat03":
trace("asset bat03");
AssetLibrary.loadData( new Modelbat03() );
break;
}
}
private function onAssetComplete(event:AssetEvent):void
{
AssetLibrary.removeEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);
if (event.asset.assetType == AssetType.MESH) {
trace('Insertion de : ' + obj[0]);
this[obj[0]] = event.asset as Mesh;
//this[obj[0]].name = obj[0] + 'x' + obj[1] + 'y' + obj[2];
this[obj[0]].geometry.scale(1);
this[obj[0]].x = ( obj[1] + ( this[obj[0]+"x"] /2 ) ) * 1;
this[obj[0]].y = ( obj[2] + ( this[obj[0] + "y"] / 2 ) ) * 1;
addChild( this[obj[0]] );
}
}
}
}
The problem lies in the fact that I only have one object that appears. for after my test, this is the first object in the list. It does not take into account the following!
Would you have a solution?
Sincerely yours,
Goupix