Importing Google Sketchup models in Mathematica

后端 未结 4 464
再見小時候
再見小時候 2021-02-05 09:10

Google\'s Sketchup is a nice, simple 3D-object modeler. Moreover Google has an enormous warehouse of 3D objects so that you actually don\'t have to do much modeling yourself if

4条回答
  •  误落风尘
    2021-02-05 09:46

    Here is code that successfully imported a very simple .dae file produced by the free version of SketchUp 8.0 into Mathematica 8. This code is not detecting or acting on transformations, it only looks at coordinates and triangles, so don't expect too much.

    data = Import[SystemDialogInput["FileOpen"], "XML"]; 
    
    points = Map[( Partition[ReadList[StringToStream[#[[1]] ], Number], 
    3]) &, (Map[Part[#, 3] &, (Partition[
    Cases[data, XMLElement["float_array", _, _], Infinity], 
    2][[All, 1]])] ) ];
    
    triangles = Map[Partition[1 + ReadList[StringToStream[#[[1]]], Number],3] &, 
    Map[Part[#, 3, 2, 3]&, 
    Cases[data, XMLElement["triangles", _, _], Infinity]]];
    
    Graphics3D[Map[GraphicsComplex[#[[1]], Polygon[#[[2]]]] &, 
    Transpose[{points, triangles}]], Boxed -> False]
    

提交回复
热议问题