Renderer
Class ModelLibrary

java.lang.Object
  |
  +--Renderer.ModelLibrary

public class ModelLibrary
extends java.lang.Object

Maintains a library of models that are available to the system. It indexes a set of Wavefront .obj files and optionally allows each to be normalized to a consistent form. A requested model is returned in the form of a ModelTemplate, which defines a generic template and must be cloned to create an instance that can be configured independently.

Each line of the index file is defined as A B [C] [D] [E] [F] [G] [/S], where

   A - unique toy name
   B - model filename with extension
   C - attitude adjustment:   {A:pitch,roll,yaw}
   D - dimensions adjustment: {D:height,width,depth}
   E - position adjustment:   {P:x,y,z}
   F - scale adjustment:      {S:scale}
   G - color                  {C:red,green,blue}
   H - transparency           {T:percent}
  /S - suppress warning messages for missing textures
 
Fields C, D, E, F, G, and H are optional, may appear in any order, and accept negative values if appropriate. No spaces are permitted within the braces. Switch /S is also optional and should appear last.

Use the optional parameters to adjust the model so that it is facing upright and toward the screen, is scaled appropriately, is centered when positioned at x=z=0, and is located on the ground at y=0.

Version:
Created 17 February 2003
Author:
Dan Tappan
See Also:
ModelTemplate

Field Summary
private  char ADJUSTMENT_CODE_ATTITUDE
           
private  char ADJUSTMENT_CODE_COLOR
           
private  char ADJUSTMENT_CODE_DIMENSIONS
           
private  char ADJUSTMENT_CODE_POSITION
           
private  char ADJUSTMENT_CODE_SCALE
           
private  char ADJUSTMENT_CODE_TRANSPARENCY
           
private  java.lang.String FIELD_DELIMITER
           
private  java.lang.String INDEX_FILENAME
           
private  boolean IS_LOGGED
           
private  java.lang.String LEXEME_COMMENT
           
private  java.lang.String LEXEME_SET_ELEMENT_DELIMITER
           
private  java.util.Hashtable m_models
           
private  java.lang.String MODEL_FORMAT_3DS
           
private  java.lang.String MODEL_FORMAT_OBJ
           
private  boolean SUPPRESS_NORMALIZATION
           
private  java.lang.String SWITCH_SUPPRESS_TEXTURE_WARNINGS
           
private  java.lang.String WARNING_FILENAME
           
 
Constructor Summary
ModelLibrary()
          Creates a new ModelLibrary with all known models available.
ModelLibrary(java.util.ArrayList allocated_models)
          Creates a new ModelLibrary with only the requested models available.
 
Method Summary
private  void configureModel(ModelTemplate model_template, java.util.Enumeration elements, java.lang.String toy_identifier, boolean is_wireframe, float transparency, javax.vecmath.Color3f override_color)
          Configures a model as specified by recursively processing each branch of its Java3D node structure.
 ModelTemplate getModel(java.lang.String model_name, java.lang.String toy_identifier, boolean is_wireframe, float transparency, javax.vecmath.Color3f override_color)
          Returns a derived instance of a model that has been configured as specified.
private  void loadModelLibrary(java.util.ArrayList allocated_models)
          Loads all or part of the model library.
 java.lang.String toString()
          Returns a string representation of this object.
private  void writeStatus(java.lang.String message)
          Conditionally writes a status message to stdout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SUPPRESS_NORMALIZATION

private final boolean SUPPRESS_NORMALIZATION
See Also:
Constant Field Values

INDEX_FILENAME

private final java.lang.String INDEX_FILENAME
See Also:
Constant Field Values

WARNING_FILENAME

private final java.lang.String WARNING_FILENAME
See Also:
Constant Field Values

MODEL_FORMAT_OBJ

private final java.lang.String MODEL_FORMAT_OBJ
See Also:
Constant Field Values

MODEL_FORMAT_3DS

private final java.lang.String MODEL_FORMAT_3DS
See Also:
Constant Field Values

LEXEME_COMMENT

private final java.lang.String LEXEME_COMMENT
See Also:
Constant Field Values

LEXEME_SET_ELEMENT_DELIMITER

private final java.lang.String LEXEME_SET_ELEMENT_DELIMITER
See Also:
Constant Field Values

FIELD_DELIMITER

private final java.lang.String FIELD_DELIMITER
See Also:
Constant Field Values

ADJUSTMENT_CODE_ATTITUDE

private final char ADJUSTMENT_CODE_ATTITUDE
See Also:
Constant Field Values

ADJUSTMENT_CODE_DIMENSIONS

private final char ADJUSTMENT_CODE_DIMENSIONS
See Also:
Constant Field Values

ADJUSTMENT_CODE_POSITION

private final char ADJUSTMENT_CODE_POSITION
See Also:
Constant Field Values

ADJUSTMENT_CODE_SCALE

private final char ADJUSTMENT_CODE_SCALE
See Also:
Constant Field Values

ADJUSTMENT_CODE_COLOR

private final char ADJUSTMENT_CODE_COLOR
See Also:
Constant Field Values

ADJUSTMENT_CODE_TRANSPARENCY

private final char ADJUSTMENT_CODE_TRANSPARENCY
See Also:
Constant Field Values

SWITCH_SUPPRESS_TEXTURE_WARNINGS

private final java.lang.String SWITCH_SUPPRESS_TEXTURE_WARNINGS
See Also:
Constant Field Values

m_models

private java.util.Hashtable m_models

IS_LOGGED

private final boolean IS_LOGGED
See Also:
Constant Field Values
Constructor Detail

ModelLibrary

public ModelLibrary()
             throws java.lang.Exception
Creates a new ModelLibrary with all known models available. This is not recommended because the load time is very long and the memory use is excessive (usually resulting in an exception).

Throws:
java.lang.Exception - - if the library cannot be created or loaded

ModelLibrary

public ModelLibrary(java.util.ArrayList allocated_models)
             throws java.lang.Exception
Creates a new ModelLibrary with only the requested models available. Requesting a subset reduces the load time because unused models are not loaded.

Parameters:
allocated_models - - the models to load, specified by model name
Throws:
java.lang.Exception - - if the library cannot be created or loaded
Method Detail

configureModel

private void configureModel(ModelTemplate model_template,
                            java.util.Enumeration elements,
                            java.lang.String toy_identifier,
                            boolean is_wireframe,
                            float transparency,
                            javax.vecmath.Color3f override_color)
Configures a model as specified by recursively processing each branch of its Java3D node structure.

Parameters:
model_template - - the model template
elements - - the nodel elements, acquired via Node.getAllChildren()
toy_identifier - - the name of the toy that will be using this model
is_wireframe - - whether the model is rendered in wireframe
transparency - - the model transparency
override_color - - the optional color overriding the defined color of this model; otherwise null

loadModelLibrary

private void loadModelLibrary(java.util.ArrayList allocated_models)
                       throws java.lang.Exception
Loads all or part of the model library.

Side Effect: optionally pretty-prints details of load process to stdout.

Parameters:
allocated_models - - the models to load, or all if null
Throws:
java.lang.Exception - - if the load fails for any reason

getModel

public ModelTemplate getModel(java.lang.String model_name,
                              java.lang.String toy_identifier,
                              boolean is_wireframe,
                              float transparency,
                              javax.vecmath.Color3f override_color)
                       throws java.lang.Exception
Returns a derived instance of a model that has been configured as specified.

Parameters:
model_name - - the model name
toy_identifier - - the name of the toy that will be using this model
is_wireframe - - whether the model is rendered in wireframe
transparency - - the model transparency
override_color - - the optional color overriding the defined color of this model; otherwise null
Returns:
the derived instance
Throws:
java.lang.Exception - - if the model does not exist or was not requested to be available in the constructor

toString

public java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
the String representation
See Also:
Support.toPrettyString(java.lang.String)

writeStatus

private void writeStatus(java.lang.String message)
Conditionally writes a status message to stdout.

Parameters:
message - - the message, which is responsible for its own newline