private void handleAvatarRendererChangeRequest(AvatarRendererChangeRequestEvent event) { switch (event.getQuality()) { case High: // Fetch the avatar configuration information and change to the // current avatar AvatarConfigComponent comp = cell.getComponent(AvatarConfigComponent.class); AvatarConfigInfo avatarConfigInfo = comp.getAvatarConfigInfo(); changeAvatar(loadAvatar(avatarConfigInfo)); break; case Medium: changeAvatar(loadAvatar(null)); break; case Low: changeAvatar(loadAvatar(null)); break; } }
/** {@inheritDoc} */ @Override public void setStatus(CellStatus status, boolean increasing) { super.setStatus(status, increasing); WlAvatarCharacter pendingAvatar = null; logger.info("AVATAR RENDERER STATUS " + status + " DIR " + increasing); // If we are increasing to the ACTIVE state, then turn everything on. // Add the listeners to the avatar Cell and set the avatar character if (status == CellStatus.ACTIVE && increasing == true) { BoundsDebugger.getInstance().add(this); if (cellMoveListener != null) { // mc should not be null, but sometimes it seems to be MovableComponent mc = cell.getComponent(MovableComponent.class); if (mc == null) { logger.severe("NULL MovableComponent in avatar " + ((AvatarCell) cell).getName()); } else { mc.removeServerCellMoveListener(cellMoveListener); } cellMoveListener = null; } // If we have not creating the avatar yet, then look for the config // component on the cell. Fetch the avatar configuration. if (avatarCharacter == null) { AvatarConfigComponent configComp = cell.getComponent(AvatarConfigComponent.class); AvatarConfigInfo avatarConfigInfo = null; if (configComp != null) { avatarConfigInfo = configComp.getAvatarConfigInfo(); } logger.info("LOADING AVATAR FOR " + avatarConfigInfo); pendingAvatar = loadAvatar(avatarConfigInfo); } else { // Otherwise remove the existing avatar from the world ClientContextJME.getWorldManager().removeEntity(avatarCharacter); pendingAvatar = null; } // Go ahead and change the avatar logger.info("CHANGING AVATAR IN SET STATUS"); changeAvatar(pendingAvatar); if (cellMoveListener == null) { cellMoveListener = new CellMoveListener() { public void cellMoved(CellTransform transform, CellMoveSource source) { if (source == CellMoveSource.REMOTE) { // System.err.println("REMOTE MOVE // "+transform.getTranslation(null)); if (avatarCharacter != null) { if (avatarCharacter.getModelInst() == null) { // Extra debug check logger.severe("MODEL INST IS NULL !"); Thread.dumpStack(); return; } if (delayedMove != null) { delayedMove = null; logger.fine( cell.getCellID() + ": remove delayed move for: " + transform.toString()); } avatarCharacter .getModelInst() .setTransform( new PTransform( transform.getRotation(null), transform.getTranslation(null), new Vector3f(1, 1, 1))); } else { logger.fine(cell.getCellID() + ": delaying move: " + transform.toString()); // we tried to move before loading the avatar. // record the new position to apply when we // actually load delayedMove = transform; } } } }; } cell.getComponent(MovableComponent.class).addServerCellMoveListener(cellMoveListener); avatarUIEventListener = new AvatarUIEventListener(); ClientContext.getInputManager().addGlobalEventListener(avatarUIEventListener); collisionChangeRequestListener = new CollisionChangeRequestListener(); ClientContext.getInputManager().addGlobalEventListener(collisionChangeRequestListener); } else if (status == CellStatus.DISK && !increasing) { BoundsDebugger.getInstance().remove(this); ClientContext.getInputManager().removeGlobalEventListener(avatarUIEventListener); ClientContext.getInputManager().removeGlobalEventListener(collisionChangeRequestListener); cell.getComponent(MovableComponent.class).removeServerCellMoveListener(cellMoveListener); avatarUIEventListener = null; cellMoveListener = null; collisionChangeRequestListener = null; } }
public AvatarImiJME(Cell cell) { super(cell); assert (cell != null); final Cell c = cell; // Listen for avatar configuration changes. AvatarConfigComponent comp = cell.getComponent(AvatarConfigComponent.class); comp.addAvatarConfigChangeListener(new AvatarChangeListener()); // XXX NPC HACK XXX if (cell instanceof AvatarCell) username = ((AvatarCell) cell).getIdentity().getUsername(); else username = "******"; // HACK ! characterMotionListener = new CharacterMotionListener() { Vector3f prevTrans; PMatrix prevRot; float prevHeight; boolean prevCollision; public void transformUpdate(Vector3f translation, PMatrix rotation) { if (logger.isLoggable(Level.FINEST)) { logger.finest( "Transform update: translation: prev: " + prevTrans + " cur: " + translation + " rotation: prev: " + prevRot + " cur: " + rotation); } float height = avatarCharacter.getController().getHeight(); boolean collision = avatarCharacter.getController().isColliding(); if (prevTrans == null || !Math3DUtils.epsilonEquals(prevTrans, translation, 0.001f) || prevRot == null || !prevRot.epsilonEquals(rotation, 0.001f) || !Math3DUtils.epsilonEquals(prevHeight, height, 0.001f) || prevCollision != collision) { MovableAvatarComponent mac = ((MovableAvatarComponent) c.getComponent(MovableComponent.class)); mac.localMoveRequest( new CellTransform(rotation.getRotation(), translation), height, collision); prevTrans = translation.clone(); prevRot = new PMatrix(rotation); prevHeight = height; prevCollision = collision; } }; }; // This info will be sent to the other clients to animate the avatar gameContextListener = new GameContextListener() { public void trigger( boolean pressed, int trigger, Vector3f translation, Quaternion rotation) { synchronized (this) { currentTrigger = trigger; currentPressed = pressed; } String animationName = null; // OWL issue #237 - regardless of the current state, send the // animation that is currently set in CycleActionState. This // is consistent with the behavior of // WlAvatarContext.setMiscAnimation() used in the trigger() // method below CycleActionState cas = (CycleActionState) avatarCharacter.getContext().getState(CycleActionState.class); if (cas != null) { animationName = cas.getAnimationName(); } float height = avatarCharacter.getController().getHeight(); boolean collision = avatarCharacter.getController().isColliding(); if (c.getComponent(MovableComponent.class) == null) { logger.warning("!!!! NULL MovableComponent"); } else { MovableAvatarComponent mac = ((MovableAvatarComponent) c.getComponent(MovableComponent.class)); mac.localMoveRequest( new CellTransform(rotation, translation), trigger, pressed, animationName, height, collision, null); } } }; }