Merge branch 'master' of https://github.com/jMonkeyEngine/jmonkeyengine into GL4ShaderSupport
Conflicts: jme3-core/src/main/resources/com/jme3/asset/Desktop.cfgexperimental
commit
5b58bda23f
@ -1,111 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (c) 2009-2012 jMonkeyEngine |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or without |
|
||||||
* modification, are permitted provided that the following conditions are |
|
||||||
* met: |
|
||||||
* |
|
||||||
* * Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* |
|
||||||
* * Redistributions in binary form must reproduce the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer in the |
|
||||||
* documentation and/or other materials provided with the distribution. |
|
||||||
* |
|
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
|
||||||
* may be used to endorse or promote products derived from this software |
|
||||||
* without specific prior written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
*/ |
|
||||||
package com.jme3.asset; |
|
||||||
|
|
||||||
import com.jme3.asset.plugins.AndroidLocator; |
|
||||||
import com.jme3.asset.plugins.ClasspathLocator; |
|
||||||
import com.jme3.audio.plugins.AndroidAudioLoader; |
|
||||||
import com.jme3.audio.plugins.NativeVorbisLoader; |
|
||||||
import com.jme3.audio.plugins.WAVLoader; |
|
||||||
import com.jme3.system.AppSettings; |
|
||||||
import com.jme3.system.android.JmeAndroidSystem; |
|
||||||
import com.jme3.texture.plugins.AndroidBufferImageLoader; |
|
||||||
import com.jme3.texture.plugins.AndroidNativeImageLoader; |
|
||||||
import java.net.URL; |
|
||||||
import java.util.logging.Level; |
|
||||||
import java.util.logging.Logger; |
|
||||||
|
|
||||||
/** |
|
||||||
* <code>AndroidAssetManager</code> is an implementation of DesktopAssetManager for Android |
|
||||||
* |
|
||||||
* @author larynx |
|
||||||
*/ |
|
||||||
public class AndroidAssetManager extends DesktopAssetManager { |
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(AndroidAssetManager.class.getName()); |
|
||||||
|
|
||||||
private void registerLoaderSafe(String loaderClass, String ... extensions) { |
|
||||||
try { |
|
||||||
Class<? extends AssetLoader> loader = (Class<? extends AssetLoader>) Class.forName(loaderClass); |
|
||||||
registerLoader(loader, extensions); |
|
||||||
} catch (Exception e){ |
|
||||||
logger.log(Level.WARNING, "Failed to load AssetLoader", e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* AndroidAssetManager constructor |
|
||||||
* If URL == null then a default list of locators and loaders for android is set |
|
||||||
* @param configFile |
|
||||||
*/ |
|
||||||
public AndroidAssetManager(URL configFile) { |
|
||||||
System.setProperty("org.xml.sax.driver", "org.xmlpull.v1.sax2.Driver"); |
|
||||||
|
|
||||||
// Set Default Android config
|
|
||||||
registerLocator("", AndroidLocator.class); |
|
||||||
registerLocator("", ClasspathLocator.class); |
|
||||||
|
|
||||||
registerLoader(AndroidNativeImageLoader.class, "jpg", "jpeg", "bmp", "gif", "png"); |
|
||||||
|
|
||||||
if (JmeAndroidSystem.getAudioRendererType().equals(AppSettings.ANDROID_MEDIAPLAYER)) { |
|
||||||
registerLoader(AndroidAudioLoader.class, "ogg", "mp3", "wav"); |
|
||||||
} else if (JmeAndroidSystem.getAudioRendererType().equals(AppSettings.ANDROID_OPENAL_SOFT)) { |
|
||||||
registerLoader(WAVLoader.class, "wav"); |
|
||||||
registerLoader(NativeVorbisLoader.class, "ogg"); |
|
||||||
} else { |
|
||||||
throw new IllegalStateException("No Audio Renderer Type defined!"); |
|
||||||
} |
|
||||||
|
|
||||||
registerLoader(com.jme3.material.plugins.J3MLoader.class, "j3m"); |
|
||||||
registerLoader(com.jme3.material.plugins.J3MLoader.class, "j3md"); |
|
||||||
registerLoader(com.jme3.material.plugins.ShaderNodeDefinitionLoader.class, "j3sn"); |
|
||||||
registerLoader(com.jme3.shader.plugins.GLSLLoader.class, "vert", "frag", "glsl", "glsllib"); |
|
||||||
registerLoader(com.jme3.export.binary.BinaryImporter.class, "j3o"); |
|
||||||
registerLoader(com.jme3.font.plugins.BitmapFontLoader.class, "fnt"); |
|
||||||
|
|
||||||
// Less common loaders (especially on Android)
|
|
||||||
registerLoaderSafe("com.jme3.texture.plugins.DDSLoader", "dds"); |
|
||||||
registerLoaderSafe("com.jme3.texture.plugins.PFMLoader", "pfm"); |
|
||||||
registerLoaderSafe("com.jme3.texture.plugins.HDRLoader", "hdr"); |
|
||||||
registerLoaderSafe("com.jme3.texture.plugins.TGALoader", "tga"); |
|
||||||
registerLoaderSafe("com.jme3.scene.plugins.OBJLoader", "obj"); |
|
||||||
registerLoaderSafe("com.jme3.scene.plugins.MTLLoader", "mtl"); |
|
||||||
registerLoaderSafe("com.jme3.scene.plugins.ogre.MeshLoader", "mesh.xml"); |
|
||||||
registerLoaderSafe("com.jme3.scene.plugins.ogre.SkeletonLoader", "skeleton.xml"); |
|
||||||
registerLoaderSafe("com.jme3.scene.plugins.ogre.MaterialLoader", "material"); |
|
||||||
registerLoaderSafe("com.jme3.scene.plugins.ogre.SceneLoader", "scene"); |
|
||||||
|
|
||||||
|
|
||||||
logger.fine("AndroidAssetManager created."); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,8 @@ |
|||||||
|
INCLUDE com/jme3/asset/General.cfg |
||||||
|
|
||||||
|
# Android specific locators |
||||||
|
LOCATOR / com.jme3.asset.plugins.AndroidLocator |
||||||
|
|
||||||
|
# Android specific loaders |
||||||
|
LOADER com.jme3.texture.plugins.AndroidNativeImageLoader : jpg, bmp, gif, png, jpeg |
||||||
|
LOADER com.jme3.audio.plugins.NativeVorbisLoader : ogg |
@ -0,0 +1,30 @@ |
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
||||||
|
<html> |
||||||
|
|
||||||
|
<head> |
||||||
|
<title></title> |
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
|
||||||
|
<code>com.jme3.asset.cache</code> contains the {@link com.jme3.asset.cache.AssetCache} |
||||||
|
interface as well as its implementations.<br> |
||||||
|
|
||||||
|
<p> |
||||||
|
|
||||||
|
<h3>AssetCaches</h3> |
||||||
|
The asset cache implementations are used by {@link com.jme3.asset.AssetManager} |
||||||
|
to cache loaded assets for faster access if they are requested again. |
||||||
|
<p> |
||||||
|
Assets in jME3 are cached in such a way that if there are no instances of |
||||||
|
that asset anymore in memory, then jME3 is likely to reclaim them. |
||||||
|
Some asset types must be cloned prior to being used, for example, 3D models |
||||||
|
cannot be stored in the cache as-is, because the user is likely to modify them |
||||||
|
after loading them. To handle this, a copy of the asset is stored in the |
||||||
|
cache instead. The asset cache that implements these rules is the |
||||||
|
{@link com.jme3.asset.cache.WeakRefCloneAssetCache} and it is used |
||||||
|
for caching most asset types. |
||||||
|
|
||||||
|
</body> |
||||||
|
</html> |
||||||
|
|
@ -0,0 +1,26 @@ |
|||||||
|
# Generic locators that should be supported on all platforms. |
||||||
|
LOCATOR / com.jme3.asset.plugins.ClasspathLocator |
||||||
|
|
||||||
|
# Generic loaders that should be supported on all platforms. |
||||||
|
LOADER com.jme3.audio.plugins.WAVLoader : wav |
||||||
|
LOADER com.jme3.cursors.plugins.CursorLoader : ani, cur, ico |
||||||
|
LOADER com.jme3.material.plugins.J3MLoader : j3m |
||||||
|
LOADER com.jme3.material.plugins.J3MLoader : j3md |
||||||
|
LOADER com.jme3.material.plugins.ShaderNodeDefinitionLoader : j3sn |
||||||
|
LOADER com.jme3.font.plugins.BitmapFontLoader : fnt |
||||||
|
LOADER com.jme3.texture.plugins.DDSLoader : dds |
||||||
|
LOADER com.jme3.texture.plugins.PFMLoader : pfm |
||||||
|
LOADER com.jme3.texture.plugins.HDRLoader : hdr |
||||||
|
LOADER com.jme3.texture.plugins.TGALoader : tga |
||||||
|
LOADER com.jme3.export.binary.BinaryImporter : j3o |
||||||
|
LOADER com.jme3.export.binary.BinaryImporter : j3f |
||||||
|
LOADER com.jme3.scene.plugins.OBJLoader : obj |
||||||
|
LOADER com.jme3.scene.plugins.MTLLoader : mtl |
||||||
|
LOADER com.jme3.scene.plugins.ogre.MeshLoader : meshxml, mesh.xml |
||||||
|
LOADER com.jme3.scene.plugins.ogre.SkeletonLoader : skeletonxml, skeleton.xml |
||||||
|
LOADER com.jme3.scene.plugins.ogre.MaterialLoader : material |
||||||
|
LOADER com.jme3.scene.plugins.ogre.SceneLoader : scene |
||||||
|
LOADER com.jme3.scene.plugins.blender.BlenderModelLoader : blend |
||||||
|
LOADER com.jme3.shader.plugins.GLSLLoader : vert, frag, glsl, glsllib |
||||||
|
LOADER com.jme3.scene.plugins.fbx.SceneLoader : fbx |
||||||
|
LOADER com.jme3.scene.plugins.fbx.SceneWithAnimationLoader : fba |
@ -1,80 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (c) 2009-2012 jMonkeyEngine |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or without |
|
||||||
* modification, are permitted provided that the following conditions are |
|
||||||
* met: |
|
||||||
* |
|
||||||
* * Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* |
|
||||||
* * Redistributions in binary form must reproduce the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer in the |
|
||||||
* documentation and/or other materials provided with the distribution. |
|
||||||
* |
|
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
|
||||||
* may be used to endorse or promote products derived from this software |
|
||||||
* without specific prior written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
*/ |
|
||||||
|
|
||||||
package jme3tools.converters; |
|
||||||
|
|
||||||
import com.jme3.asset.AssetManager; |
|
||||||
import com.jme3.system.JmeSystem; |
|
||||||
import java.io.File; |
|
||||||
import java.io.FileOutputStream; |
|
||||||
import java.io.IOException; |
|
||||||
import java.util.jar.JarEntry; |
|
||||||
import java.util.jar.JarOutputStream; |
|
||||||
|
|
||||||
public class FolderConverter { |
|
||||||
|
|
||||||
private static AssetManager assetManager; |
|
||||||
private static File sourceRoot; |
|
||||||
private static JarOutputStream jarOut; |
|
||||||
private static long time; |
|
||||||
|
|
||||||
private static void process(File file) throws IOException{ |
|
||||||
String name = file.getName().replaceAll("[\\/\\.]", "_"); |
|
||||||
JarEntry entry = new JarEntry(name); |
|
||||||
entry.setTime(time); |
|
||||||
|
|
||||||
jarOut.putNextEntry(entry); |
|
||||||
} |
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException{ |
|
||||||
if (args.length == 0){ |
|
||||||
System.out.println("Usage: java -jar FolderConverter <input folder>"); |
|
||||||
System.out.println(); |
|
||||||
System.out.println(" Converts files from input to output"); |
|
||||||
System.exit(1); |
|
||||||
} |
|
||||||
|
|
||||||
sourceRoot = new File(args[0]); |
|
||||||
|
|
||||||
File jarFile = new File(sourceRoot.getParent(), sourceRoot.getName()+".jar"); |
|
||||||
FileOutputStream out = new FileOutputStream(jarFile); |
|
||||||
jarOut = new JarOutputStream(out); |
|
||||||
|
|
||||||
assetManager = JmeSystem.newAssetManager(); |
|
||||||
assetManager.registerLocator(sourceRoot.toString(), |
|
||||||
"com.jme3.asset.plugins.FileSystemLocator"); |
|
||||||
for (File f : sourceRoot.listFiles()){ |
|
||||||
process(f); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,351 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (c) 2009-2012 jMonkeyEngine |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or without |
|
||||||
* modification, are permitted provided that the following conditions are |
|
||||||
* met: |
|
||||||
* |
|
||||||
* * Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* |
|
||||||
* * Redistributions in binary form must reproduce the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer in the |
|
||||||
* documentation and/or other materials provided with the distribution. |
|
||||||
* |
|
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
|
||||||
* may be used to endorse or promote products derived from this software |
|
||||||
* without specific prior written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
*/ |
|
||||||
|
|
||||||
package jme3tools.converters.model; |
|
||||||
|
|
||||||
import com.jme3.bounding.BoundingBox; |
|
||||||
import com.jme3.math.Transform; |
|
||||||
import com.jme3.math.Vector2f; |
|
||||||
import com.jme3.math.Vector3f; |
|
||||||
import com.jme3.scene.Geometry; |
|
||||||
import com.jme3.scene.Mesh; |
|
||||||
import com.jme3.scene.VertexBuffer; |
|
||||||
import com.jme3.scene.VertexBuffer.Format; |
|
||||||
import com.jme3.scene.VertexBuffer.Type; |
|
||||||
import com.jme3.scene.VertexBuffer.Usage; |
|
||||||
import com.jme3.scene.mesh.IndexBuffer; |
|
||||||
import com.jme3.util.BufferUtils; |
|
||||||
import java.nio.*; |
|
||||||
|
|
||||||
@Deprecated |
|
||||||
public class FloatToFixed { |
|
||||||
|
|
||||||
private static final float shortSize = Short.MAX_VALUE - Short.MIN_VALUE; |
|
||||||
private static final float shortOff = (Short.MAX_VALUE + Short.MIN_VALUE) * 0.5f; |
|
||||||
|
|
||||||
private static final float byteSize = Byte.MAX_VALUE - Byte.MIN_VALUE; |
|
||||||
private static final float byteOff = (Byte.MAX_VALUE + Byte.MIN_VALUE) * 0.5f; |
|
||||||
|
|
||||||
@Deprecated |
|
||||||
public static void convertToFixed(Geometry geom, Format posFmt, Format nmFmt, Format tcFmt){ |
|
||||||
geom.updateModelBound(); |
|
||||||
BoundingBox bbox = (BoundingBox) geom.getModelBound(); |
|
||||||
Mesh mesh = geom.getMesh(); |
|
||||||
|
|
||||||
VertexBuffer positions = mesh.getBuffer(Type.Position); |
|
||||||
VertexBuffer normals = mesh.getBuffer(Type.Normal); |
|
||||||
VertexBuffer texcoords = mesh.getBuffer(Type.TexCoord); |
|
||||||
VertexBuffer indices = mesh.getBuffer(Type.Index); |
|
||||||
|
|
||||||
// positions
|
|
||||||
FloatBuffer fb = (FloatBuffer) positions.getData(); |
|
||||||
if (posFmt != Format.Float){ |
|
||||||
Buffer newBuf = VertexBuffer.createBuffer(posFmt, positions.getNumComponents(), |
|
||||||
mesh.getVertexCount()); |
|
||||||
Transform t = convertPositions(fb, bbox, newBuf); |
|
||||||
t.combineWithParent(geom.getLocalTransform()); |
|
||||||
geom.setLocalTransform(t); |
|
||||||
|
|
||||||
VertexBuffer newPosVb = new VertexBuffer(Type.Position); |
|
||||||
newPosVb.setupData(positions.getUsage(), |
|
||||||
positions.getNumComponents(), |
|
||||||
posFmt, |
|
||||||
newBuf); |
|
||||||
mesh.clearBuffer(Type.Position); |
|
||||||
mesh.setBuffer(newPosVb); |
|
||||||
} |
|
||||||
|
|
||||||
// normals, automatically convert to signed byte
|
|
||||||
fb = (FloatBuffer) normals.getData(); |
|
||||||
|
|
||||||
ByteBuffer bb = BufferUtils.createByteBuffer(fb.capacity()); |
|
||||||
convertNormals(fb, bb); |
|
||||||
|
|
||||||
normals = new VertexBuffer(Type.Normal); |
|
||||||
normals.setupData(Usage.Static, 3, Format.Byte, bb); |
|
||||||
normals.setNormalized(true); |
|
||||||
mesh.clearBuffer(Type.Normal); |
|
||||||
mesh.setBuffer(normals); |
|
||||||
|
|
||||||
// texcoords
|
|
||||||
fb = (FloatBuffer) texcoords.getData(); |
|
||||||
if (tcFmt != Format.Float){ |
|
||||||
Buffer newBuf = VertexBuffer.createBuffer(tcFmt, |
|
||||||
texcoords.getNumComponents(), |
|
||||||
mesh.getVertexCount()); |
|
||||||
convertTexCoords2D(fb, newBuf); |
|
||||||
|
|
||||||
VertexBuffer newTcVb = new VertexBuffer(Type.TexCoord); |
|
||||||
newTcVb.setupData(texcoords.getUsage(), |
|
||||||
texcoords.getNumComponents(), |
|
||||||
tcFmt, |
|
||||||
newBuf); |
|
||||||
mesh.clearBuffer(Type.TexCoord); |
|
||||||
mesh.setBuffer(newTcVb); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static void compressIndexBuffer(Mesh mesh){ |
|
||||||
int vertCount = mesh.getVertexCount(); |
|
||||||
VertexBuffer vb = mesh.getBuffer(Type.Index); |
|
||||||
Format targetFmt; |
|
||||||
if (vb.getFormat() == Format.UnsignedInt && vertCount <= 0xffff){ |
|
||||||
if (vertCount <= 256) |
|
||||||
targetFmt = Format.UnsignedByte; |
|
||||||
else |
|
||||||
targetFmt = Format.UnsignedShort; |
|
||||||
}else if (vb.getFormat() == Format.UnsignedShort && vertCount <= 0xff){ |
|
||||||
targetFmt = Format.UnsignedByte; |
|
||||||
}else{ |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
IndexBuffer src = mesh.getIndexBuffer(); |
|
||||||
Buffer newBuf = VertexBuffer.createBuffer(targetFmt, vb.getNumComponents(), src.size()); |
|
||||||
|
|
||||||
VertexBuffer newVb = new VertexBuffer(Type.Index); |
|
||||||
newVb.setupData(vb.getUsage(), vb.getNumComponents(), targetFmt, newBuf); |
|
||||||
mesh.clearBuffer(Type.Index); |
|
||||||
mesh.setBuffer(newVb); |
|
||||||
|
|
||||||
IndexBuffer dst = mesh.getIndexBuffer(); |
|
||||||
for (int i = 0; i < src.size(); i++){ |
|
||||||
dst.put(i, src.get(i)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private static void convertToFixed(FloatBuffer input, IntBuffer output){ |
|
||||||
if (output.capacity() < input.capacity()) |
|
||||||
throw new RuntimeException("Output must be at least as large as input!"); |
|
||||||
|
|
||||||
input.clear(); |
|
||||||
output.clear(); |
|
||||||
for (int i = 0; i < input.capacity(); i++){ |
|
||||||
output.put( (int) (input.get() * (float)(1<<16)) ); |
|
||||||
} |
|
||||||
output.flip(); |
|
||||||
} |
|
||||||
|
|
||||||
private static void convertToFloat(IntBuffer input, FloatBuffer output){ |
|
||||||
if (output.capacity() < input.capacity()) |
|
||||||
throw new RuntimeException("Output must be at least as large as input!"); |
|
||||||
|
|
||||||
input.clear(); |
|
||||||
output.clear(); |
|
||||||
for (int i = 0; i < input.capacity(); i++){ |
|
||||||
output.put( ((float)input.get() / (float)(1<<16)) ); |
|
||||||
} |
|
||||||
output.flip(); |
|
||||||
} |
|
||||||
|
|
||||||
private static void convertToUByte(FloatBuffer input, ByteBuffer output){ |
|
||||||
if (output.capacity() < input.capacity()) |
|
||||||
throw new RuntimeException("Output must be at least as large as input!"); |
|
||||||
|
|
||||||
input.clear(); |
|
||||||
output.clear(); |
|
||||||
for (int i = 0; i < input.capacity(); i++){ |
|
||||||
output.put( (byte) (input.get() * 255f) ); |
|
||||||
} |
|
||||||
output.flip(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public static VertexBuffer convertToUByte(VertexBuffer vb){ |
|
||||||
FloatBuffer fb = (FloatBuffer) vb.getData(); |
|
||||||
ByteBuffer bb = BufferUtils.createByteBuffer(fb.capacity()); |
|
||||||
convertToUByte(fb, bb); |
|
||||||
|
|
||||||
VertexBuffer newVb = new VertexBuffer(vb.getBufferType()); |
|
||||||
newVb.setupData(vb.getUsage(), |
|
||||||
vb.getNumComponents(), |
|
||||||
Format.UnsignedByte, |
|
||||||
bb); |
|
||||||
newVb.setNormalized(true); |
|
||||||
return newVb; |
|
||||||
} |
|
||||||
|
|
||||||
public static VertexBuffer convertToFixed(VertexBuffer vb){ |
|
||||||
if (vb.getFormat() == Format.Int) |
|
||||||
return vb; |
|
||||||
|
|
||||||
FloatBuffer fb = (FloatBuffer) vb.getData(); |
|
||||||
IntBuffer ib = BufferUtils.createIntBuffer(fb.capacity()); |
|
||||||
convertToFixed(fb, ib); |
|
||||||
|
|
||||||
VertexBuffer newVb = new VertexBuffer(vb.getBufferType()); |
|
||||||
newVb.setupData(vb.getUsage(), |
|
||||||
vb.getNumComponents(), |
|
||||||
Format.Int, |
|
||||||
ib); |
|
||||||
return newVb; |
|
||||||
} |
|
||||||
|
|
||||||
public static VertexBuffer convertToFloat(VertexBuffer vb){ |
|
||||||
if (vb.getFormat() == Format.Float) |
|
||||||
return vb; |
|
||||||
|
|
||||||
IntBuffer ib = (IntBuffer) vb.getData(); |
|
||||||
FloatBuffer fb = BufferUtils.createFloatBuffer(ib.capacity()); |
|
||||||
convertToFloat(ib, fb); |
|
||||||
|
|
||||||
VertexBuffer newVb = new VertexBuffer(vb.getBufferType()); |
|
||||||
newVb.setupData(vb.getUsage(), |
|
||||||
vb.getNumComponents(), |
|
||||||
Format.Float, |
|
||||||
fb); |
|
||||||
return newVb; |
|
||||||
} |
|
||||||
|
|
||||||
private static void convertNormals(FloatBuffer input, ByteBuffer output){ |
|
||||||
if (output.capacity() < input.capacity()) |
|
||||||
throw new RuntimeException("Output must be at least as large as input!"); |
|
||||||
|
|
||||||
input.clear(); |
|
||||||
output.clear(); |
|
||||||
Vector3f temp = new Vector3f(); |
|
||||||
int vertexCount = input.capacity() / 3; |
|
||||||
for (int i = 0; i < vertexCount; i++){ |
|
||||||
BufferUtils.populateFromBuffer(temp, input, i); |
|
||||||
|
|
||||||
// offset and scale vector into -128 ... 127
|
|
||||||
temp.multLocal(127).addLocal(0.5f, 0.5f, 0.5f); |
|
||||||
|
|
||||||
// quantize
|
|
||||||
byte v1 = (byte) temp.getX(); |
|
||||||
byte v2 = (byte) temp.getY(); |
|
||||||
byte v3 = (byte) temp.getZ(); |
|
||||||
|
|
||||||
// store
|
|
||||||
output.put(v1).put(v2).put(v3); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private static void convertTexCoords2D(FloatBuffer input, Buffer output){ |
|
||||||
if (output.capacity() < input.capacity()) |
|
||||||
throw new RuntimeException("Output must be at least as large as input!"); |
|
||||||
|
|
||||||
input.clear(); |
|
||||||
output.clear(); |
|
||||||
Vector2f temp = new Vector2f(); |
|
||||||
int vertexCount = input.capacity() / 2; |
|
||||||
|
|
||||||
ShortBuffer sb = null; |
|
||||||
IntBuffer ib = null; |
|
||||||
|
|
||||||
if (output instanceof ShortBuffer) |
|
||||||
sb = (ShortBuffer) output; |
|
||||||
else if (output instanceof IntBuffer) |
|
||||||
ib = (IntBuffer) output; |
|
||||||
else |
|
||||||
throw new UnsupportedOperationException(); |
|
||||||
|
|
||||||
for (int i = 0; i < vertexCount; i++){ |
|
||||||
BufferUtils.populateFromBuffer(temp, input, i); |
|
||||||
|
|
||||||
if (sb != null){ |
|
||||||
sb.put( (short) (temp.getX()*Short.MAX_VALUE) ); |
|
||||||
sb.put( (short) (temp.getY()*Short.MAX_VALUE) ); |
|
||||||
}else{ |
|
||||||
int v1 = (int) (temp.getX() * ((float)(1 << 16))); |
|
||||||
int v2 = (int) (temp.getY() * ((float)(1 << 16))); |
|
||||||
ib.put(v1).put(v2); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private static Transform convertPositions(FloatBuffer input, BoundingBox bbox, Buffer output){ |
|
||||||
if (output.capacity() < input.capacity()) |
|
||||||
throw new RuntimeException("Output must be at least as large as input!"); |
|
||||||
|
|
||||||
Vector3f offset = bbox.getCenter().negate(); |
|
||||||
Vector3f size = new Vector3f(bbox.getXExtent(), bbox.getYExtent(), bbox.getZExtent()); |
|
||||||
size.multLocal(2); |
|
||||||
|
|
||||||
ShortBuffer sb = null; |
|
||||||
ByteBuffer bb = null; |
|
||||||
float dataTypeSize; |
|
||||||
float dataTypeOffset; |
|
||||||
if (output instanceof ShortBuffer){ |
|
||||||
sb = (ShortBuffer) output; |
|
||||||
dataTypeOffset = shortOff; |
|
||||||
dataTypeSize = shortSize; |
|
||||||
}else{ |
|
||||||
bb = (ByteBuffer) output; |
|
||||||
dataTypeOffset = byteOff; |
|
||||||
dataTypeSize = byteSize; |
|
||||||
} |
|
||||||
Vector3f scale = new Vector3f(); |
|
||||||
scale.set(dataTypeSize, dataTypeSize, dataTypeSize).divideLocal(size); |
|
||||||
|
|
||||||
Vector3f invScale = new Vector3f(); |
|
||||||
invScale.set(size).divideLocal(dataTypeSize); |
|
||||||
|
|
||||||
offset.multLocal(scale); |
|
||||||
offset.addLocal(dataTypeOffset, dataTypeOffset, dataTypeOffset); |
|
||||||
|
|
||||||
// offset = (-modelOffset * shortSize)/modelSize + shortOff
|
|
||||||
// scale = shortSize / modelSize
|
|
||||||
|
|
||||||
input.clear(); |
|
||||||
output.clear(); |
|
||||||
Vector3f temp = new Vector3f(); |
|
||||||
int vertexCount = input.capacity() / 3; |
|
||||||
for (int i = 0; i < vertexCount; i++){ |
|
||||||
BufferUtils.populateFromBuffer(temp, input, i); |
|
||||||
|
|
||||||
// offset and scale vector into -32768 ... 32767
|
|
||||||
// or into -128 ... 127 if using bytes
|
|
||||||
temp.multLocal(scale); |
|
||||||
temp.addLocal(offset); |
|
||||||
|
|
||||||
// quantize and store
|
|
||||||
if (sb != null){ |
|
||||||
short v1 = (short) temp.getX(); |
|
||||||
short v2 = (short) temp.getY(); |
|
||||||
short v3 = (short) temp.getZ(); |
|
||||||
sb.put(v1).put(v2).put(v3); |
|
||||||
}else{ |
|
||||||
byte v1 = (byte) temp.getX(); |
|
||||||
byte v2 = (byte) temp.getY(); |
|
||||||
byte v3 = (byte) temp.getZ(); |
|
||||||
bb.put(v1).put(v2).put(v3); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
Transform transform = new Transform(); |
|
||||||
transform.setTranslation(offset.negate().multLocal(invScale)); |
|
||||||
transform.setScale(invScale); |
|
||||||
return transform; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,4 @@ |
|||||||
|
INCLUDE com/jme3/asset/General.cfg |
||||||
|
|
||||||
|
# IOS specific loaders |
||||||
|
LOADER com.jme3.system.ios.IosImageLoader : jpg, bmp, gif, png, jpeg |
@ -1,109 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (c) 2009-2012 jMonkeyEngine |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or without |
|
||||||
* modification, are permitted provided that the following conditions are |
|
||||||
* met: |
|
||||||
* |
|
||||||
* * Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* |
|
||||||
* * Redistributions in binary form must reproduce the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer in the |
|
||||||
* documentation and/or other materials provided with the distribution. |
|
||||||
* |
|
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
|
||||||
* may be used to endorse or promote products derived from this software |
|
||||||
* without specific prior written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
*/ |
|
||||||
package com.jme3.system.ios; |
|
||||||
|
|
||||||
import com.jme3.asset.AssetLoader; |
|
||||||
import com.jme3.asset.DesktopAssetManager; |
|
||||||
import com.jme3.asset.TextureKey; |
|
||||||
import com.jme3.asset.plugins.ClasspathLocator; |
|
||||||
import com.jme3.audio.plugins.WAVLoader; |
|
||||||
import com.jme3.texture.Texture; |
|
||||||
import java.io.InputStream; |
|
||||||
import java.net.URL; |
|
||||||
import java.util.logging.Level; |
|
||||||
import java.util.logging.Logger; |
|
||||||
|
|
||||||
/** |
|
||||||
* |
|
||||||
* @author normenhansen |
|
||||||
*/ |
|
||||||
public class IosAssetManager extends DesktopAssetManager { |
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(IosAssetManager.class.getName()); |
|
||||||
|
|
||||||
public IosAssetManager() { |
|
||||||
this(null); |
|
||||||
} |
|
||||||
|
|
||||||
@Deprecated |
|
||||||
public IosAssetManager(boolean loadDefaults) { |
|
||||||
//this(Thread.currentThread().getContextClassLoader().getResource("com/jme3/asset/Android.cfg"));
|
|
||||||
this(null); |
|
||||||
} |
|
||||||
|
|
||||||
private void registerLoaderSafe(String loaderClass, String ... extensions) { |
|
||||||
try { |
|
||||||
Class<? extends AssetLoader> loader = (Class<? extends AssetLoader>) Class.forName(loaderClass); |
|
||||||
registerLoader(loader, extensions); |
|
||||||
} catch (Exception e){ |
|
||||||
logger.log(Level.WARNING, "Failed to load AssetLoader", e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* AndroidAssetManager constructor |
|
||||||
* If URL == null then a default list of locators and loaders for android is set |
|
||||||
* @param configFile |
|
||||||
*/ |
|
||||||
public IosAssetManager(URL configFile) { |
|
||||||
System.setProperty("org.xml.sax.driver", "org.xmlpull.v1.sax2.Driver"); |
|
||||||
|
|
||||||
// Set Default iOS config
|
|
||||||
registerLocator("", ClasspathLocator.class); |
|
||||||
|
|
||||||
registerLoader(IosImageLoader.class, "jpg", "bmp", "gif", "png", "jpeg"); |
|
||||||
//registerLoader(AndroidImageLoader.class, "jpg", "bmp", "gif", "png", "jpeg");
|
|
||||||
//registerLoader(AndroidAudioLoader.class, "ogg", "mp3", "wav");
|
|
||||||
registerLoader(com.jme3.material.plugins.J3MLoader.class, "j3m"); |
|
||||||
registerLoader(com.jme3.material.plugins.J3MLoader.class, "j3md"); |
|
||||||
registerLoader(com.jme3.shader.plugins.GLSLLoader.class, "vert", "frag", "glsl", "glsllib"); |
|
||||||
registerLoader(com.jme3.export.binary.BinaryImporter.class, "j3o"); |
|
||||||
registerLoader(com.jme3.font.plugins.BitmapFontLoader.class, "fnt"); |
|
||||||
registerLoader(WAVLoader.class, "wav"); |
|
||||||
|
|
||||||
// Less common loaders (especially on iOS)
|
|
||||||
registerLoaderSafe("com.jme3.audio.plugins.OGGLoader", "ogg"); |
|
||||||
registerLoaderSafe("com.jme3.texture.plugins.DDSLoader", "dds"); |
|
||||||
registerLoaderSafe("com.jme3.texture.plugins.PFMLoader", "pfm"); |
|
||||||
registerLoaderSafe("com.jme3.texture.plugins.HDRLoader", "hdr"); |
|
||||||
registerLoaderSafe("com.jme3.texture.plugins.TGALoader", "tga"); |
|
||||||
registerLoaderSafe("com.jme3.scene.plugins.OBJLoader", "obj"); |
|
||||||
registerLoaderSafe("com.jme3.scene.plugins.MTLLoader", "mtl"); |
|
||||||
registerLoaderSafe("com.jme3.scene.plugins.ogre.MeshLoader", "mesh.xml"); |
|
||||||
registerLoaderSafe("com.jme3.scene.plugins.ogre.SkeletonLoader", "skeleton.xml"); |
|
||||||
registerLoaderSafe("com.jme3.scene.plugins.ogre.MaterialLoader", "material"); |
|
||||||
registerLoaderSafe("com.jme3.scene.plugins.ogre.SceneLoader", "scene"); |
|
||||||
|
|
||||||
|
|
||||||
logger.fine("IosAssetManager created."); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,224 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2009-2015 jMonkeyEngine |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* Redistribution and use in source and binary forms, with or without |
||||||
|
* modification, are permitted provided that the following conditions are |
||||||
|
* met: |
||||||
|
* |
||||||
|
* * Redistributions of source code must retain the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer. |
||||||
|
* |
||||||
|
* * Redistributions in binary form must reproduce the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer in the |
||||||
|
* documentation and/or other materials provided with the distribution. |
||||||
|
* |
||||||
|
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||||
|
* may be used to endorse or promote products derived from this software |
||||||
|
* without specific prior written permission. |
||||||
|
* |
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
|
*/ |
||||||
|
package com.jme3.scene.plugins.fbx.file; |
||||||
|
|
||||||
|
import java.io.OutputStream; |
||||||
|
import java.io.PrintStream; |
||||||
|
import java.lang.reflect.Array; |
||||||
|
import java.text.DecimalFormat; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
import static org.omg.IOP.IORHelper.id; |
||||||
|
|
||||||
|
/** |
||||||
|
* Quick n' dirty dumper of FBX binary files. |
||||||
|
* |
||||||
|
* Outputs a format similar to an ASCII FBX file. |
||||||
|
* |
||||||
|
* @author Kirill Vainer |
||||||
|
*/ |
||||||
|
public final class FBXDump { |
||||||
|
|
||||||
|
private static final DecimalFormat DECIMAL_FORMAT |
||||||
|
= new DecimalFormat("0.0000000000"); |
||||||
|
|
||||||
|
private FBXDump() { } |
||||||
|
|
||||||
|
/** |
||||||
|
* Creates a map between object UIDs and the objects themselves. |
||||||
|
* |
||||||
|
* @param file The file to create the mappings for. |
||||||
|
* @return The UID to object map. |
||||||
|
*/ |
||||||
|
private static Map<Long, FBXElement> createUidToObjectMap(FBXFile file) { |
||||||
|
Map<Long, FBXElement> uidToObjectMap = new HashMap<Long, FBXElement>(); |
||||||
|
for (FBXElement rootElement : file.rootElements) { |
||||||
|
if (rootElement.id.equals("Objects")) { |
||||||
|
for (FBXElement fbxObj : rootElement.children) { |
||||||
|
if (fbxObj.propertiesTypes[0] != 'L') { |
||||||
|
continue; // error
|
||||||
|
} |
||||||
|
Long uid = (Long) fbxObj.properties.get(0); |
||||||
|
uidToObjectMap.put(uid, fbxObj); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return uidToObjectMap; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Dump FBX to standard output. |
||||||
|
* |
||||||
|
* @param file the file to dump. |
||||||
|
*/ |
||||||
|
public static void dumpFBX(FBXFile file) { |
||||||
|
dumpFBX(file, System.out); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Dump FBX to the given output stream. |
||||||
|
* |
||||||
|
* @param file the file to dump. |
||||||
|
* @param out the output stream where to output. |
||||||
|
*/ |
||||||
|
public static void dumpFBX(FBXFile file, OutputStream out) { |
||||||
|
Map<Long, FBXElement> uidToObjectMap = createUidToObjectMap(file); |
||||||
|
PrintStream ps = new PrintStream(out); |
||||||
|
for (FBXElement rootElement : file.rootElements) { |
||||||
|
dumpFBXElement(rootElement, ps, 0, uidToObjectMap); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static String indent(int amount) { |
||||||
|
return " ".substring(0, amount); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Convert FBX string - this replaces all instances of |
||||||
|
* <code>\x00\x01</code> to "::". |
||||||
|
* |
||||||
|
* @param string The string to convert |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private static String convertFBXString(String string) { |
||||||
|
return string.replaceAll("\u0000\u0001", "::"); |
||||||
|
} |
||||||
|
|
||||||
|
protected static void dumpFBXProperty(String id, char propertyType, |
||||||
|
Object property, PrintStream ps, |
||||||
|
Map<Long, FBXElement> uidToObjectMap) { |
||||||
|
switch (propertyType) { |
||||||
|
case 'S': |
||||||
|
// String
|
||||||
|
String str = (String) property; |
||||||
|
ps.print("\"" + convertFBXString(str) + "\""); |
||||||
|
break; |
||||||
|
case 'R': |
||||||
|
// RAW data.
|
||||||
|
byte[] bytes = (byte[]) property; |
||||||
|
ps.print("["); |
||||||
|
for (int j = 0; j < bytes.length; j++) { |
||||||
|
ps.print(String.format("%02X", bytes[j] & 0xff)); |
||||||
|
if (j != bytes.length - 1) { |
||||||
|
ps.print(" "); |
||||||
|
} |
||||||
|
} |
||||||
|
ps.print("]"); |
||||||
|
break; |
||||||
|
case 'D': |
||||||
|
case 'F': |
||||||
|
// Double, Float.
|
||||||
|
if (property instanceof Double) { |
||||||
|
ps.print(DECIMAL_FORMAT.format((Double)property)); |
||||||
|
} else if (property instanceof Float) { |
||||||
|
ps.print(DECIMAL_FORMAT.format((Float)property)); |
||||||
|
} else { |
||||||
|
ps.print(property); |
||||||
|
} |
||||||
|
break; |
||||||
|
case 'I': |
||||||
|
case 'Y': |
||||||
|
// Integer, Signed Short.
|
||||||
|
ps.print(property); |
||||||
|
break; |
||||||
|
case 'C': |
||||||
|
// Boolean
|
||||||
|
ps.print((Boolean)property ? "1" : "0"); |
||||||
|
break; |
||||||
|
case 'L': |
||||||
|
// Long
|
||||||
|
// If this is a connection, decode UID into object name.
|
||||||
|
if (id.equals("C")) { |
||||||
|
Long uid = (Long) property; |
||||||
|
FBXElement element = uidToObjectMap.get(uid); |
||||||
|
if (element != null) { |
||||||
|
String name = (String) element.properties.get(1); |
||||||
|
ps.print("\"" + convertFBXString(name) + "\""); |
||||||
|
} else { |
||||||
|
ps.print(property); |
||||||
|
} |
||||||
|
} else { |
||||||
|
ps.print(property); |
||||||
|
} |
||||||
|
break; |
||||||
|
case 'd': |
||||||
|
case 'i': |
||||||
|
case 'l': |
||||||
|
case 'f': |
||||||
|
// Arrays of things..
|
||||||
|
int length = Array.getLength(property); |
||||||
|
for (int j = 0; j < length; j++) { |
||||||
|
Object arrayEntry = Array.get(property, j); |
||||||
|
dumpFBXProperty(id, Character.toUpperCase(propertyType), arrayEntry, ps, uidToObjectMap); |
||||||
|
if (j != length - 1) { |
||||||
|
ps.print(","); |
||||||
|
} |
||||||
|
} |
||||||
|
break; |
||||||
|
default: |
||||||
|
throw new UnsupportedOperationException("" + propertyType); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected static void dumpFBXElement(FBXElement el, PrintStream ps, |
||||||
|
int indent, Map<Long, FBXElement> uidToObjectMap) { |
||||||
|
// 4 spaces per tab should be OK.
|
||||||
|
String indentStr = indent(indent * 4); |
||||||
|
String textId = el.id; |
||||||
|
|
||||||
|
// Properties are called 'P' and connections are called 'C'.
|
||||||
|
if (el.id.equals("P")) { |
||||||
|
textId = "Property"; |
||||||
|
} else if (el.id.equals("C")) { |
||||||
|
textId = "Connect"; |
||||||
|
} |
||||||
|
|
||||||
|
ps.print(indentStr + textId + ": "); |
||||||
|
for (int i = 0; i < el.properties.size(); i++) { |
||||||
|
Object property = el.properties.get(i); |
||||||
|
char propertyType = el.propertiesTypes[i]; |
||||||
|
dumpFBXProperty(el.id, propertyType, property, ps, uidToObjectMap); |
||||||
|
if (i != el.properties.size() - 1) { |
||||||
|
ps.print(", "); |
||||||
|
} |
||||||
|
} |
||||||
|
if (el.children.isEmpty()) { |
||||||
|
ps.println(); |
||||||
|
} else { |
||||||
|
ps.println(" {"); |
||||||
|
for (FBXElement childElement : el.children) { |
||||||
|
dumpFBXElement(childElement, ps, indent + 1, uidToObjectMap); |
||||||
|
} |
||||||
|
ps.println(indentStr + "}"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue