/*
* See COPYING in top-level directory.
*/
package com.monkygames.wo.io;
// === java imports === //
import com.jme3.asset.AssetManager;
//import java.util.logging.Level;
//import java.util.logging.Logger;
// === jme imports === //
import com.jme3.asset.DesktopAssetManager;
import com.jme3.bounding.BoundingSphere;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.material.Material;
// === wo imports === //
import com.jme3.system.JmeSystem;
import com.monkygames.wo.avatar.*;
import com.monkygames.wo.utils.BaseTable;
/**
* Handles loading an Avatar into 3D.
* @version 1.0
*/
public class Avatar3DLoader{
/**
* Used for looking up 3D components for the model.
**/
private BaseTable baseTable;
private AssetManager assetManager;
// ============= Constructors ============== //
public Avatar3DLoader(){
baseTable = new BaseTable(this);
assetManager = JmeSystem.newAssetManager(Thread.currentThread().getContextClassLoader().getResource("com/jme3/asset/Desktop.cfg"));
}
// ============= Public Methods ============== //
public Model loadModel(Avatar avatar){
// TEST, just load
Model model = new Model();
Node node = null;
// load the body
Node body = baseTable.loadBody(avatar.skin.color,avatar.shirt.color);
Node head = baseTable.loadHead(avatar.head.type,avatar.skin.color);
baseTable.loadEyes(avatar.eye,head);
if(head != null && body != null){
model.load(head,body);
}
return model;
}
/**
* Handles loading a single node from file.
* @param obj the path to the object.
**/
public Node loadNode(String obj){
Node node = new Node();
try{
Spatial spatial = assetManager.loadModel(obj);
//Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
//spatial.setMaterial(mat);
node.attachChild(spatial);
node.setModelBound(new BoundingSphere());
node.updateModelBound();
} catch (Exception e) {
e.printStackTrace();
//logger.logp(Level.SEVERE, this.getClass().toString(),"loadNode()", "Exception", e);
node = null;
}
return node;
}
// ============= Protected Methods ============== //
// ============= Private Methods ============== //
// ============= Implemented Methods ============== //
// ============= Extended Methods ============== //
// ============= Internal Classes ============== //
// ============= Static Methods ============== //
}
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* End:
*
* vim: ts=8 sts=4 sw=4 noexpandtab
*/