How to correctly change primitives added to ObjectContainer3D?

Software: Away3D 4.x

ralphB, Newbie
Posted: 18 May 2016 04:06 PM   Total Posts: 9

I have an ObjectContainer3D with primitives added as children, including meshes based on CylinderGeometry.  The first time it is built and renders, it looks great.  But I need to change the cylinder properties from time to time (e.g. topRadius).  No matter what I try, after I make a change, I get rendering artifacts that look like the original mesh is superimposed over the new one.

I have tried:
1. Removing all children from the ObjectContainer3D, recreating the geometries and meshes, and adding them again to the ObjectContainer3D.
2. Re-instantiating the whole ObjectContainer3D and rebuilding it.
3. Leaving the ObjectContainer3D and mesh alone, and changing only the properties of the geometry.

None of these seem to have any effect on the artifacts. 

I notice when browsing the ObjectContainer3D instance (with Flash CS6) that it has only one child, a vector, although I have done an addChild of many meshes to it.  So clearly the methodologies from Away 3.6 for working with ObjectContainer3D’s don’t apply now!

Help or guidance please?  Thank you!

   

ralphB, Newbie
Posted: 23 May 2016 09:18 PM   Total Posts: 9   [ # 1 ]

On further experimentation, the problem seems to occur when I make a Class that extends ObjectContainer3D.  There doesn’t seem to be any way to modify its children’s properties, change their materials, or kill them off.

This is making Away3D 4 functionally useless for my applications… hopefully I am doing something dumb.

Anyone?

   

Avatar
Fabrice Closier, Administrator
Posted: 24 May 2016 11:45 AM   Total Posts: 1265   [ # 2 ]

hopefully I am doing something dumb….

That’s a potential assumption. We do not know.
How do you expect a response, help etc…  if you use this forum like a personal diary?

Post instead a simple code that reproduces the problem. In this case for instance, a snippet showing the way you try to access the children would certainly be interesting…  wink

   

ralphB, Newbie
Posted: 24 May 2016 04:04 PM   Total Posts: 9   [ # 3 ]

Solved.  At the risk of adding to my “personal diary,” Fabrice, after more experimentation, it seems that the guidelines should be like this:

1. Create a class that extends ObjectContainer3D.
2. Pass in the lightpicker to the constructor.
3. Make a single main ObjectContainer3D object and add it to this in the constructor.
4. Make all parameters that will control the object instance variables (e.g. the color, widths, etc.).
5. Make a rebuild function that cleans out the main object, creates all the geometries and meshes based in the instance variables, and materials, andassigns the instance lightpicker to all materials.  By “clean out” I mean loop over it calling removeChildren.
6. Call the rebuild function in the constructor.
7. User setters to change the parameters.  Call rebuild() in the setter.

Now in the main program instantiate the class and pass in the lightpicker for the scene.  After that you can call setters to change it; the rebuild() function should remove old vestiges and start clean.

Code snippets follows.

var testObjContainer:TestObjContClass = new TestObjContClass(myLightPicker);
testObjContainer.myColor 0x0000FF// Defaults to green, should now render as blue
testObjContainer.myWidth 350;

public class 
TestObjContClass extends ObjectContainer3D{
 
 
public var mainObj:ObjectContainer3D;
 public var 
_lightPicker:StaticLightPicker;
 private var 
_myColor:int 0x00FF00;
 private var 
_myWidth:Number 200;
 private var 
_myDepth:Number 200;
 private var 
_myHeight:Number 200;
 
 public function 
TestObjContClass(lp:StaticLightPicker null{
  _lightPicker 
lp;
  
mainObj = new ObjectContainer3D();
  
this.addChild(mainObj);
  
rebuild();
 
}
 
 
public function rebuild(){
  
while(mainObj.numChildren 0){
   mainObj
.removeChild(mainObj.getChildAt(0));
  
}
  
var testCube_mat:ColorMaterial = new ColorMaterial_myColor );
  
testCube_mat.lightPicker _lightPicker;
  
  var 
testCube1_g:CubeGeometry = new CubeGeometry();
  var 
testCube1_m:Mesh  = new Mesh(testCube1_gtestCube_mat);
  
mainObj.addChild(testCube1_m);
  
testCube1_g.height _myHeight;
  
testCube1_g.width _myWidth;
  
testCube1_g.depth _myDepth;
  
  var 
testCube2_g:CubeGeometry = new CubeGeometry();
  var 
testCube2_m:Mesh  = new Mesh(testCube2_gtestCube_mat);
  
mainObj.addChild(testCube2_m);
  
testCube2_g.height _myHeight;
  
testCube2_g.width _myWidth;
  
testCube2_g.depth _myDepth;
  
testCube2_m.300;
 
}
 
public function set myColor(val:int){
  _myColor 
val;
  
rebuild();
 
}
 
public function set myWidth(val:Number){
  _myWidth 
val;
  
rebuild();
 
}
   

Avatar
Fabrice Closier, Administrator
Posted: 26 May 2016 06:40 PM   Total Posts: 1265   [ # 4 ]

Dear diary, today, I saw ralphB fix his problem alone. smile

Looking at your class, I would prolly do a bit differently. The above code could use less resources and work less. As is, you said you reconstruct a few times, you should dispose the geometries when you do removeChild, you could also have a class cubeGeometry and use it during constructs. You would then only nullify the mesh and the material.
To be more efficient. I do not see why you have a mainObj, you could simply do this.addChild/remove. The myColor should also not need to rebuild the geometries, instead loop over children and change colors. As it seams you also apply the same color, having a class colorMaterial, would also suppress the need to loop, in myColor method, a simple _myColorMaterial.color would then update all the meshes if you would share it. And assuming you are right on the geometries not being updated with primitives (I have not checked that yet), then there also no need for new geom, instead make one cubeGeometry, of size 1,1,1, share it and on update, you would only need to change scaleX,Y and Z to your width,height,depth… so no need for more than one geometry and never required to be updated.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X