com.jme3.scene.Spatial.getControl()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中com.jme3.scene.Spatial.getControl()方法的一些代码示例,展示了Spatial.getControl()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Spatial.getControl()方法的具体详情如下:
包路径:com.jme3.scene.Spatial
类名称:Spatial
方法名:getControl

Spatial.getControl介绍

[英]Returns the control at the given index in the list.
[中]返回列表中给定索引处的控件。

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Build a map of mesh vertices in a subtree of the scene graph.
 *
 * @param model the root of the subtree (may be null)
 * @return a new map (not null)
 */
public static Map<Integer, List<Float>> buildPointMap(Spatial model) {
  Map<Integer, List<Float>> map = new HashMap<>();
  SkeletonControl skeletonCtrl = model.getControl(SkeletonControl.class);
  Mesh[] targetMeshes = skeletonCtrl.getTargets();
  for (Mesh mesh : targetMeshes) {
    buildPointMapForMesh(mesh, map);
  }
  return map;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Build a map of mesh vertices in a subtree of the scene graph.
 *
 * @param model the root of the subtree (may be null)
 * @return a new map (not null)
 */
public static Map<Integer, List<Float>> buildPointMap(Spatial model) {
  Map<Integer, List<Float>> map = new HashMap<>();
  SkeletonControl skeletonCtrl = model.getControl(SkeletonControl.class);
  Mesh[] targetMeshes = skeletonCtrl.getTargets();
  for (Mesh mesh : targetMeshes) {
    buildPointMapForMesh(mesh, map);
  }
  return map;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * creates an animation event
 *
 * @param model the model on which the animation will be played
 * @param animationName the name of the animation to play
 */
public AnimationEvent(Spatial model, String animationName) {
  this.model = model;
  this.modelName = model.getName();
  this.animationName = animationName;
  initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private Spatial loadModel(int i) {
  Spatial model = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
  model.setLocalScale(0.1f);
  AnimComposer composer = model.getControl(AnimComposer.class);
  composer.setCurrentAction(animNames[i]);
  SkinningControl skinningControl = model.getControl(SkinningControl.class);
  skinningControl.setHardwareSkinningPreferred(hwSkinningEnable);
  skControls.add(skinningControl);
  rootNode.attachChild(model);
  return model;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * creates an animation event
 *
 * @param model the model on which the animation will be played
 * @param animationName the name of the animation to play
 * @param loopMode the loopMode
 * @see LoopMode
 */
public AnimationEvent(Spatial model, String animationName, LoopMode loopMode) {
  super(loopMode);
  initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
  this.model = model;
  this.modelName = model.getName();
  this.animationName = animationName;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * creates an animation event
 *
 * @param model the model on which the animation will be played
 * @param animationName the name of the animation to play
 * @param channelIndex the index of the channel default is 0. Events on the
 * same channelIndex will use the same channel.
 */
public AnimationEvent(Spatial model, String animationName, int channelIndex) {
  this.model = model;
  this.modelName = model.getName();
  this.animationName = animationName;
  initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
  this.channelIndex = channelIndex;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private <T extends Control> T findControl(Spatial s, Class<T> controlClass) {
  T ctrl = s.getControl(controlClass);
  if (ctrl != null) {
    return ctrl;
  }
  if (s instanceof Node) {
    Node n = (Node) s;
    for (Spatial spatial : n.getChildren()) {
      ctrl = findControl(spatial, controlClass);
      if (ctrl != null) {
        return ctrl;
      }
    }
  }
  return null;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * creates an animation event
 *
 * @param model the model on which the animation will be played
 * @param animationName the name of the animation to play
 * @param loopMode the loopMode
 * @see LoopMode
 * @param blendTime the time during the animation are gonna be blended
 * @see AnimChannel#setAnim(java.lang.String, float)
 */
public AnimationEvent(Spatial model, String animationName, LoopMode loopMode, float blendTime) {
  super(loopMode);
  initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
  this.model = model;
  this.modelName = model.getName();
  this.animationName = animationName;
  this.blendTime = blendTime;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * creates an animation event
 *
 * @param model the model on which the animation will be played
 * @param animationName the name of the animation to play
 * @param loopMode the loopMode
 * @see LoopMode
 * @param channelIndex the index of the channel default is 0. Events on the
 * same channelIndex will use the same channel.
 */
public AnimationEvent(Spatial model, String animationName, LoopMode loopMode, int channelIndex) {
  super(loopMode);
  initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
  this.model = model;
  this.modelName = model.getName();
  this.animationName = animationName;
  this.channelIndex = channelIndex;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * creates an animation event
 *
 * @param model the model on which the animation will be played
 * @param animationName the name of the animation to play
 * @param channelIndex the index of the channel default is 0. Events on the
 * @param blendTime the time during the animation are gonna be blended
 * same channelIndex will use the same channel.
 */
public AnimationEvent(Spatial model, String animationName, LoopMode loopMode, int channelIndex, float blendTime) {
  this.model = model;
  this.modelName = model.getName();
  this.animationName = animationName;
  this.loopMode = loopMode;
  initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
  this.channelIndex = channelIndex;
  this.blendTime = blendTime;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private void playFirstAnim(Spatial s) {
  AnimComposer control = s.getControl(AnimComposer.class);
  if (control != null) {
    anims.clear();
    for (String name : control.getAnimClipsNames()) {
      anims.add(name);
    }
    if (anims.isEmpty()) {
      return;
    }
    String anim = anims.poll();
    anims.add(anim);
    control.setCurrentAction(anim);
    composer = control;
  }
  if (s instanceof Node) {
    Node n = (Node) s;
    for (Spatial spatial : n.getChildren()) {
      playFirstAnim(spatial);
    }
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private void stopAnim(Spatial s) {
  AnimComposer control = s.getControl(AnimComposer.class);
  if (control != null) {
    control.reset();
  }
  if (s instanceof Node) {
    Node n = (Node) s;
    for (Spatial spatial : n.getChildren()) {
      stopAnim(spatial);
    }
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * adds an object to the physics space
 * @param obj the PhysicsControl or Spatial with PhysicsControl to add
 */
public void add(Object obj) {
  if (obj == null) return;
  if (obj instanceof PhysicsControl) {
    ((PhysicsControl) obj).setPhysicsSpace(this);
  } else if (obj instanceof Spatial) {
    Spatial node = (Spatial) obj;
    for (int i = 0; i < node.getNumControls(); i++) {
      if (node.getControl(i) instanceof PhysicsControl) {
        add(((PhysicsControl) node.getControl(i)));
      }
    }
  } else if (obj instanceof PhysicsCollisionObject) {
    addCollisionObject((PhysicsCollisionObject) obj);
  } else if (obj instanceof PhysicsJoint) {
    addJoint((PhysicsJoint) obj);
  } else {
    throw (new UnsupportedOperationException("Cannot add this kind of object to the physics space."));
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * removes an object from the physics space
 *
 * @param obj the PhysicsControl or Spatial with PhysicsControl to remove
 */
public void remove(Object obj) {
  if (obj == null) return;
  if (obj instanceof PhysicsControl) {
    ((PhysicsControl) obj).setPhysicsSpace(null);
  } else if (obj instanceof Spatial) {
    Spatial node = (Spatial) obj;
    for (int i = 0; i < node.getNumControls(); i++) {
      if (node.getControl(i) instanceof PhysicsControl) {
        remove(((PhysicsControl) node.getControl(i)));
      }
    }
  } else if (obj instanceof PhysicsCollisionObject) {
    removeCollisionObject((PhysicsCollisionObject) obj);
  } else if (obj instanceof PhysicsJoint) {
    removeJoint((PhysicsJoint) obj);
  } else {
    throw (new UnsupportedOperationException("Cannot remove this kind of object from the physics space."));
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Remove the specified object from this space.
 *
 * @param obj the PhysicsCollisionObject to add, or null (modified)
 */
public void remove(Object obj) {
  if (obj == null) return;
  if (obj instanceof PhysicsControl) {
    ((PhysicsControl) obj).setPhysicsSpace(null);
  } else if (obj instanceof Spatial) {
    Spatial node = (Spatial) obj;
    for (int i = 0; i < node.getNumControls(); i++) {
      if (node.getControl(i) instanceof PhysicsControl) {
        remove(((PhysicsControl) node.getControl(i)));
      }
    }
  } else if (obj instanceof PhysicsCollisionObject) {
    removeCollisionObject((PhysicsCollisionObject) obj);
  } else if (obj instanceof PhysicsJoint) {
    removeJoint((PhysicsJoint) obj);
  } else {
    throw (new UnsupportedOperationException("Cannot remove this kind of object from the physics space."));
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Generate physics shapes and bone links for the skeleton.
 *
 * @param model the spatial with the model's SkeletonControl (not null)
 */
protected void scanSpatial(Spatial model) {
  AnimControl animControl = model.getControl(AnimControl.class);
  Map<Integer, List<Float>> pointsMap = null;
  if (weightThreshold == -1.0f) {
    pointsMap = RagdollUtils.buildPointMap(model);
  }
  skeleton = animControl.getSkeleton();
  skeleton.resetAndUpdate();
  for (int i = 0; i < skeleton.getRoots().length; i++) {
    Bone childBone = skeleton.getRoots()[i];
    if (childBone.getParent() == null) {
      logger.log(Level.FINE, "Found root bone in skeleton {0}", skeleton);
      boneRecursion(model, childBone, baseRigidBody, 1, pointsMap);
    }
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Generate physics shapes and bone links for the skeleton.
 *
 * @param model the spatial with the model's SkeletonControl (not null)
 */
protected void scanSpatial(Spatial model) {
  AnimControl animControl = model.getControl(AnimControl.class);
  Map<Integer, List<Float>> pointsMap = null;
  if (weightThreshold == -1.0f) {
    pointsMap = RagdollUtils.buildPointMap(model);
  }
  skeleton = animControl.getSkeleton();
  skeleton.resetAndUpdate();
  for (int i = 0; i < skeleton.getRoots().length; i++) {
    Bone childBone = skeleton.getRoots()[i];
    if (childBone.getParent() == null) {
      logger.log(Level.FINE, "Found root bone in skeleton {0}", skeleton);
      boneRecursion(model, childBone, baseRigidBody, 1, pointsMap);
    }
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private void reset() {
  // Reset the pickups
  for(Spatial pickUp : pickUps.getChildren()) {
    GhostControl pickUpControl = pickUp.getControl(GhostControl.class);
    if(pickUpControl != null) {
      pickUpControl.setEnabled(true);
    }
    pickUp.setLocalScale(1.0f);
  }
  // Reset the player
  player.setPhysicsLocation(PLAYER_START.clone());
  player.setAngularVelocity(Vector3f.ZERO.clone());
  player.setLinearVelocity(Vector3f.ZERO.clone());
  // Reset the score
  score = 0;
  // Reset the message
  messageText.setLocalScale(0.0f);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

@Override
public void simpleInitApp() {
  flyCam.setMoveSpeed(10f);
  cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
  cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));
  DirectionalLight dl = new DirectionalLight();
  dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
  dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
  rootNode.addLight(dl);
  BlenderKey blenderKey = new BlenderKey("Blender/2.4x/BaseMesh_249.blend");
  
  Spatial scene = (Spatial) assetManager.loadModel(blenderKey);
  rootNode.attachChild(scene);
  
  Spatial model = this.findNode(rootNode, "BaseMesh_01");
  model.center();
  
  control = model.getControl(AnimControl.class);
  channel = control.createChannel();
  channel.setAnim("run_01");
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

@Override
public void simpleInitApp() {
  flyCam.setMoveSpeed(10f);
  cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
  cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));
  DirectionalLight dl = new DirectionalLight();
  dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
  dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
  rootNode.addLight(dl);
  BlenderKey blenderKey = new BlenderKey("Blender/2.4x/animtest.blend");
  
  Spatial scene = (Spatial) assetManager.loadModel(blenderKey);
  rootNode.attachChild(scene);
  
  Spatial model = this.findNode(rootNode, "Cube");
  model.center();
  
  control = model.getControl(AnimControl.class);
  channel = control.createChannel();
  channel.setAnim("Action");
}

相关文章

Spatial类方法