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

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

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

Spatial.removeFromParent介绍

[英]removeFromParent removes this Spatial from its parent.
[中]removeFromParent从父空间中删除此空间。

代码示例

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

@Override
public boolean removeFromParent() {
  return super.removeFromParent();
}

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

public void detachLinkedChildren() {
  Set<Entry<ModelKey, Spatial>> set = assetChildren.entrySet();
  for (Iterator<Entry<ModelKey, Spatial>> it = set.iterator(); it.hasNext();) {
    Entry<ModelKey, Spatial> entry = it.next();
    entry.getValue().removeFromParent();
    it.remove();
  }
}

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

@Override
  public void simpleUpdate(float tpf) {
    if (!useAutoRotate) {
      return;
    }
    time += tpf;
   //  autoRotate.rotate(0, tpf * 0.5f, 0);
    if (time > duration) {
      // morphIndex++;
      //  setMorphTarget(morphIndex);
      assets.get(assetIndex).removeFromParent();
      assetIndex = (assetIndex + 1) % assets.size();
//            if (assetIndex == 0) {
//                duration = 10;
//            }
      probeNode.attachChild(assets.get(assetIndex));
      time = 0;
    }
  }

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

/**
 * Loads the linked children AssetKeys from the AssetManager and attaches them to the Node<br>
 * If they are already attached, they will be reloaded.
 * @param manager
 */
public void attachLinkedChildren(AssetManager manager) {
  detachLinkedChildren();
  for (Iterator<ModelKey> it = assetLoaderKeys.iterator(); it.hasNext();) {
    ModelKey assetKey = it.next();
    Spatial curChild = assetChildren.get(assetKey);
    if (curChild != null) {
      curChild.removeFromParent();
    }
    Spatial child = manager.loadAsset(assetKey);
    attachChild(child);
    assetChildren.put(assetKey, child);
  }
}

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

private void updateJoints() {
  HashMap<PhysicsJoint, Spatial> oldObjects = joints;
  joints = new HashMap<PhysicsJoint, Spatial>();
  Collection<PhysicsJoint> current = space.getJointList();
  //create new map
  for (Iterator<PhysicsJoint> it = current.iterator(); it.hasNext();) {
    PhysicsJoint physicsObject = it.next();
    //copy existing spatials
    if (oldObjects.containsKey(physicsObject)) {
      Spatial spat = oldObjects.get(physicsObject);
      joints.put(physicsObject, spat);
      oldObjects.remove(physicsObject);
    } else {
      if (filter == null || filter.displayObject(physicsObject)) {
        logger.log(Level.FINE, "Create new debug Joint");
        //create new spatial
        Node node = new Node(physicsObject.toString());
        node.addControl(new BulletJointDebugControl(this, physicsObject));
        joints.put(physicsObject, node);
        physicsDebugRootNode.attachChild(node);
      }
    }
  }
  //remove leftover spatials
  for (Map.Entry<PhysicsJoint, Spatial> entry : oldObjects.entrySet()) {
    PhysicsJoint object = entry.getKey();
    Spatial spatial = entry.getValue();
    spatial.removeFromParent();
  }
}

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

private void updateVehicles() {
  HashMap<PhysicsVehicle, Spatial> oldObjects = vehicles;
  vehicles = new HashMap<PhysicsVehicle, Spatial>();
  Collection<PhysicsVehicle> current = space.getVehicleList();
  //create new map
  for (Iterator<PhysicsVehicle> it = current.iterator(); it.hasNext();) {
    PhysicsVehicle physicsObject = it.next();
    //copy existing spatials
    if (oldObjects.containsKey(physicsObject)) {
      Spatial spat = oldObjects.get(physicsObject);
      vehicles.put(physicsObject, spat);
      oldObjects.remove(physicsObject);
    } else {
      if (filter == null || filter.displayObject(physicsObject)) {
        logger.log(Level.FINE, "Create new debug Vehicle");
        //create new spatial
        Node node = new Node(physicsObject.toString());
        node.addControl(new BulletVehicleDebugControl(this, physicsObject));
        vehicles.put(physicsObject, node);
        physicsDebugRootNode.attachChild(node);
      }
    }
  }
  //remove leftover spatials
  for (Map.Entry<PhysicsVehicle, Spatial> entry : oldObjects.entrySet()) {
    PhysicsVehicle object = entry.getKey();
    Spatial spatial = entry.getValue();
    spatial.removeFromParent();
  }
}

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

