Save OBJ file from Away3d at runtime.

Software: Away3D 4.x

gordeaoux, Newbie
Posted: 06 August 2012 05:05 PM   Total Posts: 3

Hi,

I’ve been scouring these forums and the documentation for a way to save an obj file of the current scene to the user’s disk during runtime. I’m creating a project where a kinect is used to create an extruded model of the user dynamically, so I can’t simply send a pre-created obj file down the wire. The closest I found was this class, which looks like it’s not in away3d proper: http://away3d.com/livedocs/3.5.2_lib/away3d/exporters/ObjExporter.html

The features page lists obj export as one of the features - is that just for the Prefab tool?

Any tips of where to look?

   

Richard Olsson, Administrator
Posted: 06 August 2012 06:06 PM   Total Posts: 1192   [ # 1 ]

There is no support for any exporters in Away3D 4.0. Your best bet would be to create your own simple exporter, either using a format like OBJ (which should be simple if you have a limited required feature set) or using a bespoke format and then create the relevant importer in your tool.

If you are on a commercial project, you can hire one of the core Away3D developers who are very familiar with the internal data structures of the engine (and file the formats) to quickly write up something that suits your needs. If you’re feeling generous, that exporter could then be contributed back into the engine if general-purpose enough. smile

   

gordeaoux, Newbie
Posted: 06 August 2012 06:19 PM   Total Posts: 3   [ # 2 ]

Thanks for the speedy reply, Richard. I figured this might be the case. I decided to implement my own obj exporter. It’s not very generic, but I posted my method here in case it helps anyone else looking to export models.

var f:FileReference = new FileReference();   
   var 
objFile:String "" ;
   var 
i:int 0;

   
// sphereSkin is an already-existing SkinExtrude object.

   
for each(var v:Number in sphereSkin.geometry.subGeometries[0].vertexData){
    
if(i%== 0objFile += "\nv";
    
i++;
    
objFile += " " v;
   
}      
   
   i 
0;
   for 
each(var ind:uint in sphereSkin.geometry.subGeometries[0].indexData){
    
if(i%== 0objFile += "\nf";
    
i++;
    
objFile += " " String(ind 1);
   
}
   f
.save(objFile"sample.obj"); 
   

Avatar
theMightyAtom, Sr. Member
Posted: 06 August 2012 06:56 PM   Total Posts: 669   [ # 3 ]

I know Prefab features .obj export from an Away3D scene. http://www.closier.nl/prefab/

Maybe you could ask Fabrice kindly, if he could contribute that class to the community? smile

Cheers

   

gordeaoux, Newbie
Posted: 06 August 2012 11:08 PM   Total Posts: 3   [ # 4 ]

Thanks for the replies - much appreciated! I’ll keep a watch out for official file export. Unfortunately my project goes live next week, so I’m going to have to settle for doing it myself!

Here’s a slightly more generic method I ended up with that allows for multiple sub-geometries.

private function getObjFile(geometry:Geometry):String {
   
var objFile:String "" ;
   var 
i:int 0;
   var 
pri:int 0;
   var 
sg:SubGeometry;
   for 
each(sg in geometry.subGeometries){
    objFile 
+= "\no"
    
0;
    for 
each(var v:Number in sg.vertexData){
     
if(i%== 0objFile += "\nv";
     
i++;
     
objFile += " " reduceFloatingPrecision(v1000);
    

    
var b:uint 0
    for 
each(var ind:uint in sg.indexData){
     
if(b%== 0objFile += "\nf";
     
b++;
     
objFile += " " String(ind pri);
    
}
    pri 
/3;
   
}
   
   
return objFile;
  
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X