Removed org.lwjgl.util.model
This commit is contained in:
parent
1efa8258d1
commit
8dd4e47dae
41
build.xml
41
build.xml
|
@ -31,6 +31,17 @@
|
|||
<exclude name="org/lwjgl/examples/**" />
|
||||
</fileset>
|
||||
|
||||
<fileset id="lwjgl_util_applet.fileset" dir="${lwjgl.bin}">
|
||||
<exclude name="**.*"/>
|
||||
<include name="org/lwjgl/util/applet/**"/>
|
||||
</fileset>
|
||||
|
||||
<fileset id="lwjgl_util_applet_natives.fileset" dir="${lwjgl.lib}">
|
||||
<include name="win32/**"/>
|
||||
<include name="linux/**"/>
|
||||
<include name="macosx/**"/>
|
||||
</fileset>
|
||||
|
||||
<!-- Files to include in the lwjgl_test.jar file -->
|
||||
<fileset id="lwjgl_test.fileset" dir="${lwjgl.bin}">
|
||||
<exclude name="**.*" />
|
||||
|
@ -53,16 +64,10 @@
|
|||
<fileset id="lwjgl_util.fileset" dir="${lwjgl.bin}">
|
||||
<exclude name="**.*" />
|
||||
<exclude name="org/lwjgl/util/generator/**" />
|
||||
<exclude name="org/lwjgl/util/model/**" />
|
||||
<exclude name="org/lwjgl/util/applet/**" />
|
||||
<include name="org/lwjgl/util/**" />
|
||||
</fileset>
|
||||
|
||||
<!-- Files to include in the lwjgl_model.jar file -->
|
||||
<fileset id="lwjgl_model.fileset" dir="${lwjgl.bin}">
|
||||
<exclude name="**.*" />
|
||||
<include name="org/lwjgl/util/model/**" />
|
||||
</fileset>
|
||||
|
||||
<!-- Files to include in the lwjgl_fmod3.jar file -->
|
||||
<fileset id="lwjgl_fmod3.fileset" dir="${lwjgl.bin}">
|
||||
<exclude name="**.*" />
|
||||
|
@ -162,7 +167,6 @@
|
|||
<include name="**" />
|
||||
<exclude name="jar/lwjgl_fmod3.jar" />
|
||||
<exclude name="jar/lwjgl_devil.jar" />
|
||||
<exclude name="jar/lwjgl_model.jar" />
|
||||
<exclude name="native/win32/lwjgl-*.dll" />
|
||||
<exclude name="native/win32/DevIL.dll" />
|
||||
<exclude name="native/win32/ILU.dll" />
|
||||
|
@ -171,7 +175,6 @@
|
|||
<exclude name="native/linux/liblwjgl-*.so" />
|
||||
<exclude name="native/macosx/libIL*.dylib" />
|
||||
<exclude name="native/macosx/liblwjgl-*.jnilib" />
|
||||
<exclude name="res/model/**" />
|
||||
<exclude name="res/ILtest.*" />
|
||||
<exclude name="res/Missing_you.mod" />
|
||||
<exclude name="res/phero*.*" />
|
||||
|
@ -182,7 +185,6 @@
|
|||
<patternset id="lwjgl_optional">
|
||||
<include name="jar/lwjgl_fmod3.jar" />
|
||||
<include name="jar/lwjgl_devil.jar" />
|
||||
<include name="jar/lwjgl_model.jar" />
|
||||
<include name="native/win32/lwjgl-*.dll" />
|
||||
<include name="native/win32/DevIL.dll" />
|
||||
<include name="native/win32/ILU.dll" />
|
||||
|
@ -314,6 +316,12 @@
|
|||
<jar destfile="${lwjgl.temp}/jar/lwjgl.jar" taskname="lwjgl.jar">
|
||||
<fileset refid="lwjgl.fileset" />
|
||||
</jar>
|
||||
|
||||
<!-- Create lwjgl_util_applet.jar -->
|
||||
<jar destfile="${lwjgl.temp}/jar/lwjgl_util_applet.jar" taskname="lwjgl_util_applet.jar">
|
||||
<fileset refid="lwjgl_util_applet.fileset" />
|
||||
<fileset refid="lwjgl_util_applet_natives.fileset"/>
|
||||
</jar>
|
||||
|
||||
<!-- Create lwjgl_test.jar -->
|
||||
<jar destfile="${lwjgl.temp}/jar/lwjgl_test.jar" taskname="lwjgl_test.jar">
|
||||
|
@ -326,11 +334,6 @@
|
|||
<fileset refid="lwjgl_util.fileset" />
|
||||
</jar>
|
||||
|
||||
<!-- Create lwjgl_model.jar -->
|
||||
<jar destfile="${lwjgl.temp}/jar/lwjgl_model.jar" taskname="lwjgl_model.jar">
|
||||
<fileset refid="lwjgl_model.fileset" />
|
||||
</jar>
|
||||
|
||||
<!-- Create lwjgl_fmod.jar -->
|
||||
<jar destfile="${lwjgl.temp}/jar/lwjgl_fmod3.jar" taskname="lwjgl_fmod3.jar">
|
||||
<fileset refid="lwjgl_fmod3.fileset" />
|
||||
|
@ -348,18 +351,15 @@
|
|||
<fileset refid="lwjgl_applet.fileset" />
|
||||
</jar>
|
||||
<copy file="${lwjgl.lib}/lwjgl.jar" todir="applet"/>
|
||||
<copy file="${lwjgl.lib}/lwjgl_util_applet.jar" todir="applet"/>
|
||||
<copy file="${lwjgl.lib}/lwjgl_util.jar" todir="applet"/>
|
||||
<copy file="${lwjgl.lib}/lwjgl_fmod3.jar" todir="applet"/>
|
||||
<copy file="${lwjgl.lib}/lwjgl_devil.jar" todir="applet"/>
|
||||
<zip destfile="applet/res.jar">
|
||||
<zipfileset dir="${lwjgl.res}" includes="Footsteps.wav, ILtest.tga, Missing_you.mod"/>
|
||||
</zip>
|
||||
<zip destfile="applet/lwjgl.jar" update="true">
|
||||
<zipfileset dir="${lwjgl.lib}" prefix="native" includes="win32/**"/>
|
||||
<zipfileset dir="${lwjgl.lib}" prefix="native" includes="linux/**"/>
|
||||
<zipfileset dir="${lwjgl.lib}" prefix="native" includes="macosx/**"/>
|
||||
</zip>
|
||||
<signjar jar="applet/lwjgl.jar" alias="lwjgl" keystore="applet/lwjglkeystore" storepass="123456"/>
|
||||
<signjar jar="applet/lwjgl_util_applet.jar" alias="lwjgl" keystore="applet/lwjglkeystore" storepass="123456"/>
|
||||
<signjar jar="applet/lwjgl_fmod3.jar" alias="lwjgl" keystore="applet/lwjglkeystore" storepass="123456"/>
|
||||
<signjar jar="applet/lwjgl_devil.jar" alias="lwjgl" keystore="applet/lwjglkeystore" storepass="123456"/>
|
||||
</target>
|
||||
|
@ -438,6 +438,7 @@
|
|||
<target name="headers" description="invokes javah on java classes" depends="compile">
|
||||
<!-- platform specific classes -->
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/linux" force="yes">
|
||||
<class name="org.lwjgl.opengl.LinuxKeyboard" />
|
||||
<class name="org.lwjgl.opengl.LinuxDisplay" />
|
||||
<class name="org.lwjgl.opengl.LinuxPeerInfo" />
|
||||
<class name="org.lwjgl.opengl.LinuxPbufferPeerInfo" />
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
<?xml version="1.0" standalone="no"?>
|
||||
|
||||
<bonemodel xmlns="x-schema:BoneModelSchema.xml"
|
||||
modelname="plane" material="none" vertexcount="4"
|
||||
type="boned" bones="1">
|
||||
<mesh>
|
||||
<triangle a="0" b="1" c="2" />
|
||||
<triangle a="2" b="3" c="0" />
|
||||
</mesh>
|
||||
<skin>
|
||||
<texcoord u="0.0" v="1.0" />
|
||||
<texcoord u="1.0" v="1.0" />
|
||||
<texcoord u="1.0" v="0.0" />
|
||||
<texcoord u="0.0" v="0.0" />
|
||||
</skin>
|
||||
<colors>
|
||||
<color red="127" green="0" blue="0" />
|
||||
<color red="0" green="0" blue="127" />
|
||||
<color red="0" green="127" blue="0" />
|
||||
<color red="127" green="127" blue="127" />
|
||||
</colors>
|
||||
<animation>
|
||||
<sequence sequencename="">
|
||||
<frame>
|
||||
<bonematrix>
|
||||
<m00></m00>
|
||||
<m01></m01>
|
||||
<m02></m02>
|
||||
<m03></m03>
|
||||
<m10></m10>
|
||||
<m11></m11>
|
||||
<m12></m12>
|
||||
<m13></m13>
|
||||
<m20></m20>
|
||||
<m21></m21>
|
||||
<m22></m22>
|
||||
<m23></m23>
|
||||
<m30></m30>
|
||||
<m31></m31>
|
||||
<m32></m32>
|
||||
<m33></m33>
|
||||
</bonematrix>
|
||||
<time></time>
|
||||
<action></action>
|
||||
</frame>
|
||||
</sequence>
|
||||
</animation>
|
||||
<vertices>
|
||||
<vertex x="-1.0" y="1.0" z="0.0" >
|
||||
<weights>
|
||||
<bone></bone>
|
||||
<weight></weight>
|
||||
</weights>
|
||||
</vertex>
|
||||
<vertex x="1.0" y="1.0" z="0.0" >
|
||||
<weights>
|
||||
<bone></bone>
|
||||
<weight></weight>
|
||||
</weights>
|
||||
</vertex>
|
||||
<vertex x="1.0" y="-1.0" z="0.0" >
|
||||
<weights>
|
||||
<bone></bone>
|
||||
<weight></weight>
|
||||
</weights>
|
||||
</vertex>
|
||||
<vertex x="-1.0" y="-1.0" z="0.0" >
|
||||
<weights>
|
||||
<bone></bone>
|
||||
<weight></weight>
|
||||
</weights>
|
||||
</vertex>
|
||||
</vertices>
|
||||
</bonemodel>
|
|
@ -1,40 +0,0 @@
|
|||
<?xml version="1.0" standalone="no"?>
|
||||
|
||||
<meshmodel xmlns="x-schema:MeshModelSchema.xml"
|
||||
modelname="example" material="test" vertexcount="4"
|
||||
type="meshed">
|
||||
<mesh>
|
||||
<triangle a="0" b="1" c="2" />
|
||||
<triangle a="2" b="3" c="0" />
|
||||
</mesh>
|
||||
<skin>
|
||||
<texcoord u="0.0" v="1.0" />
|
||||
<texcoord u="1.0" v="1.0" />
|
||||
<texcoord u="1.0" v="0.0" />
|
||||
<texcoord u="0.0" v="0.0" />
|
||||
</skin>
|
||||
<colors>
|
||||
<color red="127" green="0" blue="0" />
|
||||
<color red="0" green="0" blue="127" />
|
||||
<color red="0" green="127" blue="0" />
|
||||
<color red="127" green="127" blue="127" />
|
||||
</colors>
|
||||
<animation>
|
||||
<sequence sequencename="plane">
|
||||
<frame time="1.0">
|
||||
<vertex x="-1.0" y="1.0" z="0.0" />
|
||||
<vertex x="1.0" y="1.0" z="0.0" />
|
||||
<vertex x="1.0" y="-1.0" z="0.0" />
|
||||
<vertex x="-1.0" y="-1.0" z="0.0" />
|
||||
<action></action>
|
||||
</frame>
|
||||
<frame time="5.0">
|
||||
<vertex x="1.0" y="1.0" z="0.0" />
|
||||
<vertex x="-1.0" y="1.0" z="0.0" />
|
||||
<vertex x="-1.0" y="-1.0" z="0.0" />
|
||||
<vertex x="1.0" y="-1.0" z="0.0" />
|
||||
<action></action>
|
||||
</frame>
|
||||
</sequence>
|
||||
</animation>
|
||||
</meshmodel>
|
|
@ -0,0 +1,312 @@
|
|||
/*
|
||||
* Copyright (c) 2006 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.applet;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
* @author Brian Matzon <brian@matzon.dk>
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class LWJGLInstaller {
|
||||
|
||||
/**
|
||||
* Files to install for each supported platform
|
||||
* @see org.lwjgl.LWJGLUtil#getPlatform()
|
||||
*/
|
||||
public static final String[][] PLATFORM_FILES = {
|
||||
{ "lwjgl", "lwjgl-fmod3", "lwjgl-devil", "openal", "fmod", "IL", "ILU", "ILUT", "jinput-osx"},
|
||||
{ "lwjgl", "lwjgl-fmod3", "lwjgl-devil", "openal", "fmod", "IL", "ILU", "ILUT", "jinput-linux"},
|
||||
{ "lwjgl", "lwjgl-fmod3", "lwjgl-devil", "OpenAL32", "fmod", "DevIL", "ILU", "ILUT", "jinput-dx8", "jinput-raw"}
|
||||
};
|
||||
|
||||
/** Whether the installer has been called */
|
||||
public static boolean installed;
|
||||
|
||||
/** Whether to hook uninstall rutine. Must be called prior to installation */
|
||||
public static boolean disableUninstall = false;
|
||||
|
||||
/** Buffer used when copying files */
|
||||
private static final byte[] COPY_BUFFER = new byte[4096];
|
||||
|
||||
private LWJGLInstaller() {
|
||||
/* Unused */
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a temporary installation of LWJGL.
|
||||
* This will extract the relevant native files (for the platform) into
|
||||
* the users temp directory, and instruct the LWJGL subsystem to load its
|
||||
* native files from there.
|
||||
* The files required by the installer, are gotten from the classloader via its
|
||||
* getResource command, and are assumed to in the path: /native/<win32|linux|macosx>/
|
||||
* Any call to this method will also add a shutdown hook to the uninstall of the libraries
|
||||
* Note: Due to the nature of native libraries, we cannot actually uninstall the currently
|
||||
* loaded files, but rather the "last" installed. This means that the most recent install of LWJGL
|
||||
* will always be present in the users temp dir.
|
||||
*
|
||||
* @see java.lang.ClassLoader#getResource(String)
|
||||
*/
|
||||
public static void tempInstall() throws Exception {
|
||||
// only need to install once
|
||||
if (installed) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// libraries to validate and install
|
||||
String[] libraries = PLATFORM_FILES[LWJGLUtil.getPlatform() - 1];
|
||||
|
||||
// Validate the certificates of the native files
|
||||
validateCertificates();
|
||||
|
||||
// install shutdown installer hook
|
||||
if(!disableUninstall) {
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
public void run() {
|
||||
uninstall();
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// create a temporary dir for the native files
|
||||
String user_temp_dir = getPriviledgedString("java.io.tmpdir");
|
||||
final String path = createTemporaryDir(user_temp_dir);
|
||||
|
||||
// extract natives
|
||||
for (int i = 0; i < libraries.length; i++) {
|
||||
String library = System.mapLibraryName(libraries[i]);
|
||||
extract(library, path);
|
||||
}
|
||||
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
System.setProperty("org.lwjgl.librarypath", path);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
LWJGLUtil.log("Failed extraction e = " + e.getMessage());
|
||||
uninstall();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the certificates of the native libraries.
|
||||
* When installing native libraries, it is imperative that we also check the certficates.
|
||||
* The reson for this, is that a user may inject a malicious jar to the classpath
|
||||
* before the "real" LWJGL jar, containing native libraries with unwanted code.
|
||||
* By forcing all the native libraries to have the same certificate as the signed
|
||||
* installer, we can also be sure that the native libraries indeed are correct.
|
||||
* @throws Exception If we encounter a certificate mismatch
|
||||
*/
|
||||
private static void validateCertificates() throws Exception {
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a file in the classpath to a specified dir
|
||||
*
|
||||
* @param file File to extract
|
||||
* @param path Path to extract to
|
||||
*/
|
||||
private static void extract(final String file, final String path) {
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
// check for existing file, and get out
|
||||
File out = new File(path + File.separator + file);
|
||||
if (out.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// create the new file and copy it to its destination
|
||||
try {
|
||||
out.createNewFile();
|
||||
String in = "/native/" + LWJGLUtil.getPlatformName() + "/" + file;
|
||||
OutputStream os = new BufferedOutputStream(new FileOutputStream(out));
|
||||
InputStream is = new BufferedInputStream(getClass().getResourceAsStream(in));
|
||||
|
||||
// Sanity check
|
||||
// ===========================================
|
||||
if (os == null) {
|
||||
LWJGLUtil.log("Unable to write to outputstream at " + out.getAbsolutePath());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is == null) {
|
||||
LWJGLUtil.log("Unable to read classpath inputstream from " + in);
|
||||
return null;
|
||||
}
|
||||
// -------------------------------------------
|
||||
|
||||
// copy the actual file
|
||||
copyFile(is, os);
|
||||
} catch (IOException ioe) {
|
||||
LWJGLUtil.log("Exception while extracting " + file + ": " + ioe.getMessage());
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies an inputstream to an outputstream
|
||||
* @param is InputStream to read from
|
||||
* @param os OutputStream to write to
|
||||
* @throws IOException if the copy process fail in any way
|
||||
*/
|
||||
static void copyFile(InputStream is, OutputStream os) throws IOException {
|
||||
int len;
|
||||
while ((len = is.read(COPY_BUFFER)) > 0) {
|
||||
os.write(COPY_BUFFER, 0, len);
|
||||
}
|
||||
is.close();
|
||||
os.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the temporary dir to store lwjgl files in.
|
||||
* The temporary dir will be created in the users temp dir and
|
||||
* called 'lwjgl-' and appended System.currentTimeMillis(). A watermark file
|
||||
* called '.lwjglinstaller' will also be created in the directory.
|
||||
* @return Name of temp directory or null if directory creation failed
|
||||
*/
|
||||
static String createTemporaryDir(final String user_temp_dir) throws Exception {
|
||||
return (String) AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws Exception {
|
||||
// create the temp directory
|
||||
File tempDir = new File(user_temp_dir + File.separator + "lwjgl-" + System.currentTimeMillis());
|
||||
if(!tempDir.mkdir()) {
|
||||
throw new IOException("Failed to create directory: " + tempDir);
|
||||
}
|
||||
|
||||
// add the watermark file
|
||||
// TODO: Write some info to the file ?
|
||||
File watermark = new File(tempDir.getAbsolutePath() + File.separator + ".lwjglinstaller");
|
||||
watermark.createNewFile();
|
||||
return tempDir.getAbsolutePath();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a property as a privileged action.
|
||||
*/
|
||||
private static String getPriviledgedString(final String property) {
|
||||
return (String) AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return System.getProperty(property);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstalls any PREVIOUS installations
|
||||
* We cannot uninstall the current installation, since the files are locked
|
||||
* by the VM.
|
||||
*/
|
||||
private static void uninstall() {
|
||||
LWJGLUtil.log("running LWJGL uninstaller");
|
||||
|
||||
// locate all installer dirs and uninstall them
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
String temp = System.getProperty("java.io.tmpdir");
|
||||
File tempDir = new File(temp);
|
||||
File[] files = tempDir.listFiles(new FileFilter() {
|
||||
|
||||
/*
|
||||
* @see java.io.FileFilter#accept(java.io.File)
|
||||
*/
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.getAbsolutePath().indexOf("lwjgl") != -1 && isInstallDirectory(pathname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the specified directory is an install directory.
|
||||
* This is done by checking for the watermark file
|
||||
* @param directory Directory to check
|
||||
* @return true if the directory is an install directory
|
||||
*/
|
||||
private boolean isInstallDirectory(File directory) {
|
||||
File installFile = new File(directory.getAbsolutePath() + File.separator + ".lwjglinstaller");
|
||||
return installFile.exists();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// uninstall each of the dirs
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
uninstall(files[i]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall LWJGL from a directory. This deletes all the files in the directory
|
||||
* and deletes the directory too.
|
||||
* @param file directory to uninstall LWJGL from
|
||||
*/
|
||||
private static void uninstall(File file) {
|
||||
File[] files = file.listFiles();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
files[i].delete();
|
||||
}
|
||||
file.delete();
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model;
|
||||
|
||||
import org.lwjgl.util.vector.Matrix4f;
|
||||
|
||||
/**
|
||||
* A BoneFrame describes a set of new positions for Bones in an animation.
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class BoneFrame extends Frame {
|
||||
|
||||
public static final long serialVersionUID = 1L;
|
||||
|
||||
/** The new transformations for each Bone in the Skeleton */
|
||||
private final Matrix4f[] bone;
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
* @param time
|
||||
* @param action
|
||||
* @param bone[]
|
||||
*/
|
||||
public BoneFrame(float time, String action, Matrix4f[] bone) {
|
||||
super(time, action);
|
||||
this.bone = bone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Bones
|
||||
*/
|
||||
public Matrix4f[] getBone() {
|
||||
return bone;
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.lwjgl.util.Color;
|
||||
import org.lwjgl.util.vector.Vector2f;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* A simple animated, skinned, boned 3D model, consisting of a single mesh
|
||||
* with a single material. The model's internal format is optimised for RAM storage;
|
||||
* no metadata is held in memory - in other words this is not a good class to use
|
||||
* for, say, a 3d modelling application.
|
||||
*
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class BonedModel extends Model {
|
||||
|
||||
public static final long serialVersionUID = 1L;
|
||||
|
||||
/** Vertices */
|
||||
private final BonedVertex[] vertex;
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
* @param material
|
||||
* @param triangle
|
||||
* @param skin[]
|
||||
* @param color[]
|
||||
* @param animation
|
||||
* @param vertex
|
||||
*/
|
||||
public BonedModel(String name, String material, Triangle[] triangle, Vector2f[] skin, Color[] color, Map animation, BonedVertex[] vertex) {
|
||||
super(name, material, triangle, skin, color, animation);
|
||||
this.vertex = vertex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the vertices
|
||||
*/
|
||||
public BonedVertex[] getVertex() {
|
||||
return vertex;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model;
|
||||
|
||||
import org.lwjgl.util.vector.ReadableVector3f;
|
||||
|
||||
/**
|
||||
*
|
||||
* A BonedVerex is a Vertex influenced by bone Weights
|
||||
*
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class BonedVertex extends Vertex {
|
||||
|
||||
public static final long serialVersionUID = 1L;
|
||||
|
||||
/** Bone weights */
|
||||
private final Weight[] weight;
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
* @param coords
|
||||
* @param normal
|
||||
* @param skin
|
||||
*/
|
||||
public BonedVertex(ReadableVector3f coords, ReadableVector3f normal, Weight[] skin) {
|
||||
super(coords, normal);
|
||||
this.weight = skin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the skin.
|
||||
*/
|
||||
public Weight[] getWeight() {
|
||||
return weight;
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The base class for animation frames.
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public abstract class Frame implements Serializable, Comparable {
|
||||
|
||||
public static final long serialVersionUID = 1L;
|
||||
|
||||
/** Frame time */
|
||||
private final float time;
|
||||
|
||||
/** User-defined action to occur after this frame has been used. May be null */
|
||||
private final String action;
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
* @param time
|
||||
* @param action
|
||||
*/
|
||||
public Frame(float time, String action) {
|
||||
this.time = time;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the frame time
|
||||
*/
|
||||
public final float getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
||||
*/
|
||||
public int compareTo(Object o) {
|
||||
if (o == null) {
|
||||
return 0;
|
||||
}
|
||||
if (! (o instanceof Frame)) {
|
||||
return 0;
|
||||
}
|
||||
Frame f = (Frame) o;
|
||||
if (f.time == time) {
|
||||
return 0;
|
||||
} else if (f.time > time) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user-defined animation action. This can be processed by whatever
|
||||
* is animating the model to perform some special action after the frame is
|
||||
* used. For example, you could use "stop" to stop the animation, or "rewind"
|
||||
* to repeat the animation ad infinitum.
|
||||
* @return String, or null, for no action
|
||||
*/
|
||||
public final String getAction() {
|
||||
return action;
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model;
|
||||
|
||||
|
||||
/**
|
||||
* A MeshFrame describes a set of new positions for Vertices in an animation.
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class MeshFrame extends Frame {
|
||||
|
||||
public static final long serialVersionUID = 1L;
|
||||
|
||||
/** The vertices */
|
||||
private final Vertex[] vertex;
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
* @param time
|
||||
* @param action
|
||||
* @param bone[]
|
||||
*/
|
||||
public MeshFrame(float time, String action, Vertex[] vertex) {
|
||||
super(time, action);
|
||||
this.vertex = vertex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Vertices
|
||||
*/
|
||||
public Vertex[] getVertex() {
|
||||
return vertex;
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.lwjgl.util.Color;
|
||||
import org.lwjgl.util.vector.Vector2f;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* A simple animated 3d mesh, consisting of multiple vertex positions.
|
||||
* with a single material. The model's internal format is optimised for RAM storage;
|
||||
* no metadata is held in memory - in other words this is not a good class to use
|
||||
* for, say, a 3d modelling application.
|
||||
*
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class MeshedModel extends Model {
|
||||
|
||||
public static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
* @param material
|
||||
* @param triangle
|
||||
* @param skin[]
|
||||
* @param color[]
|
||||
* @param animation
|
||||
*/
|
||||
public MeshedModel(String name, String material, Triangle[] triangle, Vector2f[] skin, Color[] color, Map animation) {
|
||||
super(name, material, triangle, skin, color, animation);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,140 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.lwjgl.util.Color;
|
||||
import org.lwjgl.util.vector.Vector2f;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Base class for the two kinds of model supported. A Model has a single "material"
|
||||
* and a single triangular mesh with a single skin, and any number of animations.
|
||||
*
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public abstract class Model implements Serializable {
|
||||
|
||||
public static final long serialVersionUID = 1L;
|
||||
|
||||
/** Model name */
|
||||
private final String name;
|
||||
|
||||
/** Material */
|
||||
private final String material;
|
||||
|
||||
/** Triangles */
|
||||
private final Triangle[] triangle;
|
||||
|
||||
/** Skin */
|
||||
private final Vector2f[] skin;
|
||||
|
||||
/** Colour */
|
||||
private final Color[] color;
|
||||
|
||||
/** The animations: a Map of string names to Frame[] arrays */
|
||||
private final Map animation;
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
* @param name
|
||||
* @param material
|
||||
* @param triangle
|
||||
* @param skin[]
|
||||
* @param color[]
|
||||
* @param animation
|
||||
*/
|
||||
public Model(String name, String material, Triangle[] triangle, Vector2f[] skin, Color[] color, Map animation) {
|
||||
this.name = name;
|
||||
this.material = material;
|
||||
this.triangle = triangle;
|
||||
this.skin = skin;
|
||||
this.color = color;
|
||||
this.animation = animation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a named animation from the Model
|
||||
* @param name The name of the animation
|
||||
* @return the Frames of an animation (or null, if no such animation exists)
|
||||
*/
|
||||
public final Frame[] getAnimation(String name) {
|
||||
return (Frame[]) animation.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the material.
|
||||
*/
|
||||
public final String getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the triangles.
|
||||
*/
|
||||
public final Triangle[] getTriangle() {
|
||||
return triangle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the skin.
|
||||
*/
|
||||
public final Vector2f[] getSkin() {
|
||||
return skin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the color
|
||||
*/
|
||||
public final Color[] getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return "Model["+name+"]";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public final String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class Triangle implements Serializable {
|
||||
|
||||
public static final long serialVersionUID = 1L;
|
||||
|
||||
/** Vertex indices: these look up into the parent Mesh's vertex array */
|
||||
private final int a, b, c;
|
||||
|
||||
/** Adjacency, for stripification */
|
||||
private final int adjacency;
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
* @param a
|
||||
* @param b
|
||||
* @param c
|
||||
* @param adjacency
|
||||
*/
|
||||
public Triangle(int a, int b, int c, int adjacency) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
this.adjacency = adjacency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the 'a' vertex index
|
||||
*/
|
||||
public int getA() {
|
||||
return a;
|
||||
}
|
||||
/**
|
||||
* @return Returns the 'b' vertex index
|
||||
*/
|
||||
public int getB() {
|
||||
return b;
|
||||
}
|
||||
/**
|
||||
* @return Returns the 'c' vertex index
|
||||
*/
|
||||
public int getC() {
|
||||
return c;
|
||||
}
|
||||
/**
|
||||
* @return Returns the adjacency.
|
||||
*/
|
||||
public int getAdjacency() {
|
||||
return adjacency;
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.lwjgl.util.vector.ReadableVector3f;
|
||||
|
||||
/**
|
||||
*
|
||||
* A single vertex in a mesh.
|
||||
*
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class Vertex implements Serializable {
|
||||
|
||||
public static final long serialVersionUID = 1L;
|
||||
|
||||
/** Coordinates */
|
||||
private final ReadableVector3f coords;
|
||||
|
||||
/** Normal */
|
||||
private final ReadableVector3f normal;
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
* @param coords
|
||||
* @param normal
|
||||
*/
|
||||
public Vertex(ReadableVector3f coords, ReadableVector3f normal) {
|
||||
this.coords = coords;
|
||||
this.normal = normal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the coords.
|
||||
*/
|
||||
public ReadableVector3f getCoords() {
|
||||
return coords;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the normal.
|
||||
*/
|
||||
public ReadableVector3f getNormal() {
|
||||
return normal;
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Describes how a bone influences a vertex.
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class Weight implements Serializable {
|
||||
|
||||
public static final long serialVersionUID = 1L;
|
||||
|
||||
/** Bone index */
|
||||
private final int bone;
|
||||
|
||||
/** Weight */
|
||||
private final float weight;
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
*/
|
||||
public Weight(int bone, float weight) {
|
||||
this.bone = bone;
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the bone index.
|
||||
*/
|
||||
public int getBone() {
|
||||
return bone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the weight.
|
||||
*/
|
||||
public float getWeight() {
|
||||
return weight;
|
||||
}
|
||||
}
|
|
@ -1,501 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model.loaders;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.lwjgl.util.Color;
|
||||
import org.lwjgl.util.model.BoneFrame;
|
||||
import org.lwjgl.util.model.BonedModel;
|
||||
import org.lwjgl.util.model.BonedVertex;
|
||||
import org.lwjgl.util.model.MeshFrame;
|
||||
import org.lwjgl.util.model.MeshedModel;
|
||||
import org.lwjgl.util.model.Model;
|
||||
import org.lwjgl.util.model.Triangle;
|
||||
import org.lwjgl.util.model.Vertex;
|
||||
import org.lwjgl.util.model.Weight;
|
||||
import org.lwjgl.util.vector.Matrix4f;
|
||||
import org.lwjgl.util.vector.Vector2f;
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
*
|
||||
* Loads a Model from an XML document. Construct with an XML Document as the argument,
|
||||
* and then retrieve the Model by calling load().
|
||||
*
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class XMLLoader {
|
||||
|
||||
/** The source document */
|
||||
private final Document src;
|
||||
|
||||
/** Expected number of vertices */
|
||||
private int numVertices;
|
||||
|
||||
/** Expected number of bones */
|
||||
private int numBones;
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
*/
|
||||
public XMLLoader(Document src) {
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the model from the XML document and return it.
|
||||
* @return Model
|
||||
* @throws Exception
|
||||
*/
|
||||
public Model load() throws Exception {
|
||||
String name = XMLUtil.getString(src.getDocumentElement(), "modelname");
|
||||
String material = XMLUtil.getString(src.getDocumentElement(), "material");
|
||||
numVertices = XMLUtil.getInt(src.getDocumentElement(), "vertexcount");
|
||||
if (XMLUtil.getString(src.getDocumentElement(), "type").equals("boned")) {
|
||||
// It's a boned model
|
||||
numBones = XMLUtil.getInt(src.getDocumentElement(), "bones", 0);
|
||||
return new BonedModel(
|
||||
name,
|
||||
material,
|
||||
loadTriangles(),
|
||||
loadSkin(),
|
||||
loadColor(),
|
||||
loadBoneAnimations(),
|
||||
loadBonedVertices()
|
||||
);
|
||||
} else if (XMLUtil.getString(src.getDocumentElement(), "type").equals("meshed")) {
|
||||
// It's a mesh keyframe model
|
||||
return new MeshedModel(
|
||||
name,
|
||||
material,
|
||||
loadTriangles(),
|
||||
loadSkin(),
|
||||
loadColor(),
|
||||
loadMeshAnimations()
|
||||
);
|
||||
} else {
|
||||
throw new Exception("Unsupported model type.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all the BonedVertices
|
||||
* @return Vertex[]
|
||||
* @throws Exception
|
||||
*/
|
||||
private BonedVertex[] loadBonedVertices() throws Exception {
|
||||
Element verticesElement = XMLUtil.getChild(src.getDocumentElement(), "vertices");
|
||||
if (verticesElement == null) {
|
||||
return null;
|
||||
}
|
||||
List vertexElements = XMLUtil.getChildren(verticesElement, "vertex");
|
||||
if (vertexElements.size() != numVertices) {
|
||||
throw new Exception("Vertex count incorrect, got "+vertexElements.size()+", expected "+numVertices);
|
||||
}
|
||||
BonedVertex[] vertices = new BonedVertex[vertexElements.size()];
|
||||
int vertexCount = 0;
|
||||
for (Iterator i = vertexElements.iterator(); i.hasNext(); ) {
|
||||
Element vertexElement = (Element) i.next();
|
||||
vertices[vertexCount++] = loadBonedVertex(vertexElement);
|
||||
}
|
||||
return vertices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the skin
|
||||
* @return Vector2f[]
|
||||
* @throws Exception
|
||||
*/
|
||||
private Vector2f[] loadSkin() throws Exception {
|
||||
Element skinElement = XMLUtil.getChild(src.getDocumentElement(), "skin");
|
||||
if (skinElement == null) {
|
||||
return null;
|
||||
}
|
||||
List skinElements = XMLUtil.getChildren(skinElement, "texcoord");
|
||||
if (skinElements.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
if (skinElements.size() != numVertices) {
|
||||
throw new Exception("Skin count incorrect, got "+skinElements.size()+", expected "+numVertices);
|
||||
}
|
||||
Vector2f[] skins = new Vector2f[skinElements.size()];
|
||||
int skinCount = 0;
|
||||
for (Iterator i = skinElements.iterator(); i.hasNext(); ) {
|
||||
Element texCoordElement = (Element) i.next();
|
||||
skins[skinCount++] = loadTexCoord(texCoordElement);
|
||||
}
|
||||
return skins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the colour
|
||||
* @return Color[]
|
||||
* @throws Exception
|
||||
*/
|
||||
private Color[] loadColor() throws Exception {
|
||||
Element colorsElement = XMLUtil.getChild(src.getDocumentElement(), "colors");
|
||||
if (colorsElement == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List colorElements = XMLUtil.getChildren(colorsElement, "color");
|
||||
if (colorElements.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
if (colorElements.size() != numVertices) {
|
||||
throw new Exception("Color count incorrect, got "+colorElements.size()+", expected "+numVertices);
|
||||
}
|
||||
Color[] colors = new Color[colorElements.size()];
|
||||
int colorCount = 0;
|
||||
for (Iterator i = colorElements.iterator(); i.hasNext(); ) {
|
||||
Element colorElement = (Element) i.next();
|
||||
colors[colorCount++] = loadColor(colorElement);
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all the Triangles
|
||||
* @return Triangle[]
|
||||
* @throws Exception
|
||||
*/
|
||||
private Triangle[] loadTriangles() throws Exception {
|
||||
Element meshElement = XMLUtil.getChild(src.getDocumentElement(), "mesh");
|
||||
if (meshElement == null) {
|
||||
return null;
|
||||
}
|
||||
List triangleElements = XMLUtil.getChildren(meshElement, "triangle");
|
||||
Triangle[] triangles = new Triangle[triangleElements.size()];
|
||||
int triangleCount = 0;
|
||||
for (Iterator i = triangleElements.iterator(); i.hasNext(); ) {
|
||||
Element triangleElement = (Element) i.next();
|
||||
triangles[triangleCount++] = loadTriangle(triangleElement);
|
||||
}
|
||||
return triangles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all the bone animations
|
||||
* @return Map of animation names to BoneFrame[] animations
|
||||
* @throws Exception
|
||||
*/
|
||||
private Map loadBoneAnimations() throws Exception {
|
||||
Element animationElement = XMLUtil.getChild(src.getDocumentElement(), "animation");
|
||||
if (animationElement == null) {
|
||||
return null;
|
||||
}
|
||||
List sequenceElements = XMLUtil.getChildren(src.getDocumentElement(), "sequence");
|
||||
Map animations = new HashMap(sequenceElements.size());
|
||||
for (Iterator i = sequenceElements.iterator(); i.hasNext(); ) {
|
||||
Element sequenceElement = (Element) i.next();
|
||||
animations.put(XMLUtil.getString(sequenceElement, "sequencename"), loadBonedAnimation(sequenceElement));
|
||||
}
|
||||
return animations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all the mesh keyframe animations
|
||||
* @return Map of animation names to MeshFrame[] animations
|
||||
* @throws Exception
|
||||
*/
|
||||
private Map loadMeshAnimations() throws Exception {
|
||||
Element animationElement = XMLUtil.getChild(src.getDocumentElement(), "animation");
|
||||
if (animationElement == null) {
|
||||
return null;
|
||||
}
|
||||
List sequenceElements = XMLUtil.getChildren(animationElement, "sequence");
|
||||
Map animations = new HashMap(sequenceElements.size());
|
||||
for (Iterator i = sequenceElements.iterator(); i.hasNext(); ) {
|
||||
Element sequenceElement = (Element) i.next();
|
||||
animations.put(XMLUtil.getString(sequenceElement, "sequencename"), loadMeshAnimation(sequenceElement));
|
||||
}
|
||||
return animations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a Vertex from XML
|
||||
* @param vertexElement
|
||||
* @return a Vertex
|
||||
* @throws Exception
|
||||
*/
|
||||
private BonedVertex loadBonedVertex(Element vertexElement) throws Exception {
|
||||
List weightElements = XMLUtil.getChildren(vertexElement, "weight");
|
||||
Weight[] weights;
|
||||
if (weightElements.size() == 0) {
|
||||
weights = null;
|
||||
} else {
|
||||
weights = new Weight[weightElements.size()];
|
||||
int weightCount = 0;
|
||||
for (Iterator i = weightElements.iterator(); i.hasNext(); ) {
|
||||
Element weightElement = (Element) i.next();
|
||||
weights[weightCount++] = loadWeight(weightElement);
|
||||
}
|
||||
}
|
||||
|
||||
return new BonedVertex(
|
||||
new Vector3f(
|
||||
XMLUtil.getFloat(vertexElement, "x"),
|
||||
XMLUtil.getFloat(vertexElement, "y"),
|
||||
XMLUtil.getFloat(vertexElement, "z")
|
||||
),
|
||||
XMLUtil.hasAttribute(vertexElement, "nx") ?
|
||||
new Vector3f(
|
||||
XMLUtil.getFloat(vertexElement, "nx"),
|
||||
XMLUtil.getFloat(vertexElement, "ny"),
|
||||
XMLUtil.getFloat(vertexElement, "nz")
|
||||
)
|
||||
: null,
|
||||
weights
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a Vertex from XML
|
||||
* @param vertexElement
|
||||
* @return a Vertex
|
||||
* @throws Exception
|
||||
*/
|
||||
private Vertex loadMeshVertex(Element vertexElement) throws Exception {
|
||||
return new Vertex(
|
||||
new Vector3f(
|
||||
XMLUtil.getFloat(vertexElement, "x"),
|
||||
XMLUtil.getFloat(vertexElement, "y"),
|
||||
XMLUtil.getFloat(vertexElement, "z")
|
||||
),
|
||||
XMLUtil.hasAttribute(vertexElement, "nx") ?
|
||||
new Vector3f(
|
||||
XMLUtil.getFloat(vertexElement, "nx"),
|
||||
XMLUtil.getFloat(vertexElement, "ny"),
|
||||
XMLUtil.getFloat(vertexElement, "nz")
|
||||
)
|
||||
: null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a Weight from XML
|
||||
* @param element
|
||||
* @return a Skin
|
||||
* @throws Exception
|
||||
*/
|
||||
private Weight loadWeight(Element element) throws Exception {
|
||||
int bone = XMLUtil.getInt(element, "bone");
|
||||
if (bone < 0 || bone >= numBones) {
|
||||
throw new Exception("Bone index out of range");
|
||||
}
|
||||
return new Weight(
|
||||
bone,
|
||||
XMLUtil.getFloat(element, "weight")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a Triangle from XML
|
||||
* @param element
|
||||
* @param numVertices
|
||||
* @return a Triangle
|
||||
* @throws Exception
|
||||
*/
|
||||
private Triangle loadTriangle(Element element) throws Exception {
|
||||
// Perform sanity checks
|
||||
int a = XMLUtil.getInt(element, "a");
|
||||
if (a < 0 || a >= numVertices) {
|
||||
throw new Exception("'a' is out of range");
|
||||
}
|
||||
int b = XMLUtil.getInt(element, "b");
|
||||
if (b < 0 || b >= numVertices) {
|
||||
throw new Exception("'b' is out of range");
|
||||
}
|
||||
int c = XMLUtil.getInt(element, "c");
|
||||
if (c < 0 || c >= numVertices) {
|
||||
throw new Exception("'c' is out of range");
|
||||
}
|
||||
if (a == b || a == c || b == c) {
|
||||
throw new Exception("Degenerate triangle");
|
||||
}
|
||||
return new Triangle(
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
XMLUtil.getInt(element, "adjacency", 0)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a texture coordinate from XML
|
||||
* @param element
|
||||
* @return a Vector2f
|
||||
* @throws Exception
|
||||
*/
|
||||
private Vector2f loadTexCoord(Element element) throws Exception {
|
||||
return new Vector2f(
|
||||
XMLUtil.getFloat(element, "u"),
|
||||
XMLUtil.getFloat(element, "v")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a colour from XML
|
||||
* @param element
|
||||
* @return a Color
|
||||
* @throws Exception
|
||||
*/
|
||||
private Color loadColor(Element element) throws Exception {
|
||||
return new Color(
|
||||
XMLUtil.getInt(element, "red"),
|
||||
XMLUtil.getInt(element, "green"),
|
||||
XMLUtil.getInt(element, "blue"),
|
||||
XMLUtil.getInt(element, "alpha", 255)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a boned Animation from XML
|
||||
* @param element
|
||||
* @return BoneFrame[]
|
||||
* @throws Exception
|
||||
*/
|
||||
private BoneFrame[] loadBonedAnimation(Element element) throws Exception {
|
||||
List frameElements = XMLUtil.getChildren(element, "frame");
|
||||
BoneFrame[] frames = new BoneFrame[frameElements.size()];
|
||||
int frameCount = 0;
|
||||
for (Iterator i = frameElements.iterator(); i.hasNext(); ) {
|
||||
Element frameElement = (Element) i.next();
|
||||
frames[frameCount++] = loadBoneFrame(frameElement);
|
||||
}
|
||||
Arrays.sort(frames);
|
||||
return frames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a mesh Animation from XML
|
||||
* @param element
|
||||
* @return MeshFrame[]
|
||||
* @throws Exception
|
||||
*/
|
||||
private MeshFrame[] loadMeshAnimation(Element element) throws Exception {
|
||||
List frameElements = XMLUtil.getChildren(element, "frame");
|
||||
MeshFrame[] frames = new MeshFrame[frameElements.size()];
|
||||
int frameCount = 0;
|
||||
for (Iterator i = frameElements.iterator(); i.hasNext(); ) {
|
||||
Element frameElement = (Element) i.next();
|
||||
frames[frameCount++] = loadMeshFrame(frameElement);
|
||||
}
|
||||
Arrays.sort(frames);
|
||||
return frames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a Frame from XML
|
||||
* @param element
|
||||
* @return BoneFrame
|
||||
* @throws Exception
|
||||
*/
|
||||
private BoneFrame loadBoneFrame(Element element) throws Exception {
|
||||
List boneElements = XMLUtil.getChildren(element, "bone");
|
||||
if (boneElements.size() != numBones) {
|
||||
throw new Exception("Expected "+numBones+" bones in frame, only got "+boneElements.size());
|
||||
}
|
||||
Matrix4f[] bones = new Matrix4f[boneElements.size()];
|
||||
int boneCount = 0;
|
||||
for (Iterator i = boneElements.iterator(); i.hasNext(); ) {
|
||||
Element boneElement = (Element) i.next();
|
||||
bones[boneCount++] = loadBone(boneElement);
|
||||
}
|
||||
return new BoneFrame(
|
||||
XMLUtil.getFloat(element, "time"),
|
||||
XMLUtil.getString(element, "action", null),
|
||||
bones
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a Frame from XML
|
||||
* @param element
|
||||
* @return MeshFrame
|
||||
* @throws Exception
|
||||
*/
|
||||
private MeshFrame loadMeshFrame(Element element) throws Exception {
|
||||
List vertexElements = XMLUtil.getChildren(element, "vertex");
|
||||
Vertex[] vertices = new Vertex[vertexElements.size()];
|
||||
if (vertices.length != numVertices) {
|
||||
throw new Exception("Vertex count incorrect");
|
||||
}
|
||||
int vertexCount = 0;
|
||||
for (Iterator i = vertexElements.iterator(); i.hasNext(); ) {
|
||||
Element vertexElement = (Element) i.next();
|
||||
vertices[vertexCount++] = loadMeshVertex(vertexElement);
|
||||
}
|
||||
return new MeshFrame(
|
||||
XMLUtil.getFloat(element, "time"),
|
||||
XMLUtil.getString(element, "action", null),
|
||||
vertices
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a Bone from XML
|
||||
* @param element
|
||||
* @return a Matrix4f
|
||||
* @throws Exception
|
||||
*/
|
||||
private Matrix4f loadBone(Element element) throws Exception {
|
||||
Matrix4f ret = new Matrix4f();
|
||||
ret.m00 = XMLUtil.getFloat(element, "m00");
|
||||
ret.m01 = XMLUtil.getFloat(element, "m01");
|
||||
ret.m02 = XMLUtil.getFloat(element, "m02");
|
||||
ret.m03 = XMLUtil.getFloat(element, "m03");
|
||||
ret.m10 = XMLUtil.getFloat(element, "m10");
|
||||
ret.m11 = XMLUtil.getFloat(element, "m11");
|
||||
ret.m12 = XMLUtil.getFloat(element, "m12");
|
||||
ret.m13 = XMLUtil.getFloat(element, "m13");
|
||||
ret.m20 = XMLUtil.getFloat(element, "m20");
|
||||
ret.m21 = XMLUtil.getFloat(element, "m21");
|
||||
ret.m22 = XMLUtil.getFloat(element, "m22");
|
||||
ret.m23 = XMLUtil.getFloat(element, "m23");
|
||||
ret.m30 = XMLUtil.getFloat(element, "m30", 0.0f);
|
||||
ret.m31 = XMLUtil.getFloat(element, "m31", 0.0f);
|
||||
ret.m32 = XMLUtil.getFloat(element, "m32", 0.0f);
|
||||
ret.m33 = XMLUtil.getFloat(element, "m33", 1.0f);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,191 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model.loaders;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* Some simple XML utilities
|
||||
* @author cas
|
||||
*/
|
||||
final class XMLUtil {
|
||||
|
||||
/**
|
||||
* Get a single child element
|
||||
* @param child
|
||||
* @return the single child element, or null
|
||||
* @throws Exception if the child is present multiple times
|
||||
*/
|
||||
static Element getChild(Element element, String child) throws Exception {
|
||||
NodeList nodes = element.getChildNodes();
|
||||
Element ret = null;
|
||||
for (int i = 0; i < nodes.getLength(); i ++) {
|
||||
Node childNode = (Node) nodes.item(i);
|
||||
if (childNode.getNodeName().equals(child) && childNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
if (ret != null) {
|
||||
throw new Exception("Child element '"+child+"' present multiple times");
|
||||
} else {
|
||||
ret = (Element) childNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name The name of the child elements you want
|
||||
* @return a List of child Elements
|
||||
*/
|
||||
static List getChildren(Element element, String name) throws Exception {
|
||||
NodeList nodes = element.getChildNodes();
|
||||
ArrayList ret = new ArrayList(nodes.getLength());
|
||||
for (int i = 0; i < nodes.getLength(); i ++) {
|
||||
Node childNode = (Node) nodes.item(i);
|
||||
if (childNode.getNodeName().equals(name) && childNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
ret.add(childNode);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for getting float values out of XML elements
|
||||
* @param attribute The name of the attribute
|
||||
* @throws NumberFormatException If the supplied attribute is not a number
|
||||
* @throws Exception if the value is missing
|
||||
* @return the parsed float value
|
||||
*/
|
||||
static float getFloat(Element element, String attribute) throws Exception {
|
||||
String s = element.getAttribute(attribute);
|
||||
if (s == null || "".equals(s))
|
||||
throw new Exception("Attribute '"+attribute+"' has not been specified for "+element.getNodeName());
|
||||
else
|
||||
return Float.parseFloat(s);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A convenience method for getting float values out of XML elements
|
||||
* @param attribute The name of the attribute
|
||||
* @param defaultValue The default value to return if no default is specified
|
||||
* @throws NumberFormatException If the supplied attribute is not a number
|
||||
* @return the parsed float value
|
||||
*/
|
||||
static float getFloat(Element element, String attribute, float defaultValue) throws Exception {
|
||||
String s = element.getAttribute(attribute);
|
||||
if (s == null || "".equals(s))
|
||||
return defaultValue;
|
||||
else
|
||||
return Float.parseFloat(s);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A convenience method for getting integer values out of XML elements
|
||||
* @param attribute The name of the attribute
|
||||
* @throws NumberFormatException If the supplied attribute is not a number
|
||||
* @throws Exception if the value is missing
|
||||
* @return the parsed integer value
|
||||
*/
|
||||
static int getInt(Element element, String attribute) throws Exception {
|
||||
String s = element.getAttribute(attribute);
|
||||
if (s == null || "".equals(s))
|
||||
throw new Exception("Attribute '"+attribute+"' has not been specified for "+element.getNodeName());
|
||||
else
|
||||
return Integer.parseInt(s);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A convenience method for getting integer values out of XML elements
|
||||
* @param attribute The name of the attribute
|
||||
* @param defaultValue The default value to return if no default is specified
|
||||
* @throws NumberFormatException If the supplied attribute is not a number
|
||||
* @return the parsed integer value
|
||||
*/
|
||||
static int getInt(Element element, String attribute, int defaultValue) throws Exception {
|
||||
String s = element.getAttribute(attribute);
|
||||
if (s == null || "".equals(s))
|
||||
return defaultValue;
|
||||
else
|
||||
return Integer.parseInt(s);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A convenience method for getting string values out of XML elements
|
||||
* @param attribute The name of the attribute
|
||||
* @return the string value, which will not be null
|
||||
* @throws Exception the value is not specified
|
||||
*/
|
||||
static String getString(Element element, String attribute) throws Exception {
|
||||
String s = element.getAttribute(attribute);
|
||||
if (s == null || "".equals(s))
|
||||
throw new Exception("Attribute '"+attribute+"' has not been specified for "+element.getNodeName());
|
||||
else
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A convenience method for getting string values out of XML elements
|
||||
* @param attribute The name of the attribute
|
||||
* @param defaultValue The default value to return if no default is specified
|
||||
* @return the string value, which will not be null
|
||||
*/
|
||||
static String getString(Element element, String attribute, String defaultValue) throws Exception {
|
||||
String s = element.getAttribute(attribute);
|
||||
if (s == null || "".equals(s))
|
||||
return defaultValue;
|
||||
else
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the specified attribute is present and not empty or null in the element
|
||||
*/
|
||||
static boolean hasAttribute(Element element, String attribute) {
|
||||
String s = element.getAttribute(attribute);
|
||||
if (s == null || "".equals(s))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model.renderer;
|
||||
|
||||
/**
|
||||
* Listens out for events that occur in animations and takes appropriate actions
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public interface AnimationEventListener {
|
||||
/**
|
||||
* Fired when a frame with an action associated with it is rendered
|
||||
* @param src The source Renderer
|
||||
* @param action The action
|
||||
*/
|
||||
public void receiveAnimationEvent(ModelRenderer src, String action);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model.renderer;
|
||||
|
||||
import org.lwjgl.util.Renderable;
|
||||
import org.lwjgl.util.model.Frame;
|
||||
import org.lwjgl.util.model.Model;
|
||||
|
||||
/**
|
||||
* The interface for processing individual frames of rendered models.
|
||||
* Typically the processor will process the frame of animation, and store
|
||||
* the processed results in some data structure that make it easy to render.
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public interface FrameProcessor extends Renderable {
|
||||
|
||||
/**
|
||||
* Process a frame.
|
||||
* @param model The model
|
||||
* @param frame The frame to process
|
||||
*/
|
||||
public void process(Model model, Frame frame);
|
||||
|
||||
}
|
|
@ -1,327 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model.renderer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.lwjgl.util.Renderable;
|
||||
import org.lwjgl.util.Timer;
|
||||
import org.lwjgl.util.model.Frame;
|
||||
import org.lwjgl.util.model.Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* Pluggable model renderer
|
||||
* <p>
|
||||
* Material lookups are performed by mapping the material name to a Renderable thing. You must
|
||||
* suppy appropriate Renderables - typically something that binds a 2D texture and sets up some
|
||||
* GL state.
|
||||
* <p>
|
||||
* To animate things, you will need to call Timer.tick() every frame to update the timers in your
|
||||
* Renderables. Then they'll just animate themselves. Hurrah!
|
||||
*
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class ModelRenderer implements Renderable {
|
||||
|
||||
/** Material map: String name->Renderable */
|
||||
private static final Map materials = new HashMap();
|
||||
|
||||
/** The model we're rendering */
|
||||
private Model model;
|
||||
|
||||
/** The frame processor */
|
||||
private FrameProcessor processor;
|
||||
|
||||
/** Animation event listeners */
|
||||
private List listeners;
|
||||
|
||||
/** The current material */
|
||||
private Renderable material;
|
||||
|
||||
/** The animation currently being animated */
|
||||
private Frame[] frame;
|
||||
|
||||
/** The current time */
|
||||
private final Timer timer = new Timer();
|
||||
|
||||
/** Last frame rendered */
|
||||
private Frame currentFrame;
|
||||
|
||||
/** Visibility */
|
||||
private boolean visible = true;
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
*/
|
||||
public ModelRenderer() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param model The model to set.
|
||||
*/
|
||||
public void setModel(Model model) {
|
||||
if (this.model == model) {
|
||||
return;
|
||||
}
|
||||
this.model = model;
|
||||
material = (Renderable) materials.get(model.getMaterial());
|
||||
frame = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Model we're rendering with this Renderer
|
||||
*/
|
||||
public Model getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the animation
|
||||
* @param animation
|
||||
*/
|
||||
public void setAnimation(String animation) {
|
||||
if (model == null) {
|
||||
return;
|
||||
}
|
||||
frame = model.getAnimation(animation);
|
||||
timer.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the model
|
||||
*/
|
||||
public void update() {
|
||||
|
||||
// Don't do anything if there's no model or no animation or no processor
|
||||
if (model == null || frame == null || processor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Work out what frame to show
|
||||
Frame frame = findFrame();
|
||||
if (frame != currentFrame) {
|
||||
currentFrame = frame;
|
||||
processFrame();
|
||||
if (currentFrame.getAction() != null) {
|
||||
fireAnimationEvent(currentFrame.getAction());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Render things
|
||||
*/
|
||||
public void render() {
|
||||
|
||||
// Don't do anything if there's no model or no animation or no processor
|
||||
if (model == null || frame == null || processor == null || !visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set up GL state from the Model's material
|
||||
if (material != null) {
|
||||
material.render();
|
||||
}
|
||||
|
||||
// Render the current frame
|
||||
renderFrame();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the nearest frame to the current time
|
||||
* @return the Frame nearest the current time
|
||||
*/
|
||||
private Frame findFrame() {
|
||||
float time = timer.getTime();
|
||||
|
||||
// Use a binary search to find the frame
|
||||
int i = 0;
|
||||
for (int j = frame.length - 1; i <= j;) {
|
||||
int k = i + j >> 1;
|
||||
Frame f = frame[k];
|
||||
if (f.getTime() == time) {
|
||||
return f;
|
||||
} else if (f.getTime() < time) {
|
||||
i = k + 1;
|
||||
} else {
|
||||
j = k - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return frame[i + 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the current frame of animation
|
||||
*/
|
||||
protected void processFrame() {
|
||||
processor.process(model, currentFrame);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the current frame
|
||||
*/
|
||||
protected void renderFrame() {
|
||||
processor.render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a material
|
||||
*
|
||||
* @param name
|
||||
* The material's name
|
||||
* @param renderable
|
||||
* The renderable object
|
||||
*/
|
||||
public static void putMaterial(String name, Renderable renderable) {
|
||||
materials.put(name, renderable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a material
|
||||
* @param name The material's name
|
||||
* @return a Renderable
|
||||
*/
|
||||
public static Renderable removeMaterial(String name) {
|
||||
return (Renderable) materials.remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this Renderer is visible
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the visibility of this Renderer
|
||||
* @param visible
|
||||
*/
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the animation is paused
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isPaused() {
|
||||
return timer.isPaused();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause the animation
|
||||
*/
|
||||
public void pause() {
|
||||
timer.pause();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewind the animation
|
||||
*/
|
||||
public void rewind() {
|
||||
timer.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resume a paused animation
|
||||
*/
|
||||
public void resume() {
|
||||
timer.resume();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the processor.
|
||||
*/
|
||||
public FrameProcessor getProcessor() {
|
||||
return processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the processor. The processor is the clever bit that actually does the
|
||||
* vertex twiddling and rendering.
|
||||
* @param processor The processor to set.
|
||||
*/
|
||||
public void setProcessor(FrameProcessor processor) {
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an animation listener
|
||||
* @param listener
|
||||
*/
|
||||
public void addAnimationEventListener(AnimationEventListener listener) {
|
||||
if (listeners == null) {
|
||||
listeners = new ArrayList(1);
|
||||
}
|
||||
listeners.remove(listener);
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an animation listener
|
||||
* @param listener
|
||||
*/
|
||||
public void removeAnimationEventListener(AnimationEventListener listener) {
|
||||
if (listeners == null) {
|
||||
return;
|
||||
}
|
||||
listeners.remove(listener);
|
||||
if (listeners.size() == 0) {
|
||||
listeners = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire an animation event
|
||||
* @param action
|
||||
*/
|
||||
protected void fireAnimationEvent(String action) {
|
||||
if (listeners == null) {
|
||||
return;
|
||||
}
|
||||
int n = listeners.size();
|
||||
for (int i = 0; i < n; i ++) {
|
||||
AnimationEventListener listener = (AnimationEventListener) listeners.get(i);
|
||||
listener.receiveAnimationEvent(this, action);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* 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 'LWJGL' 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 org.lwjgl.util.model.renderer;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
|
||||
/**
|
||||
* A 3D sprite!
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class Sprite3D extends ModelRenderer {
|
||||
|
||||
/** Current position */
|
||||
private final Vector3f position = new Vector3f();
|
||||
|
||||
/** Current orientation (axis/angle) */
|
||||
private final Vector3f axis = new Vector3f();
|
||||
private float angle;
|
||||
|
||||
/*
|
||||
* Recognised animation actions
|
||||
*/
|
||||
private static final String ANIM_HIDE = "hide";
|
||||
private static final String ANIM_REWIND = "rewind";
|
||||
private static final String ANIM_GOTO = "goto ";
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
*/
|
||||
public Sprite3D() {
|
||||
addAnimationEventListener(new AnimationEventListener() {
|
||||
public void receiveAnimationEvent(ModelRenderer src, String action) {
|
||||
if (action.equals(ANIM_HIDE)) {
|
||||
setVisible(false);
|
||||
} else if (action.equals(ANIM_REWIND)) {
|
||||
rewind();
|
||||
} else if (action.startsWith(ANIM_GOTO)) {
|
||||
setAnimation(action.substring(ANIM_GOTO.length()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.util.model.renderer.ModelRenderer#renderFrame()
|
||||
*/
|
||||
protected void renderFrame() {
|
||||
// TODO: rotation
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(position.getX(), position.getY(), position.getY());
|
||||
super.renderFrame();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the position.
|
||||
*/
|
||||
public Vector3f getPosition() {
|
||||
return position;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue