Worker for Mesh persing with CompactSubGeometry

Software: Away3D 4.x

Avatar
GoroMatsumoto, Sr. Member
Posted: 07 May 2013 08:55 AM   Total Posts: 166

Hi,

I’m trying parsing mesh with AS3 Worker.
It’s based on MeshSave class.

https://github.com/nixxle/Away3DAdds/blob/master/com/nixxle/away3d/MeshSave.as3

I convert a Mesh to an Object through this class for receiving from parsing worker.

Separated SubGeometry is OK.
And I add some functions for Compact one.

Attached image is results of addChild on same 3d model.
the Compact seems having a problem on index buffer.

So, If you know about constructing CompactSubGeo by code,
tell me what is the problem.

I’m working on latest dev.

Thanks.

[In Worker thread:]

public static function meshToObjectWithCompactSubGeo(mesh:Mesh):Object
  {
   
if(!mesh.geometry)
    return 
{};
   var 
m:Object {geometry:{subGeometries:[]}position:{x:mesh.position.xy:mesh.position.yz:mesh.position.z}};

   for 
each(var g:CompactSubGeometry in mesh.geometry.subGeometries)
   
{
    m
.geometry.subGeometries.push(compactSubGeometryToObject(g));
   
}

   
return m;
  
}

public static function compactSubGeometryToObject(s:CompactSubGeometry):Object
  {

   
return {
     vertices
:s.vertexData,
     
uvs:s.UVData,
     
vertexNormals:s.vertexNormalData,
     
vertexTangents:s.vertexTangentData,
     
indices:s.indexData
    }

  } 

[In Main thread:]

public static function objectToMeshWithCompactSubGeo(obj:Object):Mesh
  {
   
var geo:Geometry = new Geometry();
   var 
subGeo:CompactSubGeometry;
   
   for 
each(var subObj:Object in obj.geometry.subGeometries)
   
geo.addSubGeometry(objectToCompactSubGeometry(subObj));
   
   var 
mesh:Mesh = new Mesh(geo);
   
   return 
mesh;
  
}

public static function objectToCompactSubGeometry(obj:Object):CompactSubGeometry
  {
   
var s:CompactSubGeometry = new CompactSubGeometry();
   
s.updateData(GeometryUtil.interleaveBuffers(uint(obj.vertices.length/3), obj.verticesobj.vertexNormalsobj.vertexTangentsobj.uvsobj.uvs));
   
s.updateIndexData(Vector.<uint>(obj.indices));
   return 
s;
  

 

   

John Brookes, Moderator
Posted: 07 May 2013 09:32 AM   Total Posts: 732   [ # 1 ]

Try the GeomUtil class instead of GeometryUtil.

edit..
Your error is the number of vertices.
YourMesh.geometry.subGeometries[0].numVertices

   

Avatar
GoroMatsumoto, Sr. Member
Posted: 07 May 2013 10:11 AM   Total Posts: 166   [ # 2 ]

@JohnBrookes
Thank you.
That class seems cool.
It’s constructible Skinned one too : )

But, I got an error like a below…

RangEerror Error #1125 the index 21749 is out of range 21749
at away3d.core.base::CompactSubGeometry/fromVectors()[/Users/Goro/ActionscriptLibrary/away3d/core/base/CompactSubGeometry.as:372]
at away3d.tools.utils::GeomUtil$/constructSubGeometry()[/Users/Goro/ActionscriptLibrary/away3d/tools/utils/GeomUtil.as:190]

Yes, the number seems wrong.
I checked the number at below also:

public static function compactSubGeometryToObject(s:CompactSubGeometry):Object
  {

   trace
(s.vertexData.length);
   return 
{
     vertices
:s.vertexData,
     
uvs:s.UVData,
     
vertexNormals:s.vertexNormalData,
     
vertexTangents:s.vertexTangentData,
     
indices:s.indexData
    }
  } 

But it shows same number as error’s one.
I will keep finding a couse.

   

Avatar
GoroMatsumoto, Sr. Member
Posted: 07 May 2013 10:41 AM   Total Posts: 166   [ # 3 ]

It works once.

I convertToSeparateBuffers() and send SubGeometry as separated from worker,
and constructed as CompactSubGeometry in Main thread with GeomUtil.constructSubGeometry().

Does CompactSubGeometry.vertexData return a merged Vector data?

In my case like this:

CompactSubGeometry.vertexData.length: 21749
CompactSubGeometry.numVertices:      1673

So, how can I get separated vertexData from CompactSubGeometry?
Because I also think that I want to parse SkinnedSubGeometry.

   

John Brookes, Moderator
Posted: 07 May 2013 10:48 AM   Total Posts: 732   [ # 4 ]

Its not compactSubgeometry.vertexData.length.

compactSubgeometry.vertexData contains vertices, normals tangents and UVs

Look at this example. (Not how you would do things but just to show)

var MyMesh:Mesh = new Mesh(new PlaneGeometry(20020011), new ColorMaterial(0x00ff00));
MyMesh.= -400;
scene.addChild(MyMesh);
trace("COMPACTSUBGEOMETRY");
trace("CompactSubGeometry contains vertices, normals, tangents and Uvs in the vertexdata vector")
trace("vertexData: " MyMesh.geometry.subGeometries[0].vertexData);
trace("indexData: " MyMesh.geometry.subGeometries[0].indexData);
trace("Number of vertices: " MyMesh.geometry.subGeometries[0].numVertices);

//Convert it to Separate Buffers (old subgeometry)
MyMesh.geometry.convertToSeparateBuffers();
trace("\nSUBGEOMETRY");
trace("Subgeometry has separate vectors for each data type");
trace("vertexData: " MyMesh.geometry.subGeometries[0].vertexData);
trace("vertexNormalData: " MyMesh.geometry.subGeometries[0].vertexNormalData);
trace("vertexTangentData: " MyMesh.geometry.subGeometries[0].vertexTangentData);
trace("UVData: " MyMesh.geometry.subGeometries[0].UVData);
trace("indexData: " MyMesh.geometry.subGeometries[0].indexData);
trace("Number of vertices: " MyMesh.geometry.subGeometries[0].numVertices);

//Create vertexData from standard subgeometry
var vtc:Vector.<Number> = GeometryUtil.interleaveBuffers(MyMesh.geometry.subGeometries[0].numVerticesMyMesh.geometry.subGeometries[0].vertexDataMyMesh.geometry.subGeometries[0].vertexNormalDataMyMesh.geometry.subGeometries[0].vertexTangentDataMyMesh.geometry.subGeometries[0].UVData);


var 
geom:Geometry = new Geometry();
var 
csg:CompactSubGeometry = new CompactSubGeometry();
csg.updateData(vtc);
csg.updateIndexData(MyMesh.geometry.subGeometries[0].indexData);
geom.addSubGeometry(csg);

var 
m:Mesh = new Mesh(geom, new ColorMaterial(0xff0000));
scene.addChild(m);

trace("\nCOMPACTSUBGEOMETRY");
trace("vertexData: " m.geometry.subGeometries[0].vertexData);
trace("indexData: " m.geometry.subGeometries[0].indexData);
trace("Number of vertices: " MyMesh.geometry.subGeometries[0].numVertices); 
   

Avatar
GoroMatsumoto, Sr. Member
Posted: 07 May 2013 11:07 AM   Total Posts: 166   [ # 5 ]

I see.

When I need constructing SkinnedSubGeometry,
I will solve by sending a separated SubGeometry and additional properties.

Thank you for polite of you : )

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X