Artefacts occuring with three simple Cubes [3.6]

Software: Away3D 3.x

achim, Newbie
Posted: 16 June 2011 01:24 PM   Total Posts: 20

Hi,
I’m trying to set up a simple 3D histogram.
When I change the values, some artefacts occur, mainly when the top Cube is set to minimum height : one can see the Cube below through it.
Could it be a z-ordering problem ?
You can see the swf here :histogram demo
Thanks in advance if you can help,
Cyrill

   

achim, Newbie
Posted: 16 June 2011 01:52 PM   Total Posts: 20   [ # 1 ]

Sorted it, but in a weird manner…
First, I rounded the Cubes y positions.
Then I chose the renderer INTERSTECTING_OBJECTS.
Then I put one pixel between each Cube.
Then I put the middle one to bothsides:false, and the two others to true.
Now it works, but I guess there is an explanation to this ?
Here is the code :

package fr.tenso.charts.charts3D
{
 import flash
.display.Bitmap
 
import away3d.containers.View3D;
 
import away3d.materials.ColorMaterial;
 
import away3d.materials.BitmapMaterial;
 
import away3d.materials.ColorMaterial;
 
import away3d.primitives.Cube;
 
import away3d.primitives.data.CubeMaterialsData;
 
import away3d.core.render.Renderer;
 
import away3d.core.utils.Cast
 
import away3d.cameras.*;
 
import away3d.containers.Scene3D;
 
 
import away3d.lights.*;
 
 
import flash.display.Sprite;
 
import flash.geom.Vector3D;
 
import flash.events.Event;
 
import away3d.materials.BitmapMaterial;
 
import flash.text.TextField;
 
import fl.controls.Slider;

 
[SWF(width="700"height="700"frameRate="30"backgroundColor="#FFFFFF")]
 
public class Histogram extends Sprite
 {
  
private var _demoXML:XML;
  private var 
_hvc:HistogramValueConverter;
  private var 
_maxHeight:int;
  private var 
_rotationSpeed:int;
  private var 
view:View3D;
  private var 
_histo1:Cube;
  private var 
_histo2:Cube;
  private var 
_histo3:Cube;
  private var 
_cmd1:CubeMaterialsData;
  private var 
_cmd2:CubeMaterialsData;
  private var 
_cmd3:CubeMaterialsData;
  
  private var 
_input1:Slider;
  private var 
_input2:Slider;
  private var 
_input3:Slider;
  
  private var 
_elementsArray:Array;
  
  private var 
light1 = new DirectionalLight3D();

  
  public function 
Histogram()
  
{
   this
._demoXML=<content>
   </
content>;
   
   
this._hvc=new HistogramValueConverter();
   
   
this._maxHeight=400;
   
this._rotationSpeed=0;
   
init();
  
}
  
private function init():void
  {
   this
._hvc.init(this._maxHeight,1000);
   
view = new View3D({x:350,y:-300renderer:Renderer.INTERSECTING_OBJECTS});
   
   
_cmd1=new CubeMaterialsData();
   
_cmd2=new CubeMaterialsData();
   
_cmd3=new CubeMaterialsData();
   
   
// top and bottom :same color
   // front and back : same color
   // left and right : same color

   
_cmd1.top = new ColorMaterial(0x98d061);
   
_cmd1.bottom = new ColorMaterial(0x98d061);
   
_cmd1.front = new ColorMaterial(0x87c647);
   
_cmd1.back = new ColorMaterial(0x87c647);
   
_cmd1.left = new ColorMaterial(0x5eb705);
   
_cmd1.right = new ColorMaterial(0x5eb705);

   
_cmd2.top = new ColorMaterial(0xdc9c45);
   
_cmd2.bottom = new ColorMaterial(0xdc9c45);
   
_cmd2.front = new ColorMaterial(0xDD9431);
   
_cmd2.back = new ColorMaterial(0xDD9431);
   
_cmd2.left = new ColorMaterial(0xcf7804);
   
_cmd2.right = new ColorMaterial(0xcf7804);

   
_cmd3.top = new ColorMaterial(0x9861D0);
   
_cmd3.bottom = new ColorMaterial(0x9861D0);
   
_cmd3.front = new ColorMaterial(0x8747C6);
   
_cmd3.back = new ColorMaterial(0x8747C6);
   
_cmd3.left = new ColorMaterial(0x5e05B7);
   
_cmd3.right = new ColorMaterial(0x5e05B7);

   
_histo1 = new Cube({width:200,height:150,depth:200,bothsides:true});
   
_histo1.cubeMaterials=_cmd1;
   
_histo1.x=0;
   
   
_histo2 = new Cube({width:200,height:150,depth:200,bothsides:false});
   
_histo2.cubeMaterials=_cmd2;
   
_histo2.x=0;
   
   
_histo3 = new Cube({width:200,height:150,depth:200,bothsides:true});
   
_histo3.cubeMaterials=_cmd3;
   
_histo3.x=0;
   
   
_histo1.rotationY=_histo2.rotationY=_histo3.rotationY=30;
   
view.scene.addChild(_histo1);
   
view.scene.addChild(_histo2);
   
view.scene.addChild(_histo3);
   
   
this._input1=this.getChildByName("input1") as Slider;
   
this._input2=this.getChildByName("input2") as Slider;
   
this._input3=this.getChildByName("input3") as Slider;
   
this._input1.addEventListener(Event.CHANGE,test);
   
this._input2.addEventListener(Event.CHANGE,test);
   
this._input3.addEventListener(Event.CHANGE,test);
   
   
this._elementsArray=new Array();
   var 
element:Object;
   
element=new Object();
   
element.name=_histo1;
   
element.logicalValue=30;
   
this._elementsArray.push(element);
   
element=new Object();
   
element.name=_histo2;
   
element.logicalValue=300;
   
this._elementsArray.push(element);
   
element=new Object();
   
element.name=_histo3;
   
element.logicalValue=500;
   
this._elementsArray.push(element);
   
this._hvc.elementsArray=this._elementsArray;
   
   
view.camera.y=1800;
   
view.camera.moveBackward(5000);
   
view.camera.zoom=30;
   
   
renderThis();
   
   
addChild(view);
   
this.addEventListener(Event.ENTER_FRAME,renderThis);
   
  
}
  
private function test(pEvt:Event):void
  {
   
var i:int=-1;
   if (
pEvt.currentTarget==this._input1i+=1;
   if (
pEvt.currentTarget==this._input2i+=2;
   if (
pEvt.currentTarget==this._input3i+=3;
   
this._hvc.setElementLogicalValue(i,Number(pEvt.currentTarget.value));
  
}
  
private function renderThis(e:Event=null):void 
  {
   _histo1
.rotationY +=this._rotationSpeed;
   
_histo1.height=this._hvc.getElementGraphicalValue(0);
   
_histo1.y=_histo1.height/2;

   
_histo2.rotationY +=this._rotationSpeed;
   
_histo2.height=this._hvc.getElementGraphicalValue(1);
   
_histo2.y=1+_histo1.y+_histo1.height/2+_histo2.height/2;

   
_histo3.rotationY +=this._rotationSpeed;
   
_histo3.height=this._hvc.getElementGraphicalValue(2);
   
_histo3.y=1+_histo2.y+_histo2.height/2+_histo3.height/2;
   
   
view.render();
  
}
 }
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X