// Turn on an indication that the avatar is being loaded
LoadingInfo.startedLoading(cell.getCellID(), newAvatar.getName());
// Fetch the name tag node. There should be only one of these in the
// system.
Node nameTagNode = getNameTagNode();
// If there is an existing avatar character, then remove it, but store
// away its position. Remove the name tag, turn off input and destroy
// the avatar character.
PMatrix currentLocation = null;
if (avatarCharacter != null) {
currentLocation = avatarCharacter.getModelInst().getTransform().getWorldMatrix(true);
rootEntity.removeEntity(avatarCharacter);
avatarCharacter.getJScene().getExternalKidsRoot().detachChild(nameTagNode);
selectForInput(false);
avatarCharacter.destroy();
flg=1;
}
// Set the new avatar character. If there is none (when would that happen?)
// then just return.
avatarCharacter = newAvatar;
if (newAvatar == null) {
return;
}
// Add all of the default components to the renderer, but remove the
// collision component, since we use our own collision graph
RenderComponent rc = (RenderComponent) avatarCharacter.getComponent(RenderComponent.class);
addDefaultComponents(avatarCharacter, rc.getSceneRoot());
avatarCharacter.removeComponent(CollisionComponent.class);
// Set the initial location of the avatar if there is one
if (currentLocation != null && avatarCharacter.getModelInst() != null) {
logger.fine(cell.getCellID() + " Using current location: " + currentLocation);
avatarCharacter.getModelInst().setTransform(new PTransform(currentLocation));
} else if (delayedMove != null && avatarCharacter.getModelInst() != null) {
// there was no previous avatar, but there was a move that
// happened while the avatar was null. Apply the move now
logger.fine(cell.getCellID() + " using delayed move: " + delayedMove.toString());
PTransform trans = new PTransform(delayedMove.getRotation(null),
delayedMove.getTranslation(null),
new Vector3f(1, 1, 1));
avatarCharacter.getModelInst().setTransform(trans);
}
// Attach the name tag to the new avatar and add the avatar entity to
// the cell renderer root entity and turn on input.
Node externalRoot = avatarCharacter.getJScene().getExternalKidsRoot();
if (nameTagNode!=null) {
externalRoot.attachChild(nameTagNode);
externalRoot.setModelBound(new BoundingSphere());
externalRoot.updateModelBound();
externalRoot.updateGeometricState(0, true);
}
rootEntity.addEntity(avatarCharacter);
// Turn on input handle for the renderer, if we wish. Check for AvatarCell
// to allow NPC's to work