将Away3D网格保存到Wavefront .obj

时间:2015-08-11 16:55:30

标签: actionscript-3 3d stage3d away3d

我正在尝试将Away3D中生成的一些网格物体(使用Path Extrude)导出到我可以在Three.js中使用的.obj文件中。我已经设法导出几何体,但可以找出UV映射。这是我到目前为止所得到的:

    requestDictionary.Add("Image", filename);
    requestDictionary.Add("description", some_description);

我做错了什么? 我需要几何和UV ...到目前为止,如果我只保留前两个循环,我得到几何没有UV的有效obj。如果添加UV循环......由于某种原因,UV缓冲区无效。

1 个答案:

答案 0 :(得分:0)

试试这个:

private static function getObjFile(geometry:Geometry):String {
    var objFile:String = "" ;
    var i:int = 0;
    var pri:int = 0;
    var sg:SubGeometry;
    var b:uint = 0;

    for each(sg in geometry.subGeometries){
        objFile += "\no";
        i = 0;
        for each(var v:Number in sg.vertexData){
            if(i%3 == 0) objFile += "\nv";
            i++;
            objFile += " " + setPrecision(v, 1000);
        }

        i=0;
        for each(v in sg.vertexNormalData){
            if(i%3 == 0) objFile += "\nvn";
            i++;
            objFile += " " + setPrecision(v, 1000);
        }

        i=0;
        for each(v in sg.UVData){
            if(i%2 == 0) objFile += "\nvt";
            i++;
            objFile += " " + setPrecision(v, 1000);
        }


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

        pri = i /3;
    }


    return objFile;
}