New Primitives

Software: Away3D 4.x

Rowd, Newbie
Posted: 23 January 2012 05:04 PM   Total Posts: 3

Can anyone post a quick sample of how to use the new primitives?  I’ve loaded models and animations with the away3d 4 (dev section on github), but I can’t for the life of me figure out how to just add simple primitives now.  I keep getting an error from flash builder stating “1067: Implicit coercion of a value of type away3d.primitives:SphereGeometry to an unrelated type away3d.containers:ObjectContainer3D”

I just want some sample code for the new primitives is all :D

   

Avatar
Dan Baughman, Newbie
Posted: 24 January 2012 01:42 AM   Total Posts: 5   [ # 1 ]

Here’s an example with the capsule…

package
{
 import away3d
.cameras.*;
 
import away3d.containers.*;
 
import away3d.controllers.HoverController;
 
import away3d.debug.*;
 
import away3d.lights.*;
 
import away3d.materials.ColorMaterial;
 
import away3d.primitives.*;
 
 
import flash.display.*;
 
import flash.display3D.*;
 
import flash.events.*;
 
import flash.geom.Vector3D;
 
 
[SWF(backgroundColor="#000000", frameRate="60", quality="LOW")]
 
 
public class Primitive_Test extends Sprite
 {
  
//Material variables
  
private var _material1:ColorMaterial;
  
//Light variables
  
private var _light1:PointLight;
  private var 
_light2:PointLight;  
  
//Object variables
  
private var _trident:Trident;
  private var 
_capsule:Capsule;  
  
//engine variables
  
private var scene:Scene3D;
  private var 
view:View3D;  
  
//private var camera:HoverCamera3D;
  
private var camera:Camera3D;
  private var 
camcontroller:HoverController;  
  
//navigation variables
  
private var move:Boolean = false;
  private var 
lastPanAngle:Number;
  private var 
lastTiltAngle:Number;
  private var 
lastMouseX:Number;
  private var 
lastMouseY:Number;
  
  public function 
Primitive_Test()
  
{
   init
();
  
}
  
  
private function init():void
  {
   initEngine
();
   
initLights();
   
initMaterials();
   
initObjects();
   
initListeners();
  
}
  
  
private function initEngine():void
  {
   stage
.scaleMode = StageScaleMode.NO_SCALE;
   
stage.align = StageAlign.TOP_LEFT;
   
   
scene = new Scene3D();   
   
camera = new Camera3D();
   
camcontroller = new HoverController(camera);
   
   
view = new View3D();
   
view.scene = scene;
   
view.camera = camera;
   
   
addChild(view);
  
}
  
  
private function initLights():void
  {
   _light1 
= new PointLight();
   
_light1.color = 0xff8888; // redish color
   
_light1.position = new Vector3D(3000,3000,3000);   
   
_light2 = new PointLight();
   
_light2.color = 0xffff88;// yellowish color
   
_light2.position = new Vector3D(-3000,-3000,3000);
   
scene.addChild(_light1);
   
scene.addChild(_light2);
  
}
  
  
private function initMaterials():void
  {   
   _material1 
= new ColorMaterial(0x0000ff);
   
_material1.lights = [_light1,_light2];
  
}  
  
  
private function initObjects():void
  {   
   
//trident for debug  
   
_trident = new Trident(400, true);
   
scene.addChild(_trident);
   
   
//capsule primitive
   
_capsule = new Capsule(_material1,150,300,12,12,true);
   
scene.addChild(_capsule);
   
   
camcontroller.distance = _capsule.height*2;
  
}
  
  
private function initListeners():void
  {
   addEventListener
(Event.ENTER_FRAME, onEnterFrame);
   
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
   
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
  
}
  
  
private function onEnterFrame(event:Event):void
  {
   
if (move) {
    camcontroller
.panAngle = 0.2 * (stage.mouseX - lastMouseX) + lastPanAngle;
    
camcontroller.tiltAngle = 0.2 * (stage.mouseY - lastMouseY) + lastTiltAngle;
   
}      
   view
.render();
  
}
  
  
private function onMouseDown(event:MouseEvent):void
  {
   lastPanAngle 
= camcontroller.panAngle;
   
lastTiltAngle = camcontroller.tiltAngle;
   
lastMouseX = stage.mouseX;
   
lastMouseY = stage.mouseY;
   
move = true;
   
stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
  
}
  
  
private function onMouseUp(event:MouseEvent):void
  {
   move 
= false;
   
stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);     
  
}
  
  
private function onStageMouseLeave(event:Event):void
  {
   move 
= false;
   
stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);    
  
}
  
  
private function onResize(event:Event = null):void
  {
   view
.x = stage.stageWidth / 2;
   
view.y = stage.stageHeight / 2;
  
}
 }
} 

Hope it helps.

   

Rowd, Newbie
Posted: 24 January 2012 11:50 AM   Total Posts: 3   [ # 2 ]

I finally found what I was looking for.  I was talking about the new primitives like planegeometry.as and spheregeometry.as ... here is what I found.  The capsule primitive has changed since the version you are using.  Here is an example I got after making this thread ...

_plane = new Mesh(new PlaneGeometry(1000, 1000, 2, 2, true), sphereMat);

It’s pretty simple, I just couldnt figure out the new syntax haha

   

3dNewb, Sr. Member
Posted: 04 February 2012 02:33 PM   Total Posts: 105   [ # 3 ]

Thanks, came here looking for any way to use the geometry.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X