private void updateGhosts() {
  HashMap<PhysicsGhostObject, Spatial> oldObjects = ghosts;
  ghosts = new HashMap<PhysicsGhostObject, Spatial>();
  Collection<PhysicsGhostObject> current = space.getGhostObjectList();
  //create new map
  for (Iterator<PhysicsGhostObject> it = current.iterator(); it.hasNext();) {
    PhysicsGhostObject physicsObject = it.next();
    //copy existing spatials
    if (oldObjects.containsKey(physicsObject)) {
      Spatial spat = oldObjects.get(physicsObject);
      ghosts.put(physicsObject, spat);
      oldObjects.remove(physicsObject);
    } else {
      if (filter == null || filter.displayObject(physicsObject)) {
        logger.log(Level.FINE, "Create new debug GhostObject");
        //create new spatial
        Node node = new Node(physicsObject.toString());
        node.addControl(new BulletGhostObjectDebugControl(this, physicsObject));
        ghosts.put(physicsObject, node);
        physicsDebugRootNode.attachChild(node);
      }
    }
  }
  //remove leftover spatials
  for (Map.Entry<PhysicsGhostObject, Spatial> entry : oldObjects.entrySet()) {
    PhysicsGhostObject object = entry.getKey();
    Spatial spatial = entry.getValue();
    spatial.removeFromParent();
  }
}

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

private void updateCharacters() {
  HashMap<PhysicsCharacter, Spatial> oldObjects = characters;
  characters = new HashMap<PhysicsCharacter, Spatial>();
  Collection<PhysicsCharacter> current = space.getCharacterList();
  //create new map
  for (Iterator<PhysicsCharacter> it = current.iterator(); it.hasNext();) {
    PhysicsCharacter physicsObject = it.next();
    //copy existing spatials
    if (oldObjects.containsKey(physicsObject)) {
      Spatial spat = oldObjects.get(physicsObject);
      characters.put(physicsObject, spat);
      oldObjects.remove(physicsObject);
    } else {
      if (filter == null || filter.displayObject(physicsObject)) {
        logger.log(Level.FINE, "Create new debug Character");
        //create new spatial
        Node node = new Node(physicsObject.toString());
        node.addControl(new BulletCharacterDebugControl(this, physicsObject));
        characters.put(physicsObject, node);
        physicsDebugRootNode.attachChild(node);
      }
    }
  }
  //remove leftover spatials
  for (Map.Entry<PhysicsCharacter, Spatial> entry : oldObjects.entrySet()) {
    PhysicsCharacter object = entry.getKey();
    Spatial spatial = entry.getValue();
    spatial.removeFromParent();
  }
}

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

private void updateRigidBodies() {
  HashMap<PhysicsRigidBody, Spatial> oldObjects = bodies;
  bodies = new HashMap<PhysicsRigidBody, Spatial>();
  Collection<PhysicsRigidBody> current = space.getRigidBodyList();
  //create new map
  for (Iterator<PhysicsRigidBody> it = current.iterator(); it.hasNext();) {
    PhysicsRigidBody physicsObject = it.next();
    //copy existing spatials
    if (oldObjects.containsKey(physicsObject)) {
      Spatial spat = oldObjects.get(physicsObject);
      bodies.put(physicsObject, spat);
      oldObjects.remove(physicsObject);
    } else {
      if (filter == null || filter.displayObject(physicsObject)) {
        logger.log(Level.FINE, "Create new debug RigidBody");
        //create new spatial
        Node node = new Node(physicsObject.toString());
        node.addControl(new BulletRigidBodyDebugControl(this, physicsObject));
        bodies.put(physicsObject, node);
        physicsDebugRootNode.attachChild(node);
      }
    }
  }
  //remove leftover spatials
  for (Map.Entry<PhysicsRigidBody, Spatial> entry : oldObjects.entrySet()) {
    PhysicsRigidBody object = entry.getKey();
    Spatial spatial = entry.getValue();
    spatial.removeFromParent();
  }
}

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

private void updateCharacters() {
  HashMap<PhysicsCharacter, Spatial> oldObjects = characters;
  characters = new HashMap<PhysicsCharacter, Spatial>();
  Collection<PhysicsCharacter> current = space.getCharacterList();
  //create new map
  for (Iterator<PhysicsCharacter> it = current.iterator(); it.hasNext();) {
    PhysicsCharacter physicsObject = it.next();
    //copy existing spatials
    if (oldObjects.containsKey(physicsObject)) {
      Spatial spat = oldObjects.get(physicsObject);
      characters.put(physicsObject, spat);
      oldObjects.remove(physicsObject);
    } else {
      if (filter == null || filter.displayObject(physicsObject)) {
        logger.log(Level.FINE, "Create new debug Character");
        //create new spatial
        Node node = new Node(physicsObject.toString());
        node.addControl(new BulletCharacterDebugControl(this, physicsObject));
        characters.put(physicsObject, node);
        physicsDebugRootNode.attachChild(node);
      }
    }
  }
  //remove leftover spatials
  for (Map.Entry<PhysicsCharacter, Spatial> entry : oldObjects.entrySet()) {
    PhysicsCharacter object = entry.getKey();
    Spatial spatial = entry.getValue();
    spatial.removeFromParent();
  }
}

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

private void updateRigidBodies() {
  HashMap<PhysicsRigidBody, Spatial> oldObjects = bodies;
  bodies = new HashMap<PhysicsRigidBody, Spatial>();
  Collection<PhysicsRigidBody> current = space.getRigidBodyList();
  //create new map
  for (Iterator<PhysicsRigidBody> it = current.iterator(); it.hasNext();) {
    PhysicsRigidBody physicsObject = it.next();
    //copy existing spatials
    if (oldObjects.containsKey(physicsObject)) {
      Spatial spat = oldObjects.get(physicsObject);
      bodies.put(physicsObject, spat);
      oldObjects.remove(physicsObject);
    } else {
      if (filter == null || filter.displayObject(physicsObject)) {
        logger.log(Level.FINE, "Create new debug RigidBody");
        //create new spatial
        Node node = new Node(physicsObject.toString());
        node.addControl(new BulletRigidBodyDebugControl(this, physicsObject));
        bodies.put(physicsObject, node);
        physicsDebugRootNode.attachChild(node);
      }
    }
  }
  //remove leftover spatials
  for (Map.Entry<PhysicsRigidBody, Spatial> entry : oldObjects.entrySet()) {
    PhysicsRigidBody object = entry.getKey();
    Spatial spatial = entry.getValue();
    spatial.removeFromParent();
  }
}

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

private void updateGhosts() {
  HashMap<PhysicsGhostObject, Spatial> oldObjects = ghosts;
  ghosts = new HashMap<PhysicsGhostObject, Spatial>();
  Collection<PhysicsGhostObject> current = space.getGhostObjectList();
  //create new map
  for (Iterator<PhysicsGhostObject> it = current.iterator(); it.hasNext();) {
    PhysicsGhostObject physicsObject = it.next();
    //copy existing spatials
    if (oldObjects.containsKey(physicsObject)) {
      Spatial spat = oldObjects.get(physicsObject);
      ghosts.put(physicsObject, spat);
      oldObjects.remove(physicsObject);
    } else {
      if (filter == null || filter.displayObject(physicsObject)) {
        logger.log(Level.FINE, "Create new debug GhostObject");
        //create new spatial
        Node node = new Node(physicsObject.toString());
        node.addControl(new BulletGhostObjectDebugControl(this, physicsObject));
        ghosts.put(physicsObject, node);
        physicsDebugRootNode.attachChild(node);
      }
    }
  }
  //remove leftover spatials
  for (Map.Entry<PhysicsGhostObject, Spatial> entry : oldObjects.entrySet()) {
    PhysicsGhostObject object = entry.getKey();
    Spatial spatial = entry.getValue();
    spatial.removeFromParent();
  }
}

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

private void updateVehicles() {
  HashMap<PhysicsVehicle, Spatial> oldObjects = vehicles;
  vehicles = new HashMap<PhysicsVehicle, Spatial>();
  Collection<PhysicsVehicle> current = space.getVehicleList();
  //create new map
  for (Iterator<PhysicsVehicle> it = current.iterator(); it.hasNext();) {
    PhysicsVehicle physicsObject = it.next();
    //copy existing spatials
    if (oldObjects.containsKey(physicsObject)) {
      Spatial spat = oldObjects.get(physicsObject);
      vehicles.put(physicsObject, spat);
      oldObjects.remove(physicsObject);
    } else {
      if (filter == null || filter.displayObject(physicsObject)) {
        logger.log(Level.FINE, "Create new debug Vehicle");
        //create new spatial
        Node node = new Node(physicsObject.toString());
        node.addControl(new BulletVehicleDebugControl(this, physicsObject));
        vehicles.put(physicsObject, node);
        physicsDebugRootNode.attachChild(node);
      }
    }
  }
  //remove leftover spatials
  for (Map.Entry<PhysicsVehicle, Spatial> entry : oldObjects.entrySet()) {
    PhysicsVehicle object = entry.getKey();
    Spatial spatial = entry.getValue();
    spatial.removeFromParent();
  }
}

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

private void updateJoints() {
  HashMap<PhysicsJoint, Spatial> oldObjects = joints;
  joints = new HashMap<PhysicsJoint, Spatial>();
  Collection<PhysicsJoint> current = space.getJointList();
  //create new map
  for (Iterator<PhysicsJoint> it = current.iterator(); it.hasNext();) {
    PhysicsJoint physicsObject = it.next();
    //copy existing spatials
    if (oldObjects.containsKey(physicsObject)) {
      Spatial spat = oldObjects.get(physicsObject);
      joints.put(physicsObject, spat);
      oldObjects.remove(physicsObject);
    } else {
      if (filter == null || filter.displayObject(physicsObject)) {
        logger.log(Level.FINE, "Create new debug Joint");
        //create new spatial
        Node node = new Node(physicsObject.toString());
        node.addControl(new BulletJointDebugControl(this, physicsObject));
        joints.put(physicsObject, node);
        physicsDebugRootNode.attachChild(node);
      }
    }
  }
  //remove leftover spatials
  for (Map.Entry<PhysicsJoint, Spatial> entry : oldObjects.entrySet()) {
    PhysicsJoint object = entry.getKey();
    Spatial spatial = entry.getValue();
    spatial.removeFromParent();
  }
}

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

private void findChildren(int nodeIndex) throws IOException {
  JointWrapper jw = fetchFromCache("nodes", nodeIndex, JointWrapper.class);
  JsonObject nodeData = nodes.get(nodeIndex).getAsJsonObject();
  JsonArray children = nodeData.getAsJsonArray("children");
  if (children != null) {
    for (JsonElement child : children) {
      int childIndex = child.getAsInt();
      if (jw.children.contains(childIndex)) {
        //bone already has the child in its children
        continue;
      }
      JointWrapper cjw = fetchFromCache("nodes", childIndex, JointWrapper.class);
      if (cjw != null) {
        jw.joint.addChild(cjw.joint);
        jw.children.add(childIndex);
      } else {
        //The child might be a Node
        //Creating a dummy node to read the subgraph
        Node n = new Node();
        readChild(n, child);
        Spatial s = n.getChild(0);
        //removing the spatial from the dummy node, it will be attached to the attachment node of the bone
        s.removeFromParent();
        jw.attachedSpatial = s;
      }
    }
  }
}

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

@Override
public void update(float tpf) {
  super.update(tpf);
  if(enabled){
    timer+=tpf;
    if(timer>maxTime){
      if(spatial.getParent()!=null){
        space.removeCollisionListener(this);
        space.remove(this);
        spatial.removeFromParent();
      }
    }
  }
  if (enabled && curTime >= 0) {
    curTime += tpf;
    if (curTime > fxTime) {
      curTime = -1;
      effect.removeFromParent();
    }
  }
}

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

initScale = model.getLocalScale().clone();
model.removeFromParent();
model.setLocalTranslation(Vector3f.ZERO);
model.setLocalRotation(Quaternion.IDENTITY);

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

initScale = model.getLocalScale().clone();
model.removeFromParent();
model.setLocalTranslation(Vector3f.ZERO);
model.setLocalRotation(Quaternion.IDENTITY);

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

public void collision(PhysicsCollisionEvent event) {
  if (space == null) {
    return;
  }
  if (event.getObjectA() == this || event.getObjectB() == this) {
    space.add(ghostObject);
    ghostObject.setPhysicsLocation(getPhysicsLocation(vector));
    space.addTickListener(this);
    if (effect != null && spatial.getParent() != null) {
      curTime = 0;
      effect.setLocalTranslation(spatial.getLocalTranslation());
      spatial.getParent().attachChild(effect);
      effect.emitAllParticles();
    }
    space.remove(this);
    spatial.removeFromParent();
  }
}

代码示例来源:origin: net.sf.phat/phat-devices

private void removeAudioSpeakerSource(Node body) {
  for (Spatial s : body.getChildren()) {
    if (s instanceof AudioSpeakerSource) {
      s.removeFromParent();
    }
  }
}

相关文章

Spatial类方法