Example #1
0
  /**
   * Construct this component's scene graph. This consists of the following nodes.
   *
   * <p>parentEntity attachPoint -> localToCellNode -> Spatial, Spatial, etc. (subclass provided)
   */
  protected void initSceneGraph() {

    // Attach the localToCell node to the entity
    localToCellNode = new Node("Local-to-cell node for frame component " + name);
    RenderComponent rc =
        ClientContextJME.getWorldManager()
            .getRenderManager()
            .createRenderComponent(localToCellNode);
    entity.addComponent(RenderComponent.class, rc);
    rc.setEntity(entity);

    // Attach the subclass spatials to the localToCell node
    final Spatial[] spatials = getSpatials();
    if (spatials != null) {
      ClientContextJME.getWorldManager()
          .addRenderUpdater(
              new RenderUpdater() {
                public void update(Object arg0) {
                  if (localToCellNode != null) {
                    for (Spatial spatial : spatials) {
                      localToCellNode.attachChild(spatial);
                    }
                    ClientContextJME.getWorldManager().addToUpdateList(localToCellNode);
                  }
                }
              },
              null,
              true); // Topology change. Must wait for it to complete.
    }
  }
Example #2
0
 /** Detach this component's entity from its parent entity. */
 protected void detachFromParentEntity() {
   if (parentEntity != null) {
     parentEntity.removeEntity(entity);
     RenderComponent rcEntity = (RenderComponent) entity.getComponent(RenderComponent.class);
     if (rcEntity != null) {
       rcEntity.setAttachPoint(null);
     }
   }
   parentEntity = null;
 }
Example #3
0
 /** Attach this component's entity to its parent entity. */
 protected void attachToParentEntity() {
   if (parentEntity != null) {
     parentEntity.addEntity(entity);
     RenderComponent rcParentEntity =
         (RenderComponent) parentEntity.getComponent(RenderComponent.class);
     RenderComponent rcEntity = (RenderComponent) entity.getComponent(RenderComponent.class);
     if (rcParentEntity != null && rcParentEntity.getSceneRoot() != null && rcEntity != null) {
       rcEntity.setAttachPoint(rcParentEntity.getSceneRoot());
     }
   }
 }
  /**
   * Change the current avatar to the given avatar.
   *
   * <p>NOTE: This method must be called in the MT Game Render Thread. As such, we assume only one
   * of these methods is called at a time.
   *
   * @param newAvatar The new avatar to change to.
   */
  private void changeAvatarInternal(WlAvatarCharacter newAvatar) {

    int flg = 0;
    if (newAvatar == null) return;

    // 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
    if (cell instanceof AvatarCell) {
      selectForInput(((AvatarCell) cell).isSelectedForInput());
    }

    // Notify listeners that the avatar has changed.
    for (WeakReference<AvatarChangedListener> listenerRef : avatarChangedListeners) {
      AvatarChangedListener listener = listenerRef.get();
      if (listener != null) {
        listener.avatarChanged(avatarCharacter);
      } else {
        avatarChangedListeners.remove(listenerRef);
      }
    }

    // update the bounds if necessary
    if (avatarCharacter.getJScene() != null) {
      avatarCharacter.getPScene().submitTransformsAndGeometry(true);
      avatarCharacter.getJScene().setModelBound(new BoundingSphere());
      avatarCharacter.getJScene().updateModelBound();
      avatarCharacter.getJScene().updateWorldBound();
    }

    // Update pick geometry
    updatePickGeometry();

    // Turn off the indication that we have finished loading
    LoadingInfo.finishedLoading(cell.getCellID(), newAvatar.getName());

    // --added for sitting problem when user logs in--//
    // check If there is an existing avatar character
    if (flg == 0) {
      AvatarCell acell = (AvatarCell) cell;
      MovableAvatarComponent mac =
          (MovableAvatarComponent) acell.getComponent(MovableComponent.class);
      // check if avatar has trigger value of sitting
      if (mac.getServerTrigger() == 15) {
        avatarCharacter.getContext().triggerPressed(mac.getServerTrigger());
      }
    }
    // --added for sitting problem when user logs in--//
  }