Simple rendering on timeline not working

Software: Away3D 4.x

Alex Costea, Newbie
Posted: 28 August 2013 02:16 PM   Total Posts: 3

Hi,

I would like to render a view using code on the timeline of a flash file.

Right now I am using the following code:

import away3d.containers.View3D;
import away3d.entities.Mesh;
import away3d.materials.ColorMaterial;
import away3d.primitives.SphereGeometry;

var 
view:View3D = new View3D();
addChild(view);
var 
sphereGeometry:SphereGeometry = new SphereGeometry(350);
var 
sphereMaterial:ColorMaterial = new ColorMaterial0xff0000 );
var 
sphereMesh:Mesh = new Mesh(sphereGeometrysphereMaterial);
view.scene.addChild(sphereMesh);

view.render(); 

which renders nothing but when used in a DocumentClass it renders the Sphere no problem. I would greatly appreciate some advice on how to make it work when written on a flame on the timeline and no within a DocumentClass. A link to a tutorial would be ok as well but I have not found anything on it after extensive searches.

I attached the DocumentRoot class which was downloaded from a tutorial online.

Also like to know if possible when a book on Away3d 4 will come out.

Thank you.

 

File Attachments
basic_v4.as  (File Size: 2KB - Downloads: 312)
   

Avatar
mrpinc, Sr. Member
Posted: 28 August 2013 07:44 PM   Total Posts: 119   [ # 1 ]

The main difference between the two files is that the ‘Document Class’ adds an enter frame event listener so it is calling view.render() at the framerate of your SWF.

In your timeline code, view.render() only gets called once.  You should add an enter_frame handler and call view.render() each frame.

   

Alex Costea, Newbie
Posted: 29 August 2013 06:13 AM   Total Posts: 3   [ # 2 ]

Thanks man, it worked but I don’t really understand something. I dropped a stop() in there and one view.render() without the EnterFrame should be enough to render the scene once, is that not right? Does it disappear or not get rendered if I only call view.render() once? I am confused about why this does not work.

   

Avatar
theMightyAtom, Sr. Member
Posted: 29 August 2013 06:58 AM   Total Posts: 669   [ # 3 ]

I have run into this myself.
The scene has to be initiated on the GPU before it’s ready to be rendered.
Though in theory you would expect this to happen in one frame cycle and what you’ve done is perfectly logical. In practice though, you need to initialize your scene in one frame, and render in the next, as the scene is rendered as the frame is ENTERED.
If you want a single frame, you could use a Timer that only fires once.

Good Luck!

   

Alex Costea, Newbie
Posted: 30 August 2013 06:46 AM   Total Posts: 3   [ # 4 ]

Hey Atom,

thank a lot for the info. Clears things up smile.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X