本文整理了Java中com.jme3.scene.Spatial
类的一些代码示例,展示了Spatial
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Spatial
类的具体详情如下:
包路径:com.jme3.scene.Spatial
类名称:Spatial
[英]Spatial
defines the base class for scene graph nodes. It maintains a link to a parent, its local transforms and the world's transforms. All other scene graph elements, such as Node and Geometry are subclasses of Spatial
.
[中]Spatial
定义场景图节点的基类。它维护到父级、其局部变换和世界变换的链接。所有其他场景图形元素(如节点和几何体)都是Spatial
的子类。
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private void fixRefreshFlags(){
// force transforms to update below this node
spatial.updateGeometricState();
// force world bound to update
Spatial rootNode = spatial;
while (rootNode.getParent() != null){
rootNode = rootNode.getParent();
}
rootNode.getWorldBound();
}
代码示例来源: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
@Override
public boolean removeFromParent() {
return super.removeFromParent();
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private Vector3f getSpatialTranslation() {
if (applyLocal) {
return spatial.getLocalTranslation();
}
return spatial.getWorldTranslation();
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public void update(float tpf) {
if (enabled && spatial != null) {
Quaternion localRotationQuat = spatial.getLocalRotation();
Vector3f localLocation = spatial.getLocalTranslation();
if (!applyLocal && spatial.getParent() != null) {
getPhysicsLocation(localLocation);
localLocation.subtractLocal(spatial.getParent().getWorldTranslation());
localLocation.divideLocal(spatial.getParent().getWorldScale());
tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
spatial.setLocalTranslation(localLocation);
if (useViewDirection) {
localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y);
spatial.setLocalRotation(localRotationQuat);
}
} else {
spatial.setLocalTranslation(getPhysicsLocation());
localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y);
spatial.setLocalRotation(localRotationQuat);
}
}
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public void makeMissile() {
Vector3f pos = spaceCraft.getWorldTranslation().clone();
Quaternion rot = spaceCraft.getWorldRotation();
Vector3f dir = rot.getRotationColumn(2);
Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.mesh.xml");
missile.scale(0.5f);
missile.rotate(0, FastMath.PI, 0);
missile.updateGeometricState();
BoundingBox box = (BoundingBox) missile.getWorldBound();
final Vector3f extent = box.getExtent(null);
BoxCollisionShape boxShape = new BoxCollisionShape(extent);
missile.setName("Missile");
missile.rotate(rot);
missile.setLocalTranslation(pos.addLocal(0, extent.y * 4.5f, 0));
missile.setLocalRotation(hoverControl.getPhysicsRotation());
missile.setShadowMode(ShadowMode.Cast);
RigidBodyControl control = new BombControl(assetManager, boxShape, 20);
control.setLinearVelocity(dir.mult(100));
control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_03);
missile.addControl(control);
rootNode.attachChild(missile);
getPhysicsSpace().add(missile);
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public void setupSignpost() {
Spatial signpost = assetManager.loadModel("Models/Sign Post/Sign Post.mesh.xml");
Material mat = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
signpost.setMaterial(mat);
signpost.rotate(0, FastMath.HALF_PI, 0);
signpost.setLocalTranslation(12, 3.5f, 30);
signpost.setLocalScale(4);
signpost.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(signpost);
}
代码示例来源: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: jMonkeyEngine/jmonkeyengine
float val = ((Float)child.getUserData("height")).floatValue();
float dir = ((Float)child.getUserData("dir")).floatValue();
Vector3f translation = child.getLocalTranslation();
translation.y = (smoothstep(0, 1, val) * 2.5f) - 1.25f;
child.setUserData("height", val);
child.setUserData("dir", dir);
child.setLocalTranslation(translation);
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* Centers the spatial in the origin of the world bound.
* @return The spatial on which this method is called, e.g <code>this</code>.
*/
public Spatial center() {
Vector3f worldTrans = getWorldTranslation();
Vector3f worldCenter = getWorldBound().getCenter();
Vector3f absTrans = worldTrans.subtract(worldCenter);
setLocalTranslation(absTrans);
return this;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* applies the current transform to the given jme Node if the location has been updated on the physics side
* @param spatial
*/
public boolean applyTransform(Spatial spatial) {
if (!physicsLocationDirty) {
return false;
}
if (!applyPhysicsLocal && spatial.getParent() != null) {
localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation());
localLocation.divideLocal(spatial.getParent().getWorldScale());
tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
localRotationQuat.set(worldRotationQuat);
tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
spatial.setLocalTranslation(localLocation);
spatial.setLocalRotation(localRotationQuat);
} else {
spatial.setLocalTranslation(worldLocation);
spatial.setLocalRotation(worldRotationQuat);
}
physicsLocationDirty = false;
return true;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private void buildPlayer() {
spaceCraft = assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
CollisionShape colShape = CollisionShapeFactory.createDynamicMeshShape(spaceCraft);
spaceCraft.setShadowMode(ShadowMode.CastAndReceive);
spaceCraft.setLocalTranslation(new Vector3f(-140, 50, -23));
spaceCraft.setLocalRotation(new Quaternion(new float[]{0, 0.01f, 0}));
hoverControl = new PhysicsHoverControl(colShape, 500);
spaceCraft.addControl(hoverControl);
rootNode.attachChild(spaceCraft);
getPhysicsSpace().add(hoverControl);
hoverControl.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
spaceCraft.addControl(chaseCam);
flyCam.setEnabled(false);
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* Instantiate an enabled control to visualize the specified character.
*
* @param debugAppState which app state (not null, alias created)
* @param body the character to visualize (not null, alias created)
*/
public BulletCharacterDebugControl(BulletDebugAppState debugAppState, PhysicsCharacter body) {
super(debugAppState);
this.body = body;
myShape = body.getCollisionShape();
oldScale.set(myShape.getScale());
this.geom = DebugShapeFactory.getDebugShape(myShape);
this.geom.setName(body.toString());
geom.setMaterial(debugAppState.DEBUG_PINK);
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private static void dumpSpatialProperties( String indent, Spatial s ) {
dumpProperties(indent, s, "children");
if( !s.getUserDataKeys().isEmpty() ) {
System.out.println(indent + "userData:");
for( String key : s.getUserDataKeys() ) {
System.out.println(indent + " " + key + ":" + objectToString(s.getUserData(key)));
}
}
if( s.getNumControls() > 0 ) {
System.out.println(indent + "controls:");
for( int i = 0; i < s.getNumControls(); i++ ) {
Control ctl = s.getControl(i);
//dump(indent + " ", ctl);
dumpObject(indent + " ", ctl);
}
}
LightList lights = s.getLocalLightList();
if( lights.size() > 0 ) {
System.out.println(indent + "lights:");
for( Light l : lights ) {
dumpObject(indent + " ", l);
}
}
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
@Override
public void visit(Spatial spatial) {
SkeletonControl control = spatial.getControl(SkeletonControl.class);
if (control != null) {
Armature armature = skeletonArmatureMap.get(control.getSkeleton());
SkinningControl skinningControl = new SkinningControl(armature);
Map<String, List<Spatial>> attachedSpatials = new HashMap<>();
for (int i = 0; i < control.getSkeleton().getBoneCount(); i++) {
Bone b = control.getSkeleton().getBone(i);
Node n = control.getAttachmentsNode(b.getName());
n.removeFromParent();
if (!n.getChildren().isEmpty()) {
attachedSpatials.put(b.getName(), n.getChildren());
}
}
spatial.removeControl(control);
spatial.addControl(skinningControl);
for (String name : attachedSpatials.keySet()) {
List<Spatial> spatials = attachedSpatials.get(name);
for (Spatial child : spatials) {
skinningControl.getAttachmentsNode(name).attachChild(child);
}
}
}
}
代码示例来源: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 initialDuration the initial duration of the event
*/
public AnimationEvent(Spatial model, String animationName, float initialDuration) {
super(initialDuration);
this.model = model;
this.modelName = model.getName();
this.animationName = animationName;
}
代码示例来源: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
/**
* Creates a MotionPath for the given spatial on the given motion path.
* @param spatial
* @param path
*/
public MotionEvent(Spatial spatial, MotionPath path) {
super();
spatial.addControl(this);
this.path = path;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
Map<String, Map<String, Object>> linkedData = loadedAsset.getUserData("linkedData");
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private void dumpScene(Spatial s, int indent) {
System.err.println(indentString.substring(0, indent) + s.getName() + " (" + s.getClass().getSimpleName() + ") / " +
s.getLocalTransform().getTranslation().toString() + ", " +
s.getLocalTransform().getRotation().toString() + ", " +
s.getLocalTransform().getScale().toString());
if (s instanceof Node) {
Node n = (Node) s;
for (Spatial spatial : n.getChildren()) {
dumpScene(spatial, indent + 1);
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!