How can I create a mesh (instance of StaticMesh) from a JSON string in gwt-g3d (http开发者_如何转开发://code.google.com/p/gwt-g3d/)?
If the JSON string is static, you can load it as an ExternalMeshResource (see http://code.google.com/p/gwt-g3d/source/browse/trunk/gwt-g3d-test/src/gwt/g3d/test/client/Lesson14Demo.java on how to use this resource).
If not, you can use JSONParser.parse(jsonString)
to get a JSON value object, then do something like
Float32Array.create(jsonObj.get(fieldName).isArray().getJavaScriptObject().<JsArrayNumber>cast());
to gets a TypeArray
that you can pass to StaticMesh
. The fieldName
above depends on your json string object. For example, if you json looks something like:
{
"vertexPositions" : [0, 1, 2, ...]
"vertexNormals" : [0, 1, 0, ...]
"indices" : [0, 1, 2, ...]
}
then your fieldName
can be "vertexPositions", "vertexNormals", and "indices". (Note that the indices array is usually of type Uint16Array
instead of Float32Array
). See the implementation of AbstractMeshResource for more information
精彩评论