problems with the materialibrary

0 views
Skip to first unread message

martin

unread,
Nov 20, 2009, 7:59:36 PM11/20/09
to away3d.dev
hello,
i load my collada file. the collada consists of two objects.
i want to change the material at realtime... it works fine with only
object in the collada, but when want more than one objec. when i load
a texturesequence, both of the objects get the same texture.

[Embed(source="assets/texture.jpg")]
private var tex:Class;
[Embed(source="assets/torso_marble2.jpg")]
private var marble:Class;
var targetmat:MaterialData = model.materialLibrary.getMaterial("ID3");
targetmat.material = new BitmapMaterial(Cast.bitmap(tex));
var targetmat:MaterialData = model.materialLibrary.getMaterial("ID5");
targetmat.material = new BitmapMaterial(Cast.bitmap(marble));

in this case i get the marble texture for both of the objects, if i
change the order both of the objects get the tex texture?
where is the problem!? i use the away3d version 2.4.2. is it a problem
of away or is there a mistake in my code?
here is the collada codesnippet:
<library_materials>
<material id="ID3" name="quad">
<instance_effect url="#ID4"/>
</material>
<material id="ID5" name="lambert1">
<instance_effect url="#ID6"/>
</material>
</library_materials>

any ideas where the problems is?

ben

unread,
Nov 22, 2009, 2:08:07 PM11/22/09
to away3d.dev
Hi martin,
you have the same reference for both the materials : var
targetmat:MaterialData.
they should at least have 2 diffrent names don't they ;-)

martin

unread,
Nov 24, 2009, 5:28:10 PM11/24/09
to away3d.dev
ok i edit it but the same situation, both of the objects get the first
texture...
here my complete code:

[Embed(source="assets/texture.jpg")]
private var texture1:Class;
[Embed(source="assets/torso_marble2.jpg")]
private var texture2:Class;

private var scene:Scene3D;
private var camera:Camera3D;
private var view:View3D;

// camera movement
private static const ORBITAL_RADIUS:Number = 150;
private static const CAMERA_ORBIT:Number = 750;

private var doRotation:Boolean = false;
private var lastMouseX:int;
private var lastMouseY:int;
private var cameraPitch:Number = 60;
private var cameraYaw:Number = -60;
private var flashman:ObjectContainer3D;

private var o_asetest:Mesh;
private var model:ObjectContainer3D;
private var mesh1:Mesh;
private var mesh2:Mesh;
private var ob1:ObjectContainer3D;
private var ob2:ObjectContainer3D;


public function colladaChangeMaterialtwo()
{
//Debug
away3d.core.utils.Debug.active = true;

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
stage.addEventListener(Event.MOUSE_LEAVE, onStageLeave );

init3D();
//createScene();
this.addEventListener(Event.ENTER_FRAME, loop);
}

private function init3D():void
{
scene = new Scene3D();
camera = new Camera3D({zoom:10, focus:100, x:-100, y:-200,
z:-500});
view = new View3D({scene:scene, camera:camera});
view.x = 540 / 2;
view.y = 600 / 2;
addChild(view);
setCameraPosition();
var loader:Loader3D = Collada.load("collada/testtex.dae", { scaling:
1, material:texture2});
loader.addOnSuccess(onLoaderSuccess);
view.scene.addChild(loader);
}


private function onLoaderSuccess(event:Loader3DEvent):void
{
model = (event.loader.handle as ObjectContainer3D);
createScene();
trace("onLoaderSuccess end");
}


private function createScene():void
{
var texture1:PhongBitmapMaterial = new PhongBitmapMaterial
( Cast.bitmap( texture1 ));
var texture2:PhongBitmapMaterial = new PhongBitmapMaterial
( Cast.bitmap( texture2 ));

var targetMaterial1:MaterialData =
model.materialLibrary.getMaterial("ID3");
targetMaterial1.material = texture1;

var targetMaterial2:MaterialData =
model.materialLibrary.getMaterial("ID8");
targetMaterial2.material = texture2;

var light:DirectionalLight3D = new DirectionalLight3D({color:
0xFFFFFF, ambient:0.7, diffuse:.8, specular:0.5});
light.x = 100;
light.z = 500;
light.y = 500;
scene.addChild(light);
}

private function loop(event:Event):void
{
updateCamera();
view.render();
}

and this is my log from collada parsing:

! ------------- Begin Parse Collada -------------
! ------------- Begin Parse Scene -------------
+ Parse Node : ID14 : ID14
+ Parse Node : ID23 : ID23
! ------------- End Parse Scene -------------
! ------------- No animations to parse -------------
+ Parse Geometry : ID15
+ Parse MeshMaterialData
+ Parse Geometry : ID24
+ Parse MeshMaterialData
+ Build Material : ID8
+ Build Material : ID3
+ Build Mesh : ID14
+ Build Mesh : ID23
onLoaderSuccess end

why i have always the same texture on both?
thx for help
martin
Reply all
Reply to author
Forward
0 new messages