Simple example help

Software: Away3D 3.x

azaroth, Newbie
Posted: 08 September 2012 03:01 PM   Total Posts: 8

hey guys, im reading the book “away3d 3.6 essentials” but im stuck here:

package {

import away3d.core.base.Object3D;
import away3d.primitives.*;

import flash.events.Event;
import flash.events.KeyboardEvent;

import away3d.materials.BitmapFileMaterial;
import away3d.primitives.SeaTurtle;


public class PrimitivesDemo extends Away3DTemplate {
 
  protected var currentPrimitive:Object3D;
 
  public function PrimitivesDemo() {
  super();
  }
 
  protected override function initEngine():void{
 
  super.initEngine();
  camera.z = -500;
 
  }
 
  protected override function initScene():void{
  super.initScene;
  initSphere();
 
  }
 
  protected override function initListeners():void{
  super.initListeners();
  stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
  }
 
  protected override function onEnterFrame(event:Event):void{
  super.onEnterFrame(event);
  currentPrimitive.rotationX += 1;
  currentPrimitive.rotationY += 1;
  currentPrimitive.rotationZ += 1;
  }
 
  protected function OnKeyUp(event:KeyboardEvent):void{
  removeCurrentPrimitive();
  }
 
  switch (event.keyCode)
  {
  case 49:
  initCone();
  break;
 
  case 50:
  initCube();
  break;
 
  case 51:
  initCylinder();
  break;
 
  case 52:
  initGeodesicSphere();
  break;
 
  case 53:
  initGridPlane();
  break;
 
  case 54:
  initLineSegment();
  break;
 
  case 55:
  initPlane();
  break;
 
  case 56:
  initRegularPolygon();
  break;
 
  case 57:
  initRoundedCube();
  break;
 
  case 48:
  initTorus();
  break;
 
  case 81:
  initTriangle();
  break;
 
  case 87:
  initSeaTurtle();
  break;
 
  case 69:
  initTrident();
  break;
 
  case 82:
  initSkybox();
  break;
 
  case 84:
  initRoundedCube();
  break;
 
  case 89:
  initSkybox6();
  break;
 
  default:
  initSphere();
  break;
  }
 
  protected function removeCurrentPrimitive():void{
  scene.removeChild(currentPrimitive);
  currentPrimitive = null;
  }
 
  protected function initCube():void{
  currentPrimitive = new Cube();
  scene.addChild(currentPrimitive);
  }
 
  protected function initCylinder():void{
  currentPrimitive = new Cylinder({height: 150});
  scene.addChild(currentPrimitive);
  }
 
  protected function initGeodesicSphere():void{
  currentPrimitive = new GeodesicSphere();
  scene.addChild(currentPrimitive);
  }
 
  protected function initGridPlane():void{
  currentPrimitive = new GridPlane({segments: 4});
  scene.addChild(currentPrimitive);
  }
 
  protected function initLineSegment():void{
  currentPrimitive = new LineSegment({edge: 500});
  scene.addChild(currentPrimitive);
  }
 
  protected function initPlane():void{
  currentPrimitive = new Plane({bothsides: true});
  scene.addChild(currentPrimitive);
  }
 
  protected function initRegularPolygon():void{
  currentPrimitive = new RegularPolygon({bothsides: true});
  scene.addChild(currentPrimitive);
  }
 
  protected function initRoundedCoube():void{
  currentPrimitive = new RoundedCube();
  scene.addChild(currentPrimitive);
  }
 
  protected function initSeaTurtle():void{
  currentPrimitive = new SeaTurtle({scale: 0.3});
  scene.addChild(currentPrimitive);
  }
 
  protected function initSkybox():void{
  currentPrimitive = new Skybox();
  scene.addChild(currentPrimitive);
  }
 
  protected function initSkybox6():void{
  currentPrimitive = new Skybox6();
  scene.addChild(currentPrimitive);
  }

  protected function initSphere():void{
  currentPrimitive = new Sphere();
  scene.addChild(currentPrimitive);
  }
 
  protected function initTorus():void{
  currentPrimitive = new Torus({radius: 75, tube: 30});
  scene.addChild(currentPrimitive);
  }
 
  protected function initTriangle():void{
  currentPrimitive = new Triangle({bothsides: true});
  scene.addChild(currentPrimitive);
  }
 
  protected function initTrident():void{
  currentPrimitive = new Trident(100);
  scene.addChild(currentPrimitive);
  }
 
}
}


Away3DTemplate:


package {

import away3d.cameras.Camera3D;
import away3d.containers.Scene3D;
import away3d.containers.View3D;

import flash.display.Sprite;
import flash.events.Event;


public class Away3DTemplate extends Sprite {
 
  protected var scene:Scene3D;
  protected var camera:Camera3D;
  protected var view:View3D;
 
  public function Away3DTemplate() {
  initUI();
  initEngine();
  initScene();
  initListeners();
  }
 
  protected function initEngine():void{
  view = new View3D();
  scene = view.scene;
  camera = view.camera;
  addChild(view);
  view.x = stage.stageWidth / 2;
  view.y = stage.stageHeight / 2;
  }
 
  protected function initListeners():void{
  addEventListener(Event.ENTER_FRAME, onEnterFrame);
  }
 
  protected function onEnterFrame(event:Event):void{
  view.render();
  }
 
  protected function initScene():void{
 
  }
 
  protected function initUI():void{
 
  }
 
  }
}


still have errors, could you help me?

   

Avatar
ganesh, Member
Posted: 08 September 2012 03:35 PM   Total Posts: 54   [ # 1 ]

hi, If you are using Away3d 4 gold with tutorials of “away3d 3.6 essentials” then you will surely get errors, because some old classes/packages may not be available in latest Aways3d 4 src folder.

I also started this way but later I had to change my way of learning, now I browse net for tutorials away3d 4gold and practice them

   

azaroth, Newbie
Posted: 08 September 2012 03:46 PM   Total Posts: 8   [ # 2 ]

Hey, thank you for your answer, i thought to do the same, but i want to learn the library in a specific order, and in the net i find splited tutorials, so my head gets meshed up

   

azaroth, Newbie
Posted: 09 September 2012 06:27 AM   Total Posts: 8   [ # 3 ]

ok i went to a simplier example with just a sphere (latest away3d version) but still full errors:


package {

import flash.events.Event;
import away3d.containers.View3D;
import away3d.containers.Scene3D;
import away3d.cameras.Camera3D;
import away3d.primitives.Sphere;


public class hovercam {
 
  private var view1:View3D = new View3D;
  private var scene1:Scene3D = new Scene3D;
  private var camera1:Camera3D = new Camera3D;
  private var sphere1:Sphere = new Sphere;
 
  public function hovercam() {
 
 
  view1.x = stage.stageWidth / 2;
  view1.y = stage.stageHeight / 2;
 
 
  view1.scene = scene1;
 
 
  view1.camera = camera1;
  camera1.z = -1000;
 
 
  sphere1.radius = 50;
 
  scene1.addChild(sphere1);
 
  addEventListener(Event.ENTER_FRAME, onEnterFrame);
  }
 
  function onEnterFrame():void{
  view1.render();
  }
 
}

}

   

Avatar
ganesh, Member
Posted: 09 September 2012 09:31 AM   Total Posts: 54   [ # 4 ]

I think you are still following old 3.6 book samples with away3d gold. I took your code and tried them, initially I also got lots of errors. Then I edit these lines

import away3d.primitives.SphereGeometry; //  primitives.Sphere
import flash.display.Sprite; // added this line

public class hovercam extends Sprite // public class hovercam

private var sphere1:SphereGeometry = new SphereGeometry;// Sphere


Now the error reduced to only one “1067: Implicit coercion of a value of type away3d.primitives:SphereGeometry to an unrelated type away3d.containers:ObjectContainer3D.”

I think it is because you have not setup the codes correctly and also I have some confusion with your codes can you explain the below codes of your.

 

private var view1:View3D = new View3D;      // its ok
private var scene1:Scene3D = new Scene3D;  // its ok
private var camera1:Camera3D = new Camera3D;  // its ok


view1.scene= scene1;  // here view1.scene is scene1 but above you have just defined scene1 is a type scene3d, is it possible that scene1 is both type view3d and scene3d at a time?


  view1.camera = camera1;  // same confusion here, camera1 is camera3d plus view1.camera at a time.

camera1.z = -1000;  // which camre is this view1.camera or private var camera?

scene1.addChild(sphere1); // which scene1 is this view1’s scene or private var scene?


I am completely new to away, so if you find my questions silly plz then explain it.

Have you tried example that comes with away3 4 gold package?

 

 

 

 

 

   

azaroth, Newbie
Posted: 09 September 2012 10:36 AM   Total Posts: 8   [ # 5 ]

Hey, i will check the code and tell you, where can i find that example you mentioned?

   

Avatar
ganesh, Member
Posted: 09 September 2012 11:32 AM   Total Posts: 54   [ # 6 ]

http://away3d.com/images/uploads/releases/away3d-examples-fp11_4_0_9_gold.zip

   

Avatar
ganesh, Member
Posted: 09 September 2012 12:14 PM   Total Posts: 54   [ # 7 ]

Try this, it worked in my pc

package
{

import flash.display.Sprite;
import flash.events.Event;

import away3d.containers.*;
import away3d.primitives.*;
import away3d.entities.*;
import away3d.materials.*;

public class hovercam extends Sprite
{
  private var _view:View3D;
  private var _sphere:SphereGeometry;
  private var _mesh:Mesh;

  public function hovercam()
  {

  _view = new View3D();
  _mesh = new Mesh(new SphereGeometry(100), new ColorMaterial(0x6666FF,1))
 
  _view.scene.addChild(_mesh);
  addChild(_view);
 
  addEventListener(Event.ENTER_FRAME, _onEnterFrame);
  }


  private function _onEnterFrame(e:Event):void
  {

  _view.render();
  }


}

}

   

azaroth, Newbie
Posted: 09 September 2012 12:39 PM   Total Posts: 8   [ # 8 ]

Yeah it also worked on mine, but could you explane me the “mesh”? Also where can i find a freaking complete guide to away3d 4? How are we supposed to learn the library?

   

azaroth, Newbie
Posted: 09 September 2012 12:46 PM   Total Posts: 8   [ # 9 ]

I tryed with this:

package
{

import flash.display.Sprite;
import flash.events.Event;

import away3d.containers.*;
import away3d.primitives.*;
import away3d.entities.*;
import away3d.materials.*;

public class hovercam extends Sprite
{
  private var _view:View3D;
  private var _sphere:SphereGeometry;
  //private var _mesh:Mesh;

  public function hovercam()
  {

  _view = new View3D();
  //_mesh = new Mesh(new SphereGeometry(100), new ColorMaterial(0x6666FF,1))
 
  _view.scene.addChild(_sphere);
  addChild(_view);
 
  addEventListener(Event.ENTER_FRAME, _onEnterFrame);
  }


  private function _onEnterFrame(e:Event):void
  {

  _view.render();
  }


}

}

but throws this:


1067: Implicit coercion of a value of type away3d.primitives:SphereGeometry to an unrelated type away3d.containers:ObjectContainer3D.

   

Avatar
ganesh, Member
Posted: 09 September 2012 01:07 PM   Total Posts: 54   [ # 10 ]

Try this one, it has no mesh

package
{
import flash.display.Sprite;
import flash.events.Event;
import away3d.primitives.WireframeSphere;
import away3d.containers.View3D;

public class wireframeSphere extends Sprite
{

  public function wireframeSphere()
  {
  var myView :View3D = new View3D();
  addChild(myView);

  var mySphere:WireframeSphere = new WireframeSphere(400,20,15,0X99FF00,2);
  myView.scene.addChild(mySphere);
 
 
  function onEnterFrame(event:Event):void
  {
  myView.render();
  removeEventListener(Event.ENTER_FRAME, onEnterFrame);
  }

  addEventListener(Event.ENTER_FRAME, onEnterFrame);
  }


}

}

   

Avatar
ganesh, Member
Posted: 09 September 2012 01:22 PM   Total Posts: 54   [ # 11 ]

I don’t know your level of expertise, but about me I did some works with AS2, then a full one year break no touch with flash, now I am again busy to learn flash, but since then flash has advanced a lot now it is AS3, and so many engines out there.

So, for me AS3 and Away both are new, I also had same problem like you and posted for help in this forum http://away3d.com/forum/viewthread/3150/

About mesh, I also practiced and learn 3dmax 10 few year back, and then I came to know that Mesh is actually a face. For example to make a triangle you need three points at any distance and then you connect these points/vertices with straight line, when your triangle is ready you get an area or boundary. Now, this boundary is empty this is called wireframe triangle, and if you fill this triangle with some color you get a face. This face is also called mesh or poly.

The first code example is a filled Sphere, that’s why we need to import mesh to apply color in it, and the last code I sent here is a wireframe only thats why we dont need mesh and we can render it directly

Before we go further, let me know your expertise level, so that, we can learn together and faster.

 

 

   

Avatar
Fabrice Closier, Administrator
Posted: 09 September 2012 02:13 PM   Total Posts: 1265   [ # 12 ]

@ganesh A Mesh is not a Face. A Mesh is a collection of 1 or more faces. A face in Away3D is a triangle definition. It’s called ‘mesh’, because when you would connect each points of every triangles with a line it would “look” like a web or some kind of a net.

To get you started:
http://www.youtube.com/watch?v=VSiI4FYYuoc

http://www.gotoandlearn.com/play.php?id=165

   

azaroth, Newbie
Posted: 09 September 2012 02:59 PM   Total Posts: 8   [ # 13 ]

Hey again, finaly i found a “way” i downloaded the book “the essential guide to 3d flash” which uses away3d 3.6 I hope i dont miss any awesome content with 3.6 version instead of 4, but its the only way, im also gonna check the links wink My experiance lvl is amature, @genesh gimme your mail to speak privately about the learning together wink

   

Avatar
80prozent, Sr. Member
Posted: 09 September 2012 03:33 PM   Total Posts: 430   [ # 14 ]

hi azaroth

i dont think learning 3.6 instead of 4 is that good choice.

3.6 was before flashplayer11 and the stage3d, and is working 100% on the cpu.

working with the gpu enables you to process a lot more data, while using less of your cpu power.

at this point away3d 4 even lack some of the features the 3.6 library had, but every feature that is implemented in the gold version is much better than the 3.6 version.

it might be a bit hard to get your head arround the gpu way of working with meshes, but once you understand the principles, using away3d 4 will get much easier.

 Signature 

sorry…i hope my actionscript is better than my english…

   

Avatar
ganesh, Member
Posted: 09 September 2012 03:45 PM   Total Posts: 54   [ # 15 ]

@ Fabrice Closier
Thanks for clearing the concept. So a face is a very basic thing, and mesh is container of faces. right?


can you please tell me that, we can add wirefregeometry directly to a scene and renders it, and it works, but we cant add sphere directly to a scene, because when rendering them compiler throw erros. Why a sphere must be added to a mesh and then we add mesh to the scene before rendering?

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X