How to change plane’s width and height

Software: Away3D 4.x

Zerone, Newbie
Posted: 12 June 2012 08:44 AM   Total Posts: 22

Hi all,

After Away3d changed Plane to Mesh with PlaneGeometry.
Then it can not update the width and height in run time.

this is the way I found for change the width

PlaneGeometry(plane.geometry).width 123

below is my example:

<?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"
      
pageTitle="Plane Resize Testing"
      
minWidth="955" minHeight="600"
      
backgroundAlpha="0">
 <
s:layout>
  <
s:VerticalLayout />
 </
s:layout>
 <
fx:Script>
  <!
[CDATA[
   import away3d
.cameras.Camera3D;
   
import away3d.containers.Scene3D;
   
import away3d.containers.View3D;
   
import away3d.controllers.HoverController;
   
import away3d.entities.Mesh;
   
import away3d.materials.ColorMaterial;
   
import away3d.primitives.PlaneGeometry;
   
   private var 
plane:Mesh;
   private var 
scene:Scene3D;
   private var 
camera:Camera3D;
   private var 
view:View3D;
   private var 
cameraController:HoverController;
   
   private function 
onWidthChanged(event:Event):void{
    
if(plane != null){
     PlaneGeometry
(plane.geometry).width widthSlider.value;
    
}
   }
   
   
private function onHeightChanged(event:Event):void{
    
if(plane != null){
     PlaneGeometry
(plane.geometry).height heightSlider.value;
    
}
   }
   
   
private function onXChanged(event:Event):void{
    
if(plane != null){
     plane
.xSlider.value;
    
}
   }
   
   
private function onYChanged(event:Event):void{
    
if(plane != null){
     plane
.ySlider.value;
    
}
   }
   
   
private function onZChanged(event:Event):void{
    
if(plane != null){
     plane
.zSlider.value;
    
}
   }
   
   
private function onCreated():void{
    scene 
= new Scene3D();
    
camera = new Camera3D();
    
view = new View3D(scenecamera);
    
cameraController = new HoverController(cameranull451010001045);
    
plane = new Mesh(new PlaneGeometry(widthSlider.valueheightSlider.value), new ColorMaterial(0x00FFFF));
    
    
scene.addChild(plane);
    
mainView.addChild(view);
    
mainView.addEventListener(Event.ENTER_FRAMEonEnterFrame);
   
}
   
   
private function onEnterFrame(event:Event):void{
    view
.render();
   
}
  ]]
>
 </
fx:Script>
 <
s:Form>
  <
s:layout>
   <
s:HorizontalLayout />
  </
s:layout>
  <
s:FormItem label="Width">
   <
s:HSlider id="widthSlider" minimum="0" maximum="200" value="100" change="onWidthChanged(event)" />
  </
s:FormItem>
  <
s:FormItem label="Height">
   <
s:HSlider id="heightSlider" minimum="0" maximum="200" value="100" change="onHeightChanged(event)" />
  </
s:FormItem>
  <
s:FormItem label="X">
   <
s:HSlider id="xSlider" minimum="-100" maximum="100" value="0" change="onXChanged(event)" />
  </
s:FormItem>
  <
s:FormItem label="Y">
   <
s:HSlider id="ySlider" minimum="-100" maximum="100" value="0" change="onYChanged(event)" />
  </
s:FormItem>
  <
s:FormItem label="Z">
   <
s:HSlider id="zSlider" minimum="-100" maximum="100" value="0" change="onZChanged(event)" />
  </
s:FormItem>
 </
s:Form>
 <
mx:UIComponent id="mainView" width="100%" height="100%" creationComplete="onCreated()" />
</
s:Application
   

Zerone, Newbie
Posted: 12 June 2012 09:21 AM   Total Posts: 22   [ # 1 ]

I found a way for fix it, it is a bug in PrimitiveBase.as

update the invalidateGeometry function as below

protected function invalidateGeometry() : void
  {
   _geomDirty 
true;
   
updateGeometry();
  

update the invalidateUVs function as below

protected function invalidateUVs() : void
  {
   _uvDirty 
true;
   
updateUVs();
  
   

Richard Olsson, Administrator
Posted: 16 June 2012 11:30 AM   Total Posts: 1192   [ # 2 ]

This known bug has been fixed in the release branch of Away3D and will be in the stable 4.0 release.

However, it’s not being fixed per the suggestion in this thread, since the fix suggested above would result in the primitive being rebuilt every time a property is changed. Changing width, height and depth of a primitive right after each other would in this case trigger three rebuilds, when of course only one is necessary (in time for the next render.)

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X