pax_global_header 0000666 0000000 0000000 00000000064 11303765311 0014512 g ustar 00root root 0000000 0000000 52 comment=c60697a422637cd785dcfc4565777aa39b0ad135 java3ds-fileloader-1.2+dfsg/ 0000775 0000000 0000000 00000000000 11303765311 0015732 5 ustar 00root root 0000000 0000000 java3ds-fileloader-1.2+dfsg/META-INF/ 0000775 0000000 0000000 00000000000 11303765311 0017072 5 ustar 00root root 0000000 0000000 java3ds-fileloader-1.2+dfsg/META-INF/MANIFEST.MF 0000664 0000000 0000000 00000000152 11303765311 0020522 0 ustar 00root root 0000000 0000000 Manifest-Version: 1.0 Ant-Version: Apache Ant 1.6.5 Created-By: 1.4.2_08-b03 (Sun Microsystems Inc.) java3ds-fileloader-1.2+dfsg/com/ 0000775 0000000 0000000 00000000000 11303765311 0016510 5 ustar 00root root 0000000 0000000 java3ds-fileloader-1.2+dfsg/com/microcrowd/ 0000775 0000000 0000000 00000000000 11303765311 0020660 5 ustar 00root root 0000000 0000000 java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/ 0000775 0000000 0000000 00000000000 11303765311 0022126 5 ustar 00root root 0000000 0000000 java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/ 0000775 0000000 0000000 00000000000 11303765311 0023276 5 ustar 00root root 0000000 0000000 java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/ 0000775 0000000 0000000 00000000000 11303765311 0024475 5 ustar 00root root 0000000 0000000 java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/CannotChopException.java 0000664 0000000 0000000 00000002550 11303765311 0031255 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds; /** * Exception thrown by chunks to indicate that the * chopper cannot appropriately chop(parse) it. * This Exception won't return null for getCause() */ public class CannotChopException extends Exception { public CannotChopException(Throwable cause) { this("", cause); } public CannotChopException(String message, Throwable cause) { super(message, cause); } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/ChunkChopper.java 0000664 0000000 0000000 00000050345 11303765311 0027740 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@realvue.com */ package com.microcrowd.loader.java3d.max3ds; import java.awt.Image; import java.io.IOException; import java.io.InputStream; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; import javax.media.j3d.Behavior; import javax.media.j3d.BranchGroup; import javax.media.j3d.Light; import javax.media.j3d.Texture; import javax.media.j3d.TransformGroup; import javax.vecmath.Point3f; import javax.vecmath.Vector3f; import com.microcrowd.loader.java3d.max3ds.chunks.Chunk; import com.microcrowd.loader.java3d.max3ds.data.KeyFramer; import com.sun.j3d.loaders.SceneBase; import com.sun.j3d.utils.image.TextureLoader; /** * A singleton flyweight factory responsible for chopping the * data up and sending it to the corresponding * chunks(which are flyweights ala the flyweight pattern) * for processing. * This will sequentially read a 3ds file, load or * skip chunks and subchunks and initialize the data * for the chunks. *
* Retrieved data may be stored as state in the ChunkChopper * via {@link #pushData} for use by other chunks. *
* Features not supported; unknown chunks are skipped. */ public class ChunkChopper { private Logger logger = Logger.getLogger(ChunkChopper.class.getName()); private Loader3DS loader; private BranchGroup sceneGroup; private SceneBase base; private HashMap dataMap; private ByteBuffer chunkBuffer; private Integer chunkID; private TransformGroup currentGroup; private String currentObjectName; private ChunkTester chunkTester = new ChunkTester(); private Chunk mainChunk = new Chunk("MainChunk"); private ChunkMap chunkMap = new ChunkMap(mainChunk); private KeyFramer keyFramer = new KeyFramer(); /** This should be turned on by Loader3DS to view debugging information. */ public static boolean debug; /** Current chunk for which debugging info is viewed if debug == true */ public static Chunk debugChunk; /** * private singleton constructor. */ public ChunkChopper(){} /** * This sequentially parses the chunks out of the input stream and * constructs the 3D entities represented within. * A Chunk is a little endian data structure consists of a * 6 byte header followed by subchunks and or data. * The first short int(little endian) represent the id * of the chunk. The next int represent the total * length of the chunk(total of data, subchunks and chunk header). *
* The first chunk is the main chunk (id=4D4D) and its length * is always the length of the file. It only contains sub chunks. * Other chunks may contain data, subchunks or both. If the format * of a chunk is unknown skipped. *
* Subclasses of chunk will all automagically load the subchunks. * It is the programmers responsibility to ensure that the data * preceeding the subchunks is loaded or skipped as * required and that something useful is done with the data. If data from the * subchunks is needed in order to initialize components then that code should be * placed in {@link Chunk#initialize}. Otherwise the data may be dealt with in * {@link Chunk#loadData}. Also, if a chunk has data preceeding its subchunks * it communicates how many bytes long that data is by returning it from loadData. *
* This chopper reads a file in order from beginning to end * @param inputStream the stream with the data to be parsed. * @param loader the loader that will be configured from the data. * @param modelName name of the model file for display purposes. * @param modelSize size in bytes of the file to read. */ public synchronized SceneBase loadSceneBase(InputStream inputStream, Loader3DS loader, int modelSize) { this.loader = loader; this.sceneGroup = new BranchGroup(); this.base = new SceneBase(); this.dataMap = new HashMap(); base.setSceneGroup(sceneGroup); //FileChannel channel = null; ReadableByteChannel channel = null; try { channel = Channels.newChannel(inputStream); chunkBuffer = getByteBuffer(channel, modelSize); //chunkBuffer = getDirectByteBuffer(channel, modelSize); int mainChunkID = chunkBuffer.getShort(); long mainChunkLength = chunkBuffer.getInt(); long begin = System.currentTimeMillis(); logger.finest("\n\n\n STARTING SUBCUNKS " + (mainChunkLength - 61)); try { loadSubChunks(mainChunk, 0); } catch(CannotChopException e){ } logger.finest("FINISHED WITH THE SUBCHUNKS"); } catch (Exception e) { e.printStackTrace(); } finally { try { if(channel != null) { channel.close(); } } catch (Exception e){ //Just closing file.. don't care. } } return base; } /** * Allocates and loads a byte buffer from the channel * @param channel the file channel to load the data from * @return a direct byte buffer containing all the data of the channel at position 0 */ public ByteBuffer getByteBuffer(ReadableByteChannel channel, int channelSize) throws IOException { ByteBuffer chunkBuffer = ByteBuffer.allocate(channelSize); chunkBuffer.order(ByteOrder.LITTLE_ENDIAN); channel.read(chunkBuffer); chunkBuffer.position(0); return chunkBuffer; } /** * The base class Chunk takes care of loading subchunks for * all chunks types. It occurs as follows: *
short
.
*/
public Integer getID()
{
return chunkID;
}
/**
* Loads the image to server as a texture.
* @param textureImageName name of the image that
* is going to be set to be the texture.
*/
public Texture createTexture(String textureImageName)
{
Image image = loader.getTextureImage(textureImageName);
if(image == null)
{
System.err.println("Cannot load texture image " + textureImageName +
". Make sure it is in the directory with the model file. " +
"If its a bmp make sure JAI is installed.");
return null;
}
try
{
TextureLoader textureLoader = new TextureLoader(image, null);
return textureLoader.getTexture();
}
catch(Exception e){
e.printStackTrace();
}
return null;
}
/**
* prints some handy information... the chunk hierarchy.
*/
protected void debug(Chunk parentChunk, int level, Integer chunkID, long chunkLength, int position, long limit)
{
try {
for(int i=0; i* Features not supported; unknown chunks are skipped. *
*/ public class Loader3DS extends LoaderBase { private boolean dataMapInitialized; private TextureImageLoader textureImageLoader; private boolean fromUrl; public Loader3DS() { //turnOnDebug(); } /** * Setting this will initialize a lot of debugging code that has lots of * overhead. */ private boolean debugMode; /** * This is not supported * * @param reader loads a model from a reader * * @return nothing, this isn't implemented. * * @throws FileNotFoundException * @throws UnsupportedOperationException */ public Scene load(Reader reader) throws FileNotFoundException { throw new UnsupportedOperationException("Not supported for 3DS"); } /** * Loads the model by parsing the file, modelPath and creating a 3D Scene. * * @param modelPath the path of the 3ds file. * * @return a loaded scene * * @throws FileNotFoundException if the file can't be located. */ public Scene load(String modelPath) throws FileNotFoundException { InputStream fileIn = null; setBasePathFromFilename(modelPath); try { File modelFile = getFile(modelPath); fileIn = new FileInputStream(modelFile); return parseChunks(fileIn, (int)modelFile.length()); } finally { try { fileIn.close(); } catch (Exception e) { e.printStackTrace(); //Don't care about exceptions at this point. } } } private void setBaseUrlFromUrl(URL url) throws FileNotFoundException { String u = url.toString(); String s; if (u.lastIndexOf('/') == -1) { s = url.getProtocol() + ":"; } else { s = u.substring(0, u.lastIndexOf('/') + 1); } try { setBaseUrl(new URL(s)); } catch (MalformedURLException e) { throw new FileNotFoundException(e.getMessage()); } } /* * Takes a file name and sets the base path to the directory * containing that file. */ private void setBasePathFromFilename(String fileName) { if (fileName.lastIndexOf(java.io.File.separator) == -1) { // No path given - current directory setBasePath("." + java.io.File.separator); } else { setBasePath(fileName.substring(0, fileName.lastIndexOf(java.io.File.separator))); } } /** * Set the path where files associated with this .obj file are * located. * Only needs to be called to set it to a different directory * from that containing the .obj file. */ public void setBasePath(String pathName) { String basePath = pathName; if (basePath == null || basePath == "") basePath = "." + java.io.File.separator; basePath = basePath.replace('/', java.io.File.separatorChar); basePath = basePath.replace('\\', java.io.File.separatorChar); if (!basePath.endsWith(java.io.File.separator)) basePath = basePath + java.io.File.separator; super.setBasePath(basePath); } /** * Returns true if this loader is loading files * from a url. */ public boolean fromUrl() { return fromUrl; } /** * gets an image with the specified name. * This uses a DefaultTextureImageLoader * to load the image if one hasn't been set for * this loader. * @param imageName name of image to load. * @return image corresponding to imageName */ public Image getTextureImage(String imageName) { try { if(textureImageLoader == null) { textureImageLoader = new DefaultTextureImageLoader(this); } return textureImageLoader.getTextureImage(imageName); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); } catch (Exception e) { e.printStackTrace(); } return null; } /** * Sets the TextureImageLoader to be used * when texture images are needed. * @param loader the TextureImageLoader that will be used to load images. */ public void setTextureImageLoader(TextureImageLoader loader) { textureImageLoader = loader; } /** * Gets a chunk chopper to do all the dirty work. * * @param inputStream the stream containing the model. * @param modelSize size of the model file. * * @return a java3d scene built from input. */ protected Scene parseChunks(InputStream inputStream, int modelSize) { ChunkChopper chopper = new ChunkChopper(); SceneBase base = chopper.loadSceneBase(inputStream, this, modelSize); if(!chopper.hasLights()) { addDefaultLights(base.getSceneGroup()); addDefaultLights(chopper.getGroup()); } return base; } /** * Adds defaultlights to the group provided * similar to the ones 3ds max adds when there are none in the scene. * @param group to add the lighting to. */ public static void addDefaultLights(Group group) { PointLight light1 = new PointLight(); PointLight light2 = new PointLight(); light1.setInfluencingBounds(new BoundingSphere(new Point3d(0,0,0), 3000)); light2.setInfluencingBounds(new BoundingSphere(new Point3d(0,0,0), 3000)); Transform3D t1 = new Transform3D(new float[]{1.0f, 0.0f, 0.0f, -900f, 0.0f, 1.0f, 0.0f, 1500f, 0.0f, 0.0f, 1.0f, 1000f, 0.0f, 0.0f, 0.0f, 1.0f}); Transform3D t2 = new Transform3D(new float[]{1.0f, 0.0f, 0.0f, 900f, 0.0f, 1.0f, 0.0f, -1500f, 0.0f, 0.0f, 1.0f, -1000f, 0.0f, 0.0f, 0.0f, 1.0f}); TransformGroup group1 = new TransformGroup(t1); TransformGroup group2 = new TransformGroup(t2); group1.addChild(light1); group2.addChild(light2); group.addChild(group1); group.addChild(group2); } /** * Retrieves a file with a given name. * * @param fileName name of file to retrieve. * * @return retrieved file. */ private File getFile(String fileName) { File file = null; try { file = new File(fileName); if (!file.exists()) { throw new IOException(fileName + " doesn't exist"); } } catch (IOException ioe) { ioe.printStackTrace(); } return file; } /** * throws UnsupportedOperationException * * @param url url of model to be loaded. * * @return a java3d scene represented in url * * @throws FileNotFoundException if file couldn't be found. */ public Scene load(URL url) throws FileNotFoundException { fromUrl = true; try { URLConnection connection = url.openConnection(); if (baseUrl == null) setBaseUrlFromUrl(url); return parseChunks(connection.getInputStream(), connection.getContentLength()); } catch (Exception e) { e.printStackTrace(); throw new IllegalArgumentException("Url " + url + " cannot be loaded"); } } /** * Turn on debug mode for all 3ds xml. */ public void turnOnDebug() { if (!debugMode) { ChunkChopper.debug = true; debugMode = true; } } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/Main.java 0000664 0000000 0000000 00000036614 11303765311 0026236 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds; import java.applet.Applet; import java.awt.BorderLayout; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import javax.media.j3d.Behavior; import javax.media.j3d.BoundingSphere; import javax.media.j3d.BranchGroup; import javax.media.j3d.Canvas3D; import javax.media.j3d.GraphicsConfigTemplate3D; import javax.media.j3d.Interpolator; import javax.media.j3d.Locale; import javax.media.j3d.PhysicalBody; import javax.media.j3d.PhysicalEnvironment; import javax.media.j3d.RotPosPathInterpolator; import javax.media.j3d.Transform3D; import javax.media.j3d.TransformGroup; import javax.media.j3d.TransformInterpolator; import javax.media.j3d.View; import javax.media.j3d.ViewPlatform; import javax.media.j3d.VirtualUniverse; import javax.swing.JFileChooser; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.filechooser.FileFilter; import javax.vecmath.Point3d; import javax.vecmath.Point3f; import javax.vecmath.Quat4f; import com.sun.j3d.loaders.Scene; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior; /** * Provides an example of loader usage with key navigation. * If loaded as an applet expects a 'url' parameter tag which * must be specified as a fully qualified url. If there isn't a * url tag it looks for an applet parameter called filename. * If this is run from the command line it will try to load * the file passed in at the prompt, unless a command line argument * 'url' is the first argument. Then it will load the url represented * as the second command argument. */ public class Main extends Applet { private BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),3000.0); private Canvas3D canvas; private String modelLocation; private static final String DEFAULT_MODEL = "bounce.3DS"; private BranchGroup universeBranch; /** * If loaded from the command line a modelFile must be provided. * args are
* | A B C D |
* M = | E F G H |
* | I J K L |
* | M N O P |
*
* Then the direction vector for each axis is as follows:
*
*
* X-axis = [ A E I ]
* Y-axis = [ B F J ]
* Z-axis = [ C G K ]
*
*
* @return the actual number of bytes read.
*/
public void loadData(ChunkChopper chopper)
{
Point3f xAxis = new Point3f();
xAxis = chopper.getPoint();
Point3f zAxis = chopper.getPoint();
Point3f yAxis = chopper.getPoint();
Point3f origin = chopper.getPoint();
Transform3D transform = new Transform3D(new double[]{
xAxis.x, xAxis.y, xAxis.z, origin.x,
yAxis.x, yAxis.y, yAxis.z, origin.y,
-zAxis.x, -zAxis.y, -zAxis.z, origin.z,
0,0,0,1});
String meshName = chopper.getObjectName();
chopper.getKeyFramer().setCoordinateSystem(meshName, transform);
}
}
java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/BooleanChunk.java 0000664 0000000 0000000 00000003267 11303765311 0031213 0 ustar 00root root 0000000 0000000 /**
* Make a donation http://sourceforge.net/donate/index.php?group_id=98797
* Microcrowd.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact Josh DeFord jdeford@microcrowd.com
*/
package com.microcrowd.loader.java3d.max3ds.chunks;
import com.microcrowd.loader.java3d.max3ds.ChunkChopper;
/**
* A boolean chunk is true if it is present otherwise
* there is no chunk and that represents false. This chunk
* will set chopper data to Boolean true with a key that is the id of the chunk.
* These have no subchunks. Only String data.
*/
public class BooleanChunk extends Chunk
{
/**
* If this method is being called then
* a boolean true will be set on the chunk chopper
* with a key that is the id of this chunk.
*
* @param chopper the chopper on which the boolean true data is to be set
*
*/
public void loadData(ChunkChopper chopper)
{
chopper.pushData(chopper.getID(), new Boolean(true));
}
}
java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/BoundingBoxChunk.java 0000664 0000000 0000000 00000003724 11303765311 0032050 0 ustar 00root root 0000000 0000000 /**
* Make a donation http://sourceforge.net/donate/index.php?group_id=98797
* Microcrowd.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact Josh DeFord jdeford@microcrowd.com
*/
package com.microcrowd.loader.java3d.max3ds.chunks;
import javax.media.j3d.BoundingBox;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import com.microcrowd.loader.java3d.max3ds.ChunkChopper;
/**
* Loads the bounding box for keyframer of mesh. The pivot
* is relative to it.
* {@see KeyFramerInfoChunk} for more information about using
* animations from a 3ds file
*/
public class BoundingBoxChunk extends Chunk
{
/**
* Gets the bounding box and associates it with the current mes.
* @param chopper the ChunkChopper containing the state of the parser.
*/
public void loadData(ChunkChopper chopper)
{
Point3f min = chopper.getPoint();
Point3f max = chopper.getPoint();
BoundingBox box = new BoundingBox(new Point3d(min), new Point3d(max));
Point3f center = new Point3f(max.x - min.x,
max.y - min.y,
max.z - min.z);
//chopper.getKeyFramer().setBoundingBox(box);
chopper.getKeyFramer().setPivotCenter(center);
}
}
java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/CameraChunk.java 0000664 0000000 0000000 00000005207 11303765311 0031020 0 ustar 00root root 0000000 0000000 /**
* Make a donation http://sourceforge.net/donate/index.php?group_id=98797
* Microcrowd.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact Josh DeFord jdeford@microcrowd.com
*/
package com.microcrowd.loader.java3d.max3ds.chunks;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import com.microcrowd.loader.java3d.max3ds.ChunkChopper;
/**
* Loads percentage values from binary data representing them.
*/
public class CameraChunk extends Chunk
{
/**
* Reads the position and target vectors and subtracts them to get
* an axis of rotation. Translate a transform to position and rotate
* on the axis of rotation to point at the target. The angle
* between the z axis and the axis of rotation is the angle used to
* rotate. The translated and rotated vector is stored it the
* chopper as a named object since camera chunks are named.
*/
public void loadData(ChunkChopper chopper)
{
Vector3d yVector = new Vector3d(0,1,0);
Point3d position = new Point3d(chopper.getPoint());
Point3d target = new Point3d(chopper.getPoint());
float bank = chopper.getFloat();
float lens = chopper.getFloat();
//This is the vector for the direction
//of the camera. Represented as a line
//from target to position. We'll use it
//as an axis when we bank.
//Vector3d cameraDirection = new Vector3d();
//cameraDirection.sub(target,position);
//AxisAngle4f bankAxisAngle = new AxisAngle4f(cameraDirection, bankAngle);
Transform3D transform = new Transform3D();
transform.lookAt(position, target, yVector);
transform.invert();
((TransformGroup)chopper.getGroup()).setTransform(transform);
chopper.addViewGroup(chopper.getGroup());
}
}
java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/Chunk.java 0000664 0000000 0000000 00000010440 11303765311 0027702 0 ustar 00root root 0000000 0000000 /**
* Make a donation http://sourceforge.net/donate/index.php?group_id=98797
* Microcrowd.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact Josh DeFord jdeford@microcrowd.com
*/
package com.microcrowd.loader.java3d.max3ds.chunks;
import java.util.HashMap;
import com.microcrowd.loader.java3d.max3ds.ChunkChopper;
/**
* The base class for all chunks. Chunks are flyweights and should be managed
* by {@link ChunkChopper} Every chunk should know how many bytes of data(or
* be able figure out) to read before its subchunks are found. Chunks that only have
* subchunks need not overrided loadData.
* Chunks may store data for later use in loadData with {@link pushData}
* If a chunk needs to initialize components with from subchunks, that data
* can be retrieved with {@link ChunkChopper#popData} inside the {@link
* #initialize} method. {@link #loadData} is called at the beginning of the
* loading process, before any data or subchunks have been loaded(the chunk
* itself must load its data).
* * During loadData, if the length of data before subchunks is unknown, * {@link ChunkChopper#getChunkBytes} may be called and all the data * for the chunk(including subchunks) will be read and returned. */ public class Chunk { private HashMap subChunkMap = new HashMap(); private String name; private String description; /** * default no-arg constructror. */ public Chunk(String chunkName) { name = chunkName; } /** * default no-arg constructror. */ public Chunk() { } public void addSubChunk(Integer id, Chunk subChunk) { subChunkMap.put(id, subChunk); } public Chunk getSubChunk(Integer id) { return (Chunk)subChunkMap.get(id); } /** * This method is called after all the current chunks subchunks are * loaded. Any data stored by those subchunks may be retrieved via {@link * ChunkChopper#popData} * The default implementation does nothing. * * @param chopper may contain data loaded by subchunks. */ public void initialize(ChunkChopper chopper) { } /** * This is called by the chunk chopper before any of the chunk's * subchunks are loaded. Any data loaded that may need to be * used later by superchunks should be stored in * the chunk chopper via {@link ChunkChopper#popData} * The default implementation does nothing. * @param chopper may contain data loaded by subchunks. */ public void loadData(ChunkChopper chopper) { } /** * Sets nice human readable name for the chunk. * @param name to use for display of this chunk. */ public final void setName(String name) { this.name = name; } /** * Gets a human readable name for the chunk. * @return name used to display the chunk. */ public final String getName() { return name; } public final String getDescription() { return description; } public final void setDescription(String desc) { description = desc; } /** * Returns the name of this chunk. * If the name is null then it just * returns the unqualified class name. */ public String toString() { if (getName() != null) return getName(); String className = getClass().getName(); return className.substring(className.lastIndexOf('.') + 1, className.length()); } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/ColorChunk.java 0000664 0000000 0000000 00000005700 11303765311 0030704 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import javax.vecmath.Color3f; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; /** * Loads colors from binary data representing them. */ public class ColorChunk extends Chunk { protected int currentColorType; private static final int FLOAT_COLOR = 0x10; private static final int BYTE_COLOR = 0x11; private static final int BYTE_COLOR_GAMMA = 0x12; private static final int FLOAT_COLOR_GAMMA = 0x13; /** * Based on the color type retrieved * from {@link #getColorType} loads * an rgb or float color and pushes * it onto the chunk chopper. * * @param chopper the chopper that will store the color data. */ public void loadData(ChunkChopper chopper) { int colorType = getColorType(chopper); if (colorType == BYTE_COLOR) { float r = (chopper.getUnsignedByte()) / 255f; float g = (chopper.getUnsignedByte()) / 255f; float b = (chopper.getUnsignedByte()) / 255f; Color3f color = new Color3f(r, g, b); chopper.pushData(chopper.getID(), color); } else if (colorType == FLOAT_COLOR) { Color3f color = new Color3f(chopper.getFloat(), chopper.getFloat(), chopper.getFloat()); chopper.pushData(chopper.getID(), color); } else { throw new IllegalArgumentException("Only RGB colors are enabled. ChunkID=" + Integer.toHexString((byte)chopper.getID().intValue()) + " Color type = " + Integer.toHexString((byte)colorType)); } } /** * Gets the color type for this chunk. * @param chopper with the information the * chunk may use to determine color type * @return the color type for the chunk retrieved * from the chopper using this chunks id. */ protected int getColorType(ChunkChopper chopper) { return chopper.getID().intValue(); } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/FacesDescriptionChunk.java 0000664 0000000 0000000 00000030372 11303765311 0033056 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import javax.media.j3d.Appearance; import javax.media.j3d.Geometry; import javax.media.j3d.Material; import javax.media.j3d.Shape3D; import javax.media.j3d.TransformGroup; import javax.vecmath.Color3f; import javax.vecmath.Point3f; import javax.vecmath.TexCoord2f; import javax.vecmath.Vector3f; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; import com.microcrowd.loader.java3d.max3ds.ChunkMap; import com.sun.j3d.utils.geometry.GeometryInfo; import com.sun.j3d.utils.geometry.NormalGenerator; import com.sun.j3d.utils.geometry.Stripifier; /** * This chunk describes all the triangles that make up a mesh. * Each triangle is defined in terms of three indexes each of which * is a point reference to a vertex in the vertex list loaded * by the triangular mesh chunk. * After loading the Smoothing chunk the normals for the mesh * are generated accordingly. */ public class FacesDescriptionChunk extends Chunk { public static final Appearance DEFAULT_APPEARANCE; private Point3f[] currentVertices; private TexCoord2f[] textureTriangles; private PointMapper shareMap; static { DEFAULT_APPEARANCE= new Appearance(); Material defaultMaterial = new Material(); defaultMaterial.setAmbientColor(new Color3f(.5f, .5f, .5f)); //defaultMaterial.setDiffuseColor(new Color3f(.5f, .5f, .5f)); //defaultMaterial.setSpecularColor(new Color3f(.5f, .5f, .5f)); DEFAULT_APPEARANCE.setMaterial(defaultMaterial); } /** * Maintains a two way mapping between coordinates * and vertices. A coordinate to vertex is one to many * Vertex to coordinate is one to one. * In this class we maintain the definition that a coordinate * is a point in 3D space and a vertex is a coordinate serving * as one of three defining a face. */ private class PointMapper extends HashMap { private Set[] coordinateSet; /** * Constructs a PointMapper with a * the number of coordinates initialized to size. * @param size the number of coordinates in the set. */ public PointMapper(int size) { coordinateSet = new Set[size]; } /** * Adds an index for a coordinate to the set of vertices mapped * to that coordinate. All coordinates may have one or more vertices * that use them. * @param coordinate the coordinate being mapped to the vertexNum * @param vertexNum the number of the vertex using the coordinate */ public void addCoordinate(Point3f coordinate, int vertexNum) { Set sharedCoordinates = (Set)get(coordinate); if(sharedCoordinates == null) { sharedCoordinates = new HashSet(); put(coordinate, sharedCoordinates); } sharedCoordinates.add(new Integer(vertexNum)); coordinateSet[vertexNum] = sharedCoordinates; } /** * Gets all the coordinates for a particular vertex that * also share that vertex after the smoothing groups have been * accounted for. Any coordinates that are not both shared * by the vertex and do not share a smoothing group with the coordinate * will not be returned. * @param coordinateNum the number of the coordinate to get the set * of vertices for that share it. * @param smoothGroups the group of coordinates used to filter out the * non-shared vertices. */ public Set getSharedCoordinates(int coordinateNum, int[] smoothGroups) { Set returnSet = new HashSet(); Set sharingVertices = coordinateSet[coordinateNum]; Iterator vertices = sharingVertices.iterator(); int coordinateMask = smoothGroups[coordinateNum]; while(vertices.hasNext()) { Integer vertex = (Integer)vertices.next(); int nextMask = smoothGroups[vertex.intValue()]; if((nextMask & coordinateMask) != 0) { returnSet.add(vertex); } } return returnSet; } } /** * Reads the number of faces from the ChunkChopper. * For each face read three shorts representing * indices of vertices loaded by the TriangularMeshChunk * * @param chopper chopper the has the data */ public void loadData(ChunkChopper chopper) { int numFaces = chopper.getUnsignedShort(); shareMap = new PointMapper(numFaces*3); Point3f[] coordinates = (Point3f[])chopper.popData(ChunkMap.VERTEX_LIST); TexCoord2f[] texturePoints = (TexCoord2f[])chopper.popData(ChunkMap.TEXTURE_COORDINATES); currentVertices = new Point3f[numFaces * 3]; chopper.pushData(chopper.getID(), currentVertices); if (texturePoints != null) { textureTriangles = new TexCoord2f[numFaces * 3]; } for (int i = 0; i < numFaces; i++) { int vertexIndex = i * 3; int index0 = chopper.getUnsignedShort(); int index1 = chopper.getUnsignedShort(); int index2 = chopper.getUnsignedShort(); currentVertices[vertexIndex] = coordinates[index0]; currentVertices[vertexIndex + 1] = coordinates[index1]; currentVertices[vertexIndex + 2] = coordinates[index2]; shareMap.addCoordinate(coordinates[index0], vertexIndex); shareMap.addCoordinate(coordinates[index1], vertexIndex+1); shareMap.addCoordinate(coordinates[index2], vertexIndex+2); if (textureTriangles != null) { textureTriangles[vertexIndex] = texturePoints[index0]; textureTriangles[vertexIndex + 1] = texturePoints[index1]; textureTriangles[vertexIndex + 2] = texturePoints[index2]; } //This is a bit masked value that is used to determine which edges are visible... not needed. chopper.getUnsignedShort(); } } /** * Loads a mesh onto the scene graph with the specified data * from subchunks. * If there is no material, this will put a default * material on the shape. */ public void initialize(ChunkChopper chopper) { final String materialName = (String)chopper.popData(ChunkMap.FACES_MATERIAL); final int[] smoothGroups = (int[])chopper.popData(ChunkMap.SMOOTH); Shape3D shape = new Shape3D(); GeometryInfo geometryInfo = new GeometryInfo(GeometryInfo.TRIANGLE_ARRAY); geometryInfo.setCoordinates(currentVertices); TransformGroup transformGroup = (TransformGroup)chopper.getGroup(); transformGroup.addChild(shape); if (textureTriangles != null) { geometryInfo.setTextureCoordinateParams(1, 2); geometryInfo.setTextureCoordinates(0, textureTriangles); } if(materialName != null) { shape.setAppearance((Appearance)chopper.getNamedObject(materialName)); } else { shape.setAppearance(DEFAULT_APPEARANCE); } if(smoothGroups == null) { NormalGenerator normalGenerator = new NormalGenerator(); geometryInfo.recomputeIndices(); normalGenerator.generateNormals(geometryInfo); } else { Vector3f[] normals = generateNormals(currentVertices); Vector3f[] smoothNormals = smoothNormals(normals, shareMap, smoothGroups); geometryInfo.setNormals(smoothNormals); } new Stripifier().stripify(geometryInfo); shape.setGeometry(geometryInfo.getGeometryArray()); shape.setCapability(Geometry.ALLOW_INTERSECT); com.sun.j3d.utils.picking.PickTool.setCapabilities(shape, com.sun.j3d.utils.picking.PickTool.INTERSECT_FULL); currentVertices=null; textureTriangles=null; } /** * Takes all the normals for all the vertices and averages them with * normals with which they share a coordinate and at least one smooth group. * @param currentNormals the normals for each face. * @param sharedPoints the point mapper that will choose which points are * and which are not shared. * @param smoothGroups the indexed list of group masks loaded by the smooth chunk. * @return normals averaged among the shared vertices in their smoothing groups. */ public Vector3f[] smoothNormals(Vector3f[] currentNormals, PointMapper sharedPoints, int[] smoothGroups) { Vector3f[] smoothNormals = new Vector3f[currentNormals.length]; for(int i=0; i < currentNormals.length; i++) { Set otherPoints = sharedPoints.getSharedCoordinates(i, smoothGroups); if(otherPoints != null) { Vector3f[] sharedNormals = new Vector3f[otherPoints.size()]; Iterator pointIterator = otherPoints.iterator(); for(int j = 0; j < sharedNormals.length; j++) { sharedNormals[j] = currentNormals[((Integer)pointIterator.next()).intValue()]; } smoothNormals[i] = averageNormals(sharedNormals); } else { smoothNormals[i] = currentNormals[i]; } } return smoothNormals; } /** * Averages the normals provided in order to provide * smooth, noncreased appearances for meshes. * @param normals the normals that should be averaged * @return a normalized normal that can be used in place * of all the normals provided. */ public Vector3f averageNormals(Vector3f[] normals) { Vector3f newNormal = new Vector3f(); for(int i=0; i < normals.length; i++) { newNormal.add(normals[i]); } newNormal.normalize(); return newNormal; } /** * Generates normals for each vertex of each * face that are absolutely normal to the face. * @param point0 The first point of the face * @param point1 The second point of the face * @param point2 The third point of the face * @return the three normals that should be * used for the triangle represented by the parameters. */ private Vector3f[] generateNormals(Point3f points[]) { Vector3f[] normals = new Vector3f[points.length]; for(int i=0; i < normals.length;) { Vector3f normal = new Vector3f(); Vector3f v1 = new Vector3f(); Vector3f v2 = new Vector3f(); v1.sub(points[i+1], points[i]); v2.sub(points[i+2], points[i]); normal.cross(v1, v2); normal.normalize(); normals[i++] = new Vector3f(normal); normals[i++] = new Vector3f(normal); normals[i++] = new Vector3f(normal); } return normals; } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/FacesMaterialChunk.java 0000664 0000000 0000000 00000004034 11303765311 0032325 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; /** * FacesMaterialsChunk contains the materials information * from the 3ds file. It contains information pertaining to * which faces of a mesh have materials on them and the * texture coordinates for texture mapping. * Right now, its just putting the name of the material * that needs to be applied to the mesh under construction. * * @author jdeford */ public class FacesMaterialChunk extends Chunk { /** * Loads the texture coordinates for a mesh, * * @param chopper the ChunkChopper containing the state of the parser. */ public void loadData(ChunkChopper chopper) { final String materialName = chopper.getString(); int numFaces = chopper.getUnsignedShort(); if (numFaces > 0) { for (int j = 0; j < numFaces; j++) { int index = j * 3; int position = chopper.getUnsignedShort() * 3; } } chopper.pushData(chopper.getID(), materialName); } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/FloatChunk.java 0000664 0000000 0000000 00000003222 11303765311 0030670 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; /** * These have no subchunks. Only data. * Any objects that have a float chunk * as a sub chunk may retrieve the float * value from {@link ChunkChopper.popData()} * using the current chunk id as an argument. */ public class FloatChunk extends Chunk { /** * Loads a Float value into the chopper * for use later when parent chunks are * initializing * * @param chopper the chopper in which the float * chunk will be stored by the id of this chunk. */ public void loadData(ChunkChopper chopper) { chopper.pushData(chopper.getID(), new Float(chopper.getFloat())); } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/FramesChunk.java 0000664 0000000 0000000 00000002752 11303765311 0031047 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; /** * This chunk specifies the beginning and end frames. * * @author jdeford */ public class FramesChunk extends Chunk { /** * Reads two ints. Start frame and stop frame. * * @param chopper the chopper that may be used to store the starting and * stopping frames. * */ public void loadData(ChunkChopper chopper) { long start = chopper.getUnsignedInt(); long stop = chopper.getUnsignedInt(); } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/FramesDescriptionChunk.java 0000664 0000000 0000000 00000004232 11303765311 0033246 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import javax.media.j3d.TransformGroup; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; import com.microcrowd.loader.java3d.max3ds.data.KeyFramer; /** * This chunk contains the name of the object * the frames belong to and the parameters and * hierarchy information for it. */ public class FramesDescriptionChunk extends Chunk { /** * reads the name of the object for these frames * and stores it in the chopper. * * @param chopper the chopper used to store the transient data * for this chunk. */ public void loadData(ChunkChopper chopper) { KeyFramer keyFramer = chopper.getKeyFramer(); String objectName = chopper.getString(); chopper.setObjectName(objectName); chopper.getUnsignedShort(); chopper.getUnsignedShort(); int fatherID = chopper.getShort(); TransformGroup transformGroup = chopper.getNamedTransformGroup(objectName); if(transformGroup == null)//its a dummy transformGroup. { transformGroup = new TransformGroup(); keyFramer.setDummyObject(transformGroup); } keyFramer.addFather(fatherID, transformGroup); } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/GlobalColorChunk.java 0000664 0000000 0000000 00000003121 11303765311 0032020 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; /** * Loads colors from binary data representing them. * Its a global in the manner that it reads its own * header information. */ public class GlobalColorChunk extends ColorChunk { /** * Gets the color type for this chunk. * @param chopper with the information the * chunk may use to determine color type * @return the color type for the chunk. */ protected int getColorType(ChunkChopper chopper) { int type = chopper.getUnsignedShort(); int colorLength = chopper.getUnsignedInt(); return type; } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/HierarchyInfoChunk.java 0000664 0000000 0000000 00000003242 11303765311 0032357 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; /** * A HierarchyInfoChunk stores information about * where an object belong in a hierarchy of object that * have animations which may or may not be related. * Each object, including dummy objects, have an identifier * used to specify them as hierarchical parents of other * objects for the purpose of key framing. * * @author Josh DeFord */ public class HierarchyInfoChunk extends Chunk { /** * Loads a word of data that describes the parent. */ public void loadData(ChunkChopper chopper) { int hierarchyIdentifier = chopper.getShort(); chopper.getKeyFramer().setID(hierarchyIdentifier); } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/KeyFramerInfoChunk.java 0000664 0000000 0000000 00000005440 11303765311 0032330 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import javax.media.j3d.Behavior; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; /** * A KeyFramerInfoChunk stores information about things * that happen to meshes: Position information, rotation * information, scale information, pivot information * and frame information. * Together with the frames chunk thes are used * display animation behaviors. * * @author Josh DeFord */ public class KeyFramerInfoChunk extends Chunk { /** * Retrieves the named object for the current key framer * inserts the rotation, position and pivot transformations for frame 0 * and assigns the coordinate system to it. * * The inverse of the local coordinate system converts from 3ds * semi-absolute coordinates (what is in the file) to local coordinates. * * Then these local coordinates are converted with matrix * that will instantiate them to absolute coordinates: * Xabs = sx a1 (Xl-Px) + sy a2 (Yl-Py) + sz a3 (Zl-Pz) + Tx * Yabs = sx b1 (Xl-Px) + sy b2 (Yl-Py) + sz b3 (Zl-Pz) + Ty * Zabs = sx c1 (Xl-Px) + sy c2 (Yl-Py) + sz c3 (Zl-Pz) + Tz * Where: * (Xabs,Yabs,Zabs) = absolute coordinate * (Px,Py,Pz) = mesh pivot (constant) * (X1,Y1,Z1) = local coordinates * * @param chopper the ChunkChopper containing the current state of the parser. */ public void initialize(ChunkChopper chopper) { String meshName = (String)chopper.getObjectName(); Behavior frameBehavior = chopper.getKeyFramer().createBehavior(meshName, chopper.getNamedTransformGroup(meshName), chopper.getNamedObject(meshName)); if(frameBehavior != null) chopper.addBehaviorNode(frameBehavior); } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/LightChunk.java 0000664 0000000 0000000 00000006007 11303765311 0030676 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import javax.media.j3d.BoundingSphere; import javax.media.j3d.PointLight; import javax.media.j3d.Transform3D; import javax.media.j3d.TransformGroup; import javax.vecmath.Color3f; import javax.vecmath.Point3d; import javax.vecmath.Vector3f; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; import com.microcrowd.loader.java3d.max3ds.ChunkMap; /** * Lights to be placed in a scene. * Only point lights and target spot lights are supported. * All the default parameters are used for lights as well. * Only position is specified. */ public class LightChunk extends Chunk { private Vector3f currentPosition; /** * This is called by the chunk chopper before any of the chunk's * subchunks are loaded. Any data loaded that may need to be * used later by superchunks should be stored in * the chunk chopper via {@link ChunkChopper#pushData} * * @param chopper used to store the position of the light. */ public void loadData(ChunkChopper chopper) { currentPosition = chopper.getVector(); TransformGroup group = chopper.getGroup(); Transform3D transform = new Transform3D(); group.getTransform(transform); transform.setTranslation(currentPosition); group.setTransform(transform); chopper.pushData(chopper.getID(), currentPosition); } /** * Gets the data put into the chopper by the subchunks * and creates a light, adding it to the scene as a named object. * @param chopper the ChunkChopper containing sub chunk data. */ public void initialize(ChunkChopper chopper) { Color3f color = (Color3f)chopper.popData(ChunkMap.COLOR); PointLight light = (PointLight)chopper.popData(ChunkMap.SPOTLIGHT); if(light == null) { light = new PointLight(); chopper.addLightNode(light); } light.setColor(color); light.setInfluencingBounds(new BoundingSphere(new Point3d(0,0,0), 3000)); chopper.getGroup().addChild(light); } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/MaterialChunk.java 0000664 0000000 0000000 00000010320 11303765311 0031356 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import javax.media.j3d.Appearance; import javax.media.j3d.Material; import javax.media.j3d.PolygonAttributes; import javax.media.j3d.Texture; import javax.media.j3d.TransparencyAttributes; import javax.vecmath.Color3f; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; import com.microcrowd.loader.java3d.max3ds.ChunkMap; /** * Loads material chunks with ambient, diffuse and specular colors, * shininess, transparency, two sidedness and texture. */ public class MaterialChunk extends Chunk { //public static final Integer SELF_ILLUMINATED = new Integer((short)0xA084); /** * This will set the ambient, diffuse and specular * colors as well as the textures, two sidedness * and transparency of the material. * * @param chopper the chopper containing the data * needed to set the attributes. */ public void initialize(ChunkChopper chopper) { Appearance appearance = new Appearance(); Material material = new Material(); Color3f ambientColor = (Color3f)chopper.popData(ChunkMap.AMBIENT_COLOR); if (ambientColor != null) { material.setAmbientColor(ambientColor); } Color3f color = (Color3f)chopper.popData(ChunkMap.DIFFUSE_COLOR); if (color != null) { material.setDiffuseColor(color); } color = (Color3f)chopper.popData(ChunkMap.SPECULAR_COLOR); if (color != null) { material.setSpecularColor(color); } Texture texture = (Texture)chopper.popData(ChunkMap.TEXTURE); if(texture != null) { appearance.setTexture(texture); } Boolean twoSided = (Boolean)chopper.popData(ChunkMap.TWO_SIDED); if (twoSided != null) //Just being there is equivalent to a boolean true. { PolygonAttributes polyAttributes = appearance.getPolygonAttributes(); if(polyAttributes == null) { polyAttributes = new PolygonAttributes(); } polyAttributes.setCullFace(PolygonAttributes.CULL_NONE); appearance.setPolygonAttributes(polyAttributes); } Float transparency = (Float)chopper.popData(ChunkMap.TRANSPARENCY); if (transparency != null) { if (transparency.floatValue() > 0.01f) { TransparencyAttributes transparencyAttributes = new TransparencyAttributes(TransparencyAttributes.FASTEST, transparency.floatValue()); appearance.setTransparencyAttributes(transparencyAttributes); } } String name = (String)chopper.popData(ChunkMap.MATERIAL_NAME); Float shininess = (Float)chopper.popData(ChunkMap.SHININESS); if (shininess != null) { float shine = shininess.floatValue() * 1024f; material.setShininess(shine); } /* Boolean illuminated = (Boolean)chopper.popData(SELF_ILLUMINATED); if(illuminated != null && illuminated.booleanValue() == true) { material.setEmissiveColor(ambientColor); } */ appearance.setMaterial(material); chopper.setNamedObject(name, appearance); } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/NamedObjectChunk.java 0000664 0000000 0000000 00000003501 11303765311 0031776 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import javax.media.j3d.TransformGroup; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; /** * Loads information about a named object: Cameras, meshes and lights */ public class NamedObjectChunk extends Chunk { /** * Adds a TransformGroup the the chopper's branch * group to which meshes will be added. * * @param chopper The chopper containing the state of parsing. */ public void loadData(ChunkChopper chopper) { final String name = chopper.getString(); TransformGroup transformGroup = new TransformGroup(); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); transformGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING); chopper.addObject(name, transformGroup); } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/PercentageChunk.java 0000664 0000000 0000000 00000004172 11303765311 0031705 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; /** * Loads percentage values from binary data representing them. */ public class PercentageChunk extends Chunk { /** Represents an int percentage */ public static final int INT = 0x30; /** Represents a float percentage */ public static final int FLOAT = 0x31; private float percentage; /** * Gets tye type of percentage, reads it * and sets the value on the chopper using * the id of the current chunk as the key. * */ public void loadData(ChunkChopper chopper) { int percentageType = chopper.getUnsignedShort(); int percentageLength = chopper.getUnsignedInt(); if (percentageType == INT) { percentage = (chopper.getUnsignedShort()) / 100f; chopper.pushData(chopper.getID(), new Float(percentage)); } else if (percentageType == FLOAT) { percentage = chopper.getFloat() / 100f; chopper.pushData(chopper.getID(), new Float(percentage)); } else { throw new IllegalArgumentException("Only float and int percentages are enabled."); } } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/PivotChunk.java 0000664 0000000 0000000 00000003116 11303765311 0030726 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import javax.vecmath.Point3f; import javax.vecmath.Vector3f; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; /** * Loads the pivot for a mesh. * {@see KeyFramerInfoChunk} for more information about using * animations from a 3ds file */ public class PivotChunk extends Chunk { /** * Gets the pivot and associates it with the current mes. * @param chopper the ChunkChopper containing the state of the parser. */ public void loadData(ChunkChopper chopper) { Vector3f pivot = new Vector3f((Point3f)chopper.getPoint()); chopper.getKeyFramer().setPivot(pivot); } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/PositionChunk.java 0000664 0000000 0000000 00000004324 11303765311 0031433 0 ustar 00root root 0000000 0000000 /** * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import java.util.ArrayList; import javax.vecmath.Point3f; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; /** * Loads the position of a mesh as defined in the 3ds file. * This position may need to be converted to another coordinate * system by KeyFramerInfoChunk. * * {@see KeyFramerInfoChunk} for more information about using * animations from a 3ds file */ public class PositionChunk extends Chunk { /** * Loads the position for a shape and KeyFramerInfoChunk * * @param chopper the ChunkChopper containing the state of the parser. */ public void loadData(ChunkChopper chopper) { int flags = chopper.getUnsignedShort(); chopper.getLong(); int numKeys = chopper.getUnsignedInt(); ArrayList pointList = new ArrayList(); for(int i =0; i < numKeys; i++) { long keyNumber = chopper.getUnsignedInt(); int accelerationData = chopper.getUnsignedShort(); Point3f position = chopper.getPoint(); if(i==0) { chopper.getKeyFramer().setPosition(position); } pointList.add(position); } chopper.getKeyFramer().setPositionKeys(pointList); } } java3ds-fileloader-1.2+dfsg/com/microcrowd/loader/java3d/max3ds/chunks/RotationChunk.java 0000664 0000000 0000000 00000010673 11303765311 0031432 0 ustar 00root root 0000000 0000000 /*8 * Make a donation http://sourceforge.net/donate/index.php?group_id=98797 * Microcrowd.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact Josh DeFord jdeford@microcrowd.com */ package com.microcrowd.loader.java3d.max3ds.chunks; import java.util.ArrayList; import java.util.List; import javax.vecmath.Quat4f; import javax.vecmath.Vector3f; import com.microcrowd.loader.java3d.max3ds.ChunkChopper; /** * Extracts the rotation information from the 3ds file. * Rotations occur about a pivot at a position within * a local coordinate system. The rotation information * is provided to the KeyFramerInfoChunk which then converts * it to a global coordinate system and applies animation * information. * {@see KeyFramerInfoChunk} for more information about using * animations from a 3ds file */ public class RotationChunk extends Chunk { /** * String that will be used as a data object in the transform that the * RotationInterpolator will be a child of so it may be look up later. **/ public static String ROTATION_TAG = "ROTATION_INTERPOLATOR"; /** * Loads the quaternion for a rotation of a shape * and notifies mesh info chunk. * * @param chopper the ChunkChopper containing the state of the parser. */ public void loadData(ChunkChopper chopper) { int flags = chopper.getUnsignedShort(); chopper.getLong(); int numKeys = chopper.getUnsignedInt(); Quat4f previousQuat = null; List quats = new ArrayList(); for(int i =0; i < numKeys; i++) { long frameNumber = chopper.getUnsignedInt();//Part of the track header int accelerationData = chopper.getUnsignedShort();//Part of the track header getSplineTerms(accelerationData, chopper);//Part of the track header float angle = chopper.getFloat(); Vector3f vector = chopper.getVector(); Quat4f quat = getQuaternion(vector, angle); if(previousQuat != null) { quat.mul(previousQuat, quat); } previousQuat = quat; quats.add(quat); if(i==0) { chopper.getKeyFramer().setRotation(quat); } } chopper.getKeyFramer().setOrientationKeys(quats); } /** * This only reads the spline data and should be part * of the track header when it gets invented. * @param chopper an integer representing the bits that * determine which of the five possible spline terms are present in the * data and should be read. * @param chopper what to read the data from * The possible spline values are are *