Parent mesh uses material of child mesh

Software: Away3D 4.x

bluntcoder, Newbie
Posted: 26 November 2012 03:03 PM   Total Posts: 19

Hello,

I have a mesh for some terrain, which has a grass texture, and then I want to attach a simple textured cube onto that mesh as child. When I do so, the parent mesh uses the texture of the child mesh. Is this a bug or am I doing something wrong?

var material:TextureMaterial mGround.material as TextureMaterial;
material.texture Cast.bitmapTexture(s_ResourceMgr.BitmapDataFromDisplayObject(mGroundTexture));
material.alphaBlending true;

var 
cube:Mesh = new Mesh(new CubeGeometry());
cube.city.CountryMapPosition.x;
cube.city.CountryMapPosition.z;
cube.city.CountryMapPosition.y;
  
material cube.material as TextureMaterial;
material.texture Cast.bitmapTexture(s_ResourceMgr.BitmapDataFromDisplayObject(mRedTexture));
mGround.addChild(cube); 

Anyone ever run into this?

   

Saaikouze, Newbie
Posted: 26 November 2012 03:28 PM   Total Posts: 10   [ # 1 ]

Why are you adding the cube to the ground? Is there some relation between them? Otherwise just add both to the view

   

bluntcoder, Newbie
Posted: 26 November 2012 03:34 PM   Total Posts: 19   [ # 2 ]

Because I need to transform the parent mesh, rotate it, scale it, etc.

I found a workaround - by submitting the material on construction, it works:

var cube:Mesh = new Mesh(new CubeGeometry(), new ColorMaterial(0xFF0000)); 

So this is definitely a bug.

   

Avatar
Fabrice Closier, Administrator
Posted: 26 November 2012 04:26 PM   Total Posts: 1265   [ # 3 ]

This sounds like a typical job for ObjectContainer3D.

That’s not a bug. if you want to have a mesh having 2 materials while in a parent/child relationship, instead of using the parent material. Pass the material to parent.submeshes[0] en set the second material child to child.submeshes[0]. Both parent en child materials should be then null.
But using ObjectContainer3D would be way more easy.

   

bluntcoder, Newbie
Posted: 26 November 2012 06:54 PM   Total Posts: 19   [ # 4 ]

Oh ok - so then what is the difference between a mesh and “submeshes” vs attaching other meshes with addChild()? When would you use one over the other?

   

Avatar
Fabrice Closier, Administrator
Posted: 26 November 2012 08:47 PM   Total Posts: 1265   [ # 5 ]

Because we are limited in max entries per vector and that we must have one texture per buffers for gpu reasons. We need to “subdivide” the content, yet keep it under same “roof”. Mesh extends ObjectContainer3D, so yes you can addChild, but it less “easy” than using ObjectContainer3D directly.
The mesh.material is the one used by default. In case of multiple material meshes you can have one material per submesh. If none is found the default mesh material is used instead. Exact same rule. (You can play/learn in Prefab with this if you open the mesh details)

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X