com.threed.jpct
Class Loader

java.lang.Object
  extended by com.threed.jpct.Loader

public final class Loader
extends java.lang.Object

Loader offers some static methods for loading files. Various methods for loading objects and animations as well as some very basic methods for loading text-files can be found here.


Method Summary
static void clearCache()
          Empties the file-cache.
static Object3D[] load3DS(java.io.InputStream stream, float scale)
          Loads a file in 3DS-format into an array of objects. 3DS is a 3D-Studio format supported by many converter tools.
static Object3D loadASC(java.io.InputStream stream, float scale, boolean swap)
          Loads a file in ASC-format into an object.
static Object3D loadMD2(java.io.InputStream stream, float newScale)
          Loads an object out of a file in MD2-format (Quake2 model format).
static Object3D[] loadOBJ(java.io.InputStream objStream, java.io.InputStream mtlStream, float scale)
          Loads a file in OBJ-format into an array of objects.
static Object3D loadSerializedObject(java.io.InputStream is)
          Loads an object in serialized format.
static Object3D[] loadSerializedObjectArray(java.io.InputStream is)
          Loads an object-array in serialized format.
static java.lang.String loadTextFile(java.io.InputStream stream)
          Loads a text-file into a String.
static java.lang.String[] readTextureNames3DS(java.io.InputStream stream)
          Reads the texture names from a 3DS-file.
static void setVertexOptimization(boolean enabled)
          Enables(default)/Disables vertex optimizations for the Loader.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setVertexOptimization

public static void setVertexOptimization(boolean enabled)
Enables(default)/Disables vertex optimizations for the Loader. Using this, vertices can be combined to one if they cover exactly the same point in space. This reduces vertex count. If you disable this, be sure to have a reason...
This setting affects ASC, 3DS and OBJ files only. If used for loading 3DS or OBJ files, the vertex sharing information from the files will be used instead (Could be helpful to use these files as keyframes).

Parameters:
enabled - optimize vertex usage

loadTextFile

public static java.lang.String loadTextFile(java.io.InputStream stream)
Loads a text-file into a String. Used internally by jPCT and maybe useful for other applications. This method is for accessing files from an InputStream.

Parameters:
stream - the InputStream
Returns:
the file content

loadSerializedObject

public static Object3D loadSerializedObject(java.io.InputStream is)
Loads an object in serialized format. This format can't be created by jPCT-AE but by using the desktop version of jPCT by using the DeSerializer.
This is the fastest and least memory intense way to load an object in jPCT-AE.

Parameters:
is - the inputstream
Returns:
the object

loadSerializedObjectArray

public static Object3D[] loadSerializedObjectArray(java.io.InputStream is)
Loads an object-array in serialized format. This format can't be created by jPCT-AE but by using the desktop version of jPCT by using the DeSerializer.
This is the fastest and least memory intense way to load objects in jPCT-AE.

Parameters:
is - the inputstream
Returns:
the objects

loadMD2

public static Object3D loadMD2(java.io.InputStream stream,
                               float newScale)
Loads an object out of a file in MD2-format (Quake2 model format). The object is loaded including all keyframes so that the returned object already contains the animation for this object. The texture indicated in the file is ignored (the texture coordinates are of course not). All meshes of the animation will be stored in compressed format. This method is for accessing files from an InputStream.

Parameters:
stream - the InputStream
newScale - a scaling parameter, 1 means no changes to the mesh
Returns:
the object including all animation data
See Also:
Mesh.compress()

load3DS

public static Object3D[] load3DS(java.io.InputStream stream,
                                 float scale)
Loads a file in 3DS-format into an array of objects. 3DS is a 3D-Studio format supported by many converter tools. A 3DS-file can contain many different objects. Each object will be named like its 3DS-name (the name this object has in 3D-Studio) plus a suffix "_jPCT" plus the object's internal ID.
The loader will read the textures' names out of the 3DS-file and will add dummy textures with these names to the texture-manager (If the name is already in use, no new dummy texture will be added). So one may load some textures and add them to the manager with the appropiate names before loading the 3DS-file or replace the ones generated by the loader after loading is finished. If the materials used in the file are not using textures, small, single colored textures will be generated that represent the diffuse colors of the materials. This method is for accessing files from an InputStream.

Parameters:
stream - the InputStream
scale - a scaling parameter to scale the object right after loading. Should be set to 1 to avoid rescaling
Returns:
the objects from the file (i.e. the complete 3DS-scene)

readTextureNames3DS

public static java.lang.String[] readTextureNames3DS(java.io.InputStream stream)
Reads the texture names from a 3DS-file.

Parameters:
stream - the input stream for the file
Returns:
String[] the texture names

loadASC

public static Object3D loadASC(java.io.InputStream stream,
                               float scale,
                               boolean swap)
Loads a file in ASC-format into an object. ASC is an ASCII-based 3D-Studio format supported by many converter tools. This method is for accessing files from an InputStream.

Parameters:
stream - the InputStream
scale - a scaling parameter to scale the object right after loading. Should be set to 1 to avoid rescaling
swap - if set to true, y and z coordinates of the object will be swaped. This could be helpful for correct backface culling on some Object3Ds.
Returns:
the object

loadOBJ

public static Object3D[] loadOBJ(java.io.InputStream objStream,
                                 java.io.InputStream mtlStream,
                                 float scale)
Loads a file in OBJ-format into an array of objects. OBJ is Wavefront's Advanced Visualizer format supported by many converter tools. A OBJ-file can contain many different objects/groups. Each object will be named like its OBJ-name (the name this object has in the file) plus a suffix "_jPCT" plus the object's internal ID. This loader loads polygonal information only (i.e. no splines and similar things) and supports polygons with up to 4 vertices. Everything higher will be loaded with a warning and most likely not displayed correctly.
The loader will read the textures' names out of the OBJ-file and will add dummy textures with these names to the texture-manager (If the name is already in use, no new dummy texture will be added). So one may load some textures and add them to the manager with the appropiate names before loading the OBJ-file or replace the ones generated by the loader after loading is finished. If the materials used in the file are not using textures, small, single colored textures will be generated that represent the diffuse colors of the materials. This method is for accessing files from an InputStream.

Parameters:
objStream - the InputStream of the actual OBJ-file
mtlStream - the InputStream of the material file. May be null.
scale - a scaling parameter to scale the object right after loading. Should be set to 1 to avoid rescaling
Returns:
the objects/groups from the file (i.e. the complete polygonal content)

clearCache

public static void clearCache()
Empties the file-cache. Useful to free some memory after loading has definitly finished.