public DeployedModel deployToModule(File moduleRootDir, ImportedModel importedModel) throws IOException {
try {
String modelName = getFilename(importedModel.getOriginalURL().toURI().getPath());
HashMap<String, String> textureDeploymentMapping = new HashMap();
DeployedModel deployedModel = new DeployedModel(importedModel.getOriginalURL(), this);
LoaderData data = new LoaderData();
data.setDeployedTextures(textureDeploymentMapping);
data.setModelLoaderClassname(this.getClass().getName());
deployedModel.setLoaderData(data);
// TODO replace getName with getModuleName(moduleRootDir)
String moduleName = moduleRootDir.getName();
String targetDirName = moduleRootDir.getAbsolutePath()+File.separator+"art"+ File.separator + modelName;
File targetDir = new File(targetDirName);
targetDir.mkdirs();
// Must deploy textures before models so we have the deployment url mapping
deployTextures(targetDir, textureDeploymentMapping, importedModel);
ModelCellServerState cellSetup = new ModelCellServerState();
ModelCellComponentServerState setup = new ModelCellComponentServerState();
cellSetup.addComponentServerState(setup);
cellSetup.setName(importedModel.getWonderlandName());
BoundingVolume modelBounds = importedModel.getModelBG().getWorldBound();
float scale = scaleBounds(modelBounds);
modelBounds = modelBounds.transform(new Quaternion(), Vector3f.ZERO,
new Vector3f(scale, scale, scale));
cellSetup.setBoundingVolumeHint(new BoundingVolumeHint(false, modelBounds));
deployedModel.setModelBounds(modelBounds);
Vector3f offset = importedModel.getRootBG().getLocalTranslation();
PositionComponentServerState position = new PositionComponentServerState();
Vector3f boundsCenter = modelBounds.getCenter();
offset.subtractLocal(boundsCenter);
deployedModel.setModelTranslation(offset);
deployedModel.setModelRotation(importedModel.getModelBG().getLocalRotation());
deployedModel.setModelScale(importedModel.getModelBG().getLocalScale().multLocal(scale));
// System.err.println("BOUNDS CENTER "+boundsCenter);
// System.err.println("OFfset "+offset);
// System.err.println("Cell origin "+boundsCenter);
position.setTranslation(boundsCenter);
// The cell bounds already have the rotation and scale applied, so these
// values must not go in the Cell transform. Instead they go in the
// deployedModel so that the model is correctly oriented and thus
// matches the bounds in the cell.
// Center the worldBounds on the cell (ie 0,0,0)
BoundingVolume worldBounds = modelBounds.clone(null);
worldBounds.setCenter(new Vector3f(0,0,0));
position.setBounds(worldBounds);
cellSetup.addComponentServerState(position);
deployedModel.addCellServerState(cellSetup);
deployModels(targetDir,
moduleName,
deployedModel,
importedModel,