* Creates the piece node with its transform group and add it to the piece branch.
*/
private void createPieceOfFurnitureNode(final HomePieceOfFurniture piece,
final boolean ignoreDrawingMode,
final boolean waitModelAndTextureLoadingEnd) {
final TransformGroup pieceTransformGroup = new TransformGroup();
// Allow the change of the transformation that sets piece size and position
pieceTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
pieceTransformGroup.setCapability(Group.ALLOW_CHILDREN_READ);
pieceTransformGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
pieceTransformGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
addChild(pieceTransformGroup);
// While loading model use a temporary node that displays a white box
final BranchGroup waitBranch = new BranchGroup();
waitBranch.setCapability(BranchGroup.ALLOW_DETACH);
waitBranch.addChild(getModelBox(Color.WHITE));
// Allow appearance change on all children
setModelCapabilities(waitBranch);
pieceTransformGroup.addChild(waitBranch);
// Set piece model initial location, orientation and size
updatePieceOfFurnitureTransform();
// Load piece real 3D model
Content model = piece.getModel();
ModelManager.getInstance().loadModel(model, waitModelAndTextureLoadingEnd,
new ModelManager.ModelObserver() {
public void modelUpdated(BranchGroup modelRoot) {
float [][] modelRotation = piece.getModelRotation();
// Add piece model scene to a normalized transform group
TransformGroup modelTransformGroup =
ModelManager.getInstance().getNormalizedTransformGroup(modelRoot, modelRotation, 1);
updatePieceOfFurnitureModelNode(modelRoot, modelTransformGroup, ignoreDrawingMode, waitModelAndTextureLoadingEnd);
}
public void modelError(Exception ex) {
// In case of problem use a default red box
updatePieceOfFurnitureModelNode(getModelBox(Color.RED), new TransformGroup(), ignoreDrawingMode, waitModelAndTextureLoadingEnd);
}
});
}