public void selectForInput(boolean selected) { if (selectedForInput == selected) return; if (avatarCharacter == null) { logger.warning("selectForInput called with null avatarCharacter"); Thread.dumpStack(); return; } logger.info("selectedForInput " + selected); selectedForInput = selected; if (avatarCharacter != null) { WorldManager wm = ClientContextJME.getWorldManager(); ((WlAvatarContext) avatarCharacter.getContext()).getBehaviorManager().setEnable(false); if (controlScheme == null && selectedForInput) { controlScheme = new DefaultCharacterControls(ClientContextJME.getWorldManager()); ((AvatarControls) wm.getUserData(AvatarControls.class)).setDefault(controlScheme); } setCollisionController(avatarCharacter); if (selectedForInput) { // Listen for avatar movement and update the cell avatarCharacter .getContext() .getController() .addCharacterMotionListener(characterMotionListener); // Listen for game context changes avatarCharacter.getContext().addGameContextListener(gameContextListener); avatarCharacter.selectForInput(); controlScheme.addCharacterToTeam(avatarCharacter); controlScheme.setCharacter(avatarCharacter); // Chain the camera processor to the avatar motion processor for // smooth animation. For animated avatars we use CharacterAnimationProcessor for the simple // avatar CharacterProcessor ProcessorCollectionComponent pcc = avatarCharacter.getComponent(ProcessorCollectionComponent.class); ProcessorComponent characterProcessor = null; ProcessorComponent characterAnimationProcessor = null; for (ProcessorComponent pc : pcc.getProcessors()) { if (pc instanceof CharacterProcessor) characterProcessor = pc; else if (pc instanceof CharacterAnimationProcessor) { characterAnimationProcessor = pc; break; } } cameraChainedProcessor = null; if (characterAnimationProcessor != null) { cameraChainedProcessor = characterAnimationProcessor; } else if (characterProcessor != null) cameraChainedProcessor = characterProcessor; if (cameraChainedProcessor != null) { cameraChainedProcessor.addToChain(ViewManager.getViewManager().getCameraProcessor()); cameraChainedProcessor.setRunInRenderer(true); } // Disable culling for local avatar, fix for issue 799 avatarCharacter.getJScene().setCullHint(CullHint.Never); } else { avatarCharacter .getContext() .getController() .removeCharacterMotionListener(characterMotionListener); avatarCharacter.getContext().removeGameContextListener(gameContextListener); if (controlScheme != null) { controlScheme.clearCharacterTeam(); } if (cameraChainedProcessor != null) { cameraChainedProcessor.removeFromChain(ViewManager.getViewManager().getCameraProcessor()); cameraChainedProcessor = null; } // Reenable culling for local avatar, fix for issue 799 avatarCharacter.getJScene().setCullHint(CullHint.Dynamic); } } else { logger.severe("The avatar was null during enableInputListeners()."); } }