Can’t see Away3D scene

Software: Away3D 4.x

Xark, Newbie
Posted: 01 April 2013 10:11 AM   Total Posts: 3

Hi,

I’m a total newbie in flash/flex/away3d world and I’ve lost hours trying to see something in 3D on the screen.

I’m working with Flex 4.6 + Away3D 4.1 and I suspect the problem might be related to Stage3D pixels being printed behind Flash. So, I tried to set backgroundAlpha=“0” to the Application tag, but it keeps printing fully white screen.

The code is like this:

View3D MXML component

<?xml version="1.0" encoding="utf-8"?>
<mx:UIComponent xmlns:fx="http://ns.adobe.com/mxml/2009"
    
xmlns:s="library://ns.adobe.com/flex/spark"
    
xmlns:mx="library://ns.adobe.com/flex/mx"
    
width="100%"
    
height="100%">

 <
fx:Script>
  <!
[CDATA[
   import away3d
.containers.View3D;
   
   public var 
view:View3D;
   
   
override protected function createChildren():void
   {
    super
.createChildren();
    
view = new View3D();
    
addChild(view);
    
view.addEventListener(Event.ADDED_TO_STAGEupdate);
   
}
   
   override 
protected function updateDisplayList(unscaledWidth:NumberunscaledHeight:Number):void
   {
    super
.updateDisplayList(unscaledWidthunscaledHeight);
    
update();
   
}
   
   
private function update(e:* = null):void
   {
    
if (view.stage)
    
{
     view
.unscaledWidth 2;
     
view.unscaledHeight 2;
     
view.render();
     
trace("rendered");
    
}
   }
  ]]
>
 </
fx:Script>

</
mx:UIComponent

Main MXML application

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      
xmlns:s="library://ns.adobe.com/flex/spark"
      
xmlns:mx="library://ns.adobe.com/flex/mx"
      
xmlns:local="*"       creati
      backgroundAlpha
="0">

 <
fx:Script>
  <!
[CDATA[
   
/* imports... */
   
   
public function creationComplete():void
   {
    addEventListener
(Event.ADDED_TO_STAGEinit);
   
}
   
   
public function init(event:Event):void
   {
    
var plane:Mesh = new Mesh(new PlaneGeometry(9090), new ColorMaterial(0x5555FF));
    
viewComponent.view.scene.addChild(plane);
    
viewComponent.view.camera.= -100;
    
viewComponent.view.camera.100;
    
viewComponent.view.camera.= -100;
    
viewComponent.view.camera.lookAt(new Vector3D());
   
}
  ]]
>
 </
fx:Script>

 <
local:AwayView3D id="viewComponent"/>

</
s:Application

I don’t get any error but the screen is white.

In the Away3D examples I saw they implement everything inside a AS3 class, without any MXML code, but I don’t know if that’s for doing it more readable, or there’s a good reason for that. What’s the best way?

What am I missing? Any help would be appreciated.

 

   

Xark, Newbie
Posted: 01 April 2013 12:49 PM   Total Posts: 3   [ # 1 ]

OK, I’ve just managed to solve the problem. After trying hundreds of different implementations, the thing is you have to render the view each frame, not only once.

I’ll put the final code here if someone is in the same situation as me:

Main MXML Application

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      
xmlns:s="library://ns.adobe.com/flex/spark"
      
xmlns:mx="library://ns.adobe.com/flex/mx"
      
xmlns:local="*"       creati
      backgroundAlpha
="0">

 <
fx:Script>
  <!
[CDATA[
   import away3d
.containers.View3D;
   
import away3d.entities.Mesh;
   
import away3d.materials.ColorMaterial;
   
import away3d.primitives.PlaneGeometry;
   
import flash.events.Event;
   
import flash.display.Sprite;
   
import flash.geom.Vector3D;
   
import mx.core.UIComponent;
   
   public function 
creationComplete():void
   {
    addEventListener
(Event.ADDED_TO_STAGEinit);
   
}
   
   
public function init(event:Event):void
   {
    
var plane:Mesh = new Mesh(new PlaneGeometry(9090), new ColorMaterial(0x5555FF));
    
viewComponent.view.scene.addChild(plane);
    
viewComponent.view.camera.= -100;
    
viewComponent.view.camera.100;
    
viewComponent.view.camera.= -100;
    
viewComponent.view.camera.lookAt(new Vector3D());
   
}
  ]]
>
 </
fx:Script>

 <
local:AwayView3D id="viewComponent" />

</
s:Application

AwayView3D MXML component

<?xml version="1.0" encoding="utf-8"?>
<mx:UIComponent xmlns:fx="http://ns.adobe.com/mxml/2009"
    
xmlns:s="library://ns.adobe.com/flex/spark"
    
xmlns:mx="library://ns.adobe.com/flex/mx">

 <
fx:Script>
  <!
[CDATA[
   import away3d
.containers.View3D;
   
import flash.events.Event;
   
   public var 
view:View3D;
   
   
   
override protected function createChildren():void
   {
    super
.createChildren();
    
view = new View3D();
    
addChild(view);
    
view.addEventListener(Event.ADDED_TO_STAGEinit);
   
}
   
   
public function init(event:Event):void {
    update
();
    
addEventListener(Event.ENTER_FRAMErender);
   
}
   
   override 
protected function updateDisplayList(unscaledWidth:NumberunscaledHeight:Number):void
   {
    super
.updateDisplayList(unscaledWidthunscaledHeight);
    
update();
   
}
   
   
private function update(e:* = null):void
   {
    
if (view.stage)
    
{
     view
.unscaledWidth 2;
     
view.unscaledHeight 2;
    
}
   }
   
   
private function render(event:Event):void {
    view
.render();
   
}
   
   
  ]]
>
 </
fx:Script>

</
mx:UIComponent
   

ERik Eide, Newbie
Posted: 10 May 2013 10:04 PM   Total Posts: 3   [ # 2 ]

nice, I’m gonna try this right now smile, I’ve got the same problem

just one question..
don’t you think you should put a removeListener ?

public function init(event:Event):void {
    view
.removeEventListener(Event.ADDED_TO_STAGEinit);
    ...
 

thanks for the component

e.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X