2 * Copyright (c) 2003-2009 jMonkeyEngine
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 package com.jmex.model.converters;
35 import java.io.IOException;
36 import java.io.InputStream;
37 import java.io.OutputStream;
39 import com.jme.animation.SpatialTransformer;
40 import com.jme.scene.Node;
41 import com.jme.system.DisplaySystem;
42 import com.jme.system.dummy.DummySystemProvider;
43 import com.jme.util.LittleEndien;
44 import com.jme.util.export.binary.BinaryExporter;
45 import com.jmex.model.converters.maxutils.TDSFile;
48 * Started Date: Jun 26, 2004<br><br>
50 * Converts .3ds files into jME binary
52 * @author Jack Lindamood
54 public class MaxToJme extends FormatConverter {
55 private LittleEndien myIn;
57 private TDSFile chunkedTDS=null;
60 * Converts a .3ds file to .jme via command prompt
61 * @param args The array of parameters. args="file1.3ds file2.jme" will convert file1.3ds to jme and save it to file2.jme.
63 public static void main(String[] args){
64 DisplaySystem.getDisplaySystem(DummySystemProvider.DUMMY_SYSTEM_IDENTIFIER);
65 new MaxToJme().attemptFileConvert(args);
69 * Converts a .3ds file (represented by the InputStream) to jME format.
70 * @param max The .3ds file as an InputStream
71 * @param bin The place to put the jME format
72 * @throws IOException If read/write goes wrong.
74 public void convert(InputStream max,OutputStream bin) throws IOException {
75 myIn=new LittleEndien(max);
76 chunkedTDS=new TDSFile(myIn, this);
77 Node toReturn=chunkedTDS.buildScene();
80 BinaryExporter.getInstance().save(toReturn, bin);
85 * This function returns the controller of a loaded 3ds model. Will return
86 * null if a correct SpatialTransformer could not be found, or if one does not exist.
87 * @param model The model that was loaded.
88 * @return The controller for that 3ds model.
90 public static SpatialTransformer findController(Node model) {
91 if (model.getQuantity()==0 ||
92 model.getChild(0).getControllers().size()==0 ||
93 !(model.getChild(0).getController(0) instanceof SpatialTransformer))
95 return (SpatialTransformer) (model.getChild(0)).getController(0);