2011-04-14 80 views

回答

1

如果JSON字符串是静态的,则可以将其作为ExternalMeshResource加载(有关如何使用此资源,请参阅http://code.google.com/p/gwt-g3d/source/browse/trunk/gwt-g3d-test/src/gwt/g3d/test/client/Lesson14Demo.java)。

如果没有,你可以使用JSONParser.parse(jsonString)得到一个JSON值对象,然后像做

Float32Array.create(jsonObj.get(fieldName).isArray().getJavaScriptObject().<JsArrayNumber>cast()); 

以得到一个TypeArray可以传递到StaticMesh。上面的fieldName取决于你的json字符串对象。例如,如果你的JSON看起来像:

{ 
    "vertexPositions" : [0, 1, 2, ...] 
    "vertexNormals" : [0, 1, 0, ...] 
    "indices" : [0, 1, 2, ...] 
} 

那么你fieldName可以 “vertexPositions”, “vertexNormals” 和 “指标”。 (请注意,索引数组通常是​​而不是Float32Array)。请参阅implementation of AbstractMeshResource以获取更多信息