Freestyle (custom) polygon shape (Away3d 4.x)

Software: Away3D 4.x

DigitalVanilla, Newbie
Posted: 14 April 2012 05:00 AM   Total Posts: 9

Hello guys,

i recently got a small project for a client and my idea to use Away3d was really great. Awesome framework!
I need to create a part of the project where the user is able to draw a flat polygon shape like in the attachment, so I started to create a SubGeomerty, add the points (x,y,x) and the rest (normals, indexes etc..) everything is fine but when the polygon enter in the camera view, Im getting some errors, can you please help me to solve this litle problem? Thanks!

my code:

var lightPicker = new StaticLightPicker([pointLight1]);
      
var 
colorMaterial ColorMaterial = new ColorMaterial(0xFFFFFF);
colorMaterial.smooth false;
colorMaterial.bothSides false;
colorMaterial.diffuseMethod.alphaThreshold .3;
colorMaterial.ambient .2;
colorMaterial.lightPicker lightPicker

var 
vertexes:Vector.<Number> = new Vector.<Number>([0,0,050,0,050,0,50]);

var 
normals:Vector.<Number> = new Vector.<Number>([0,1,00,1,00,1,0]);

var 
uvs:Vector.<Number> = new Vector.<Number>([0,10,10,1]);
 
var 
indices:Vector.<uint> = Vector.<uint>([0,1,23,4,56,7,8]);
     
var 
rawTangents:Vector.<Number> = Vector.<Number>([000,0,0]);
 
var 
subGeometry:SubGeometry = new SubGeometry();
subGeometry.updateVertexData(vertexes);
subGeometry.updateUVData(uvs);
subGeometry.updateIndexData(indices);
subGeometry.updateVertexNormalData(normals);
subGeometry.updateVertexTangentData(rawTangents);
     
var 
geometry:Geometry = new Geometry();
geometry.addSubGeometry(subGeometry);      
     
var 
mesh:Mesh = new Mesh(geometrycolorMaterial);
LightsHelper.addStaticLightToMaterials(meshpointLight1);

scene_.addChild(mesh

 

   

Richard Olsson, Administrator
Posted: 14 April 2012 08:55 AM   Total Posts: 1192   [ # 1 ]

The length of the tangents vector looks a little off. Why five entries? I would suggest you just remove it altogether and set autoDeriveVertexTangents to true.

Also, it would be helpful if you could say what kind of errors you’re getting.

   

DigitalVanilla, Newbie
Posted: 14 April 2012 02:30 PM   Total Posts: 9   [ # 2 ]

nothing, I removed the tangets and added the autoDeriveVertexTangents

and im getting this:

ArgumentError: Error #3671: Buffer has zero size.
at flash.display3D::Context3D/createVertexBuffer()
at away3d.core.base::SubGeometry/getVertexNormalBuffer()
at away3d.core.base::SubMesh/getVertexNormalBuffer()
at away3d.materials.passes::DefaultScreenPass/render()
at away3d.materials::MaterialBase/renderPass()
at away3d.core.render::DefaultRenderer/drawRenderables()
at away3d.core.render::DefaultRenderer/draw()
at away3d.core.render::RendererBase/executeRender()
at away3d.core.render::DefaultRenderer/executeRender()
at away3d.core.render::RendererBase/render()
at away3d.containers::View3D/render()
at Felix/onEnterFrame()

   

Richard Olsson, Administrator
Posted: 14 April 2012 02:35 PM   Total Posts: 1192   [ # 3 ]

Ah, reading your code again I realize that you are initializing your vector incorrectly.

You should either use casting, or instantiate and then supply the values. I’m surprised your compiler doesn’t warn you about the fact that you are implicitly casting an array to an integer.

Alt 1 (casting):
myVector = Vector.<Number>([0, 0, 0]);

Alt 2 (instantiation):
myVector = new Vector.<Number>(3, false);
myVector.push(0, 0, 0);

   

DigitalVanilla, Newbie
Posted: 14 April 2012 03:40 PM   Total Posts: 9   [ # 4 ]

tnx brò! amazing smile
I stopped to code in flash 3 years agò to jump on iOS and now I have this small project for a client; I forgot many many things :(

   

DigitalVanilla, Newbie
Posted: 15 April 2012 06:00 AM   Total Posts: 9   [ # 5 ]

I updated the code, no more errors but it doesnt render anything.. wierd!
but at least im almost there :)

var colorMaterial ColorMaterial = new ColorMaterial(0xffffff);
      
colorMaterial.smooth false;
      
colorMaterial.bothSides true;
      
colorMaterial.diffuseMethod.alphaThreshold .3;
      
colorMaterial.ambient .2;
      
colorMaterial.lightPicker lightPicker;

      var 
vertexes:Vector.<Number> = new Vector.<Number>(3false);
      
vertexes.push(0,0,0);
      
vertexes.push(50,0,0);
      
vertexes.push(50,0,50);

      var 
normals:Vector.<Number> = new Vector.<Number>(3false);
      
normals.push(0,1,0);
      
normals.push(0,1,0);
      
normals.push(0,1,0);
      
      var 
uvs:Vector.<Number> = new Vector.<Number>(3false);
      
uvs.push(0,1);
      
uvs.push(0,1);
      
uvs.push(0,1);
     
      var 
indices:Vector.<uint> = Vector.<uint>([0,1,2]);
    
      var 
subGeometry:SubGeometry = new SubGeometry();
      
subGeometry.updateVertexData(vertexes);
      
subGeometry.updateVertexNormalData(normals);
      
subGeometry.updateUVData(uvs);
      
subGeometry.updateIndexData(indices);
      
/*subGeometry.autoDeriveVertexTangents  = true;
      subGeometry.autoDeriveVertexNormals = true;*/
      
      
var geometry:Geometry = new Geometry();
      
geometry.addSubGeometry(subGeometry);
        
      var 
sphere:SphereGeometry = new SphereGeometry();
     
      var 
mesh:Mesh = new Mesh(geometrycolorMaterial);
      
      
LightsHelper.addStaticLightToMaterials(meshpointLight1);
      
      
scene_.addChild(mesh);
      
      
camContr.lookAtObject mesh
   

Rayen123, Member
Posted: 26 April 2012 12:39 AM   Total Posts: 70   [ # 6 ]

Hi,
did you find solution ?

   

DigitalVanilla, Newbie
Posted: 26 April 2012 06:52 AM   Total Posts: 9   [ # 7 ]

Yes, I hired a skilled away3d+mathematician developer smile
best and fast solution eheh

   

Rayen123, Member
Posted: 26 April 2012 08:45 AM   Total Posts: 70   [ # 8 ]

heh raspberry,
and what was wrong in this code? why was nothing showed ?

   

DigitalVanilla, Newbie
Posted: 26 April 2012 08:47 AM   Total Posts: 9   [ # 9 ]

don’t know truly smile
The guy is very skilled, I had to focus on other aspect of the pipeline smile
Less coding, more happiness :D

   

Rayen123, Member
Posted: 26 April 2012 09:12 AM   Total Posts: 70   [ # 10 ]

Okey,
if you will know (or your mathematic) how fix this code to show triangle, or somebody else will know, please reply wink thanks

   

DigitalVanilla, Newbie
Posted: 26 April 2012 09:14 AM   Total Posts: 9   [ # 11 ]

he’s working with another type of frameworks now, no I beleve the solution is not longer valid here.

   

John Brookes, Moderator
Posted: 26 April 2012 09:41 AM   Total Posts: 732   [ # 12 ]

If you do

var vertexes:Vector.<Number> = new Vector.<Number>(3, false);
vertexes.push(0,0,0);
vertexes.push(50,0,0);
vertexes.push(500, 0, 50);

you would end up with a vector of length 12

Just remove the 3 false from the vertexs uvs etc
eg

var vertexes:Vector.<Number> = new Vector.<Number>;
vertexes.push(0,0,0);
vertexes.push(50,0,0);
vertexes.push(500, 0, 50);

Another thing the UVs are all in the same position, something like

var uvs:Vector.<Number> = new Vector.<Number>;// (3, false);
    uvs.push(0,1);
    uvs.push(1,1);
    uvs.push(0,0);

or however you want them positioned,

   

Rayen123, Member
Posted: 26 April 2012 09:50 AM   Total Posts: 70   [ # 13 ]

THANKS YOU VERY MUCH smile It works!

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X