cube primitive not displaying in correct ‘y’ position

Software: Away3D 4.x

Avatar
LostPixel, Newbie
Posted: 12 March 2014 04:11 PM   Total Posts: 5

I have developed a companion program for the game Minecraft and have decided to provide a 3D display of the imported data.

The data comes from a Minecraft schematic file giving length,width and height of the schematic. It also provides an array that gives the blocks material. It’s position in the array can be used find its location within the schematic.

When i put it to code I get a 3D display with the blocks in the correct x and z position but the y position is wrong.

I am using Flash CC version 13.1.0.226, This is an AIR for desktop version 3.8 and I am using Away3D version 4.1.6

Here is the code:

package ui {
 import away3d
.containers.*;
 
import away3d.entities.*;
 
import away3d.materials.*;
 
import away3d.primitives.*;
 
import away3d.utils.*;
 
 
import flash.display.Sprite;
 
import flash.events.Event;
 
import flash.geom.Vector3D;
 
import flash.utils.ByteArray;

 public class 
Schematic3D extends Sprite {
  
private var fileData:FileToData;
  private var 
size:int;
  private var 
l:int;
  private var 
w:int;
  private var 
h:int;
  private var 
blocks:ByteArray;
  private var 
blockData:ByteArray;
  private var 
view:View3D;
  private var 
cube:Mesh;
  
  public function 
Schematic3D(fileToData:FileToData{
   addEventListener
(Event.ADDED_TO_STAGEonAdded);
   
addEventListener(Event.REMOVED_FROM_STAGEonRemoved);
   
fileData fileToData;
  
}
  
  
private function onAdded(e:Event):void {
   removeEventListener
(Event.ADDED_TO_STAGEonAdded);
   
size 30;
   
fileData.schematicHeight;
   
fileData.schematicLength;
   
fileData.schematicWidth;
   
blocks fileData.blocks;
   
blockData fileData.blockData;
   
show();
  
}
  
  
private function show():void {
   
var bpl w;
   
//setup the view
   
view = new View3D();
   
addChild(view);
   
   
//setup the camera
   
view.camera.300;
   
view.camera.= -300;
   
view.camera.300;
   
view.camera.lookAt(new Vector3D());
   
   
//setup the scene
   
for(var i:int 0blocks.lengthi++) {
    cube 
= new Mesh(new CubeGeometry(sizesizesize), new TextureMaterial(Cast.bitmapTexture(Stone)));
    
cube.= (w) * size;
    
cube.int(bpl) * size
    
cube.= -((int(w) - (int(bpl) * bpl)) * size);
    
view.scene.addChild(cube);
   
}
   
   
//setup the render loop
   
addEventListener(Event.ENTER_FRAMEonEnterFrame);
  
}
  
  
private function onEnterFrame(e:Event):void {
   view
.render();
  
}
  
  
private function onRemoved(e:Event):void {
   removeEventListener
(Event.ENTER_FRAMEonEnterFrame);
   
view.dispose();
  
}
 }

Here is what the display looks like:
Output image

   

Avatar
mrpinc, Sr. Member
Posted: 12 March 2014 05:07 PM   Total Posts: 119   [ # 1 ]

The Y calculation you are using is correct.  It is your Z calculation that is wrong.  Your “layers” are offset dramatically.

Also you should only create 1 instance of the cube geometry and pass the same instance to all of your mesh’s.  Same thing with the TextureMaterial.  A single instance should be shared between all mesh’s.

   

Avatar
theMightyAtom, Sr. Member
Posted: 12 March 2014 05:11 PM   Total Posts: 669   [ # 2 ]

There’s no apparent problem as far as i can see.

What do the figures look like that give you this result? h=1, l=7,w=6?
You’re obviously going to need over 7*6 blocks before you see any difference in y. How many blocks in all?

   

Avatar
LostPixel, Newbie
Posted: 12 March 2014 08:48 PM   Total Posts: 5   [ # 3 ]
mrpinc - 12 March 2014 05:07 PM

The Y calculation you are using is correct.  It is your Z calculation that is wrong.  Your “layers” are offset dramatically.

Also you should only create 1 instance of the cube geometry and pass the same instance to all of your mesh’s.  Same thing with the TextureMaterial.  A single instance should be shared between all mesh’s.

If i comment the statement ‘cube.y = int(i / bpl) * size;’ I get the same result.
When I include the statement the objects are not being repositioned up or down the y axis.

Also the final result will not have the same texture on each cube so there will be a different TextureMaterial for each cube

To answer theMightyAtom. There are 14 layers: h = 14 for a total of 588 blocks.

Anyway I’m stumped. What am I doing wrong

   

Avatar
theMightyAtom, Sr. Member
Posted: 12 March 2014 08:56 PM   Total Posts: 669   [ # 4 ]

try tracing out the cube.y, and your z as MrPinc suggests.
I’m pretty sure this isn’t an Away3D issue.

And you can still share geometry even when you are using different materials. It will seriously increase performance and reduce memory.
Declare your geometry outside the loop. If your going to use it in other operations declare it as a variable.

Good Luck!

   

Avatar
LostPixel, Newbie
Posted: 12 March 2014 09:45 PM   Total Posts: 5   [ # 5 ]

well…. It seems my z calculation is wrong. I was sure I had already traced it.
And that’s what I get for assuming.

Thank you very much for putting me back on track.

   

Avatar
theMightyAtom, Sr. Member
Posted: 12 March 2014 09:48 PM   Total Posts: 669   [ # 6 ]

full points to mrPinc, well spotted!

http://xkcd.com/1339/

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X