本文整理汇总了Java中com.jme3.scene.SceneGraphVisitor类的典型用法代码示例。如果您正苦于以下问题:Java SceneGraphVisitor类的具体用法?Java SceneGraphVisitor怎么用?Java SceneGraphVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SceneGraphVisitor类属于com.jme3.scene包,在下文中一共展示了SceneGraphVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeSpatial
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
public void removeSpatial(Spatial s) {
s.depthFirstTraversal(new SceneGraphVisitor(){
@Override
public void visit(Spatial sx) {
if(sx instanceof Geometry){
Geometry geo=(Geometry)sx;
Material mat=geo.getMaterial();
String mat_name=mat==null?null:mat.getName();
if(mat_name==null){
System.err.println("Invalid material or missing name");
}else{
Iterator<Entry> e_i=ENTRIES.iterator();
while(e_i.hasNext()){
if(e_i.next().geo==geo){
e_i.remove();
break;
}
}
}
}
}
});
}
示例2: findSpatial
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
/**
* Finds a spatial in the given Spatial tree with the specified name and
* path, the path and name are constructed from the given (sub-)spatial(s)
* and is not read from the UserData of the objects. This is mainly used to
* check if the original spatial still exists in the original file.
*
* @param root
* @param name
* @param path
*/
public static Spatial findSpatial(final Spatial root, final String name, final String path) {
if (name == null || path == null) {
logger.log(Level.WARNING, "Trying to find Spatial with null name spatial for {0}.", root);
return null;
}
if (name.equals(root.getName()) && path.equals(getSpatialPath(root))) {
return root;
}
final SpatialHolder holder = new SpatialHolder();
root.depthFirstTraversal(new SceneGraphVisitor() {
@Override
public void visit(Spatial spatial) {
if (name.equals(spatial.getName()) && path.equals(getSpatialPath(spatial))) {
if (holder.spatial == null) {
holder.spatial = spatial;
} else {
logger.log(Level.WARNING, "Found Spatial {0} twice in {1}", new Object[]{path, root});
}
}
}
});
return holder.spatial;
}
示例3: removeBondPointsForItem
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
protected void removeBondPointsForItem(Spatial item) {
item.depthFirstTraversal(new SceneGraphVisitor() {
@Override
public void visit(Spatial spatial) {
if (spatial instanceof Node) {
Node bondPoint = (Node) spatial;
ObjectBond bond = bondForPoint.get(bondPoint);
if (bond != null) {
inventory.removeJoint(bond.hostItem, bond.guestItem, MySixDofJoint.class);
removeBond(bond);
}
String role = spatial.getUserData("bondPoint");
if ("host".equals(role)) {
hostBondPoints.remove(bondPoint.getName());
} else if ("guest".equals(role)) {
guestBondPoints.remove(bondPoint.getName());
}
}
}
});
guestBondPointsByItem.remove(item);
}
示例4: createInitBonds
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
public void createInitBonds() {
for (Spatial item : items) {
item.depthFirstTraversal(new SceneGraphVisitor() {
@Override
public void visit(Spatial spatial) {
if (spatial instanceof Node) {
Node node = (Node) spatial;
String hostId = node.getUserData("initBondHostId");
if (hostId != null) {
objectBondTracker.createInitBond(node, hostId,
(Integer) node.getUserData("initBondTightness"));
}
}
}
});
}
}
示例5: makeWireFrame
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
public static void makeWireFrame(Spatial spatial) {
SceneGraphVisitor sgv = new SceneGraphVisitor() {
@Override
public void visit(Spatial spa) {
if (spa instanceof Geometry) {
Geometry geo = (Geometry) spa;
Material mat = geo.getMaterial();
if (mat == null) {
mat = new Material(LuoYing.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
}
mat.getAdditionalRenderState().setWireframe(true);
geo.setMaterial(mat);
geo.setCullHint(Spatial.CullHint.Never);
}
}
};
spatial.depthFirstTraversal(sgv);
}
示例6: initialize
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
@Override
public void initialize() {
super.initialize();
entity.getSpatial().depthFirstTraversal(new SceneGraphVisitor() {
@Override
public void visit(Spatial spatial) {
if (spatial instanceof Geometry) {
if (spatial.getControl(LodControl.class) == null) {
LodControl lod = new MyLodControl();
lod.setDistTolerance(distTolerance);
lod.setTrisPerPixel(trisPerPixel);
lod.setEnabled(enabled);
spatial.addControl(lod);
lcs.add(lod);
}
}
}
});
}
示例7: onActivate
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
@Override
protected void onActivate() {
if(owner != null) owner.setInvisible(true);
SceneGraphVisitor visitor = new SceneGraphVisitor() {
@Override
public void visit(Spatial spatial) {
Entity e = spatial.getUserData("entity");
if (e == null) return;
if (!(e instanceof Mob)) System.out.println("non-Mob encountered in the Mob node");
Mob mob = (Mob) e;
if (mob.getTarget() == owner) mob.setTarget(null);
}
};
world.getMobNode().depthFirstTraversal(visitor);
}
示例8: makeMesh
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
@Override
protected void makeMesh(AssetManager assetManager){
geometry = assetManager.loadModel(meshfile);
geometry.setLocalScale(scale);
geometry.getLocalRotation().multLocal(new Quaternion().fromAngleNormalAxis(angle, Vector3f.UNIT_Y));
deleteSpecialNodes();
((Node)geometry).depthFirstTraversal(new SceneGraphVisitor() {
@Override
public void visit(Spatial spatial) {
if(spatial instanceof LightNode)
spatial.getParent().detachChild(spatial);
if(!cull && spatial instanceof Geometry){
((Geometry)spatial).getMaterial().getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
}
}
});
}
示例9: addSpatial
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
public void addSpatial(Spatial s) {
NEED_SUBSTANCES_UPDATE=true;
s.depthFirstTraversal(new SceneGraphVisitor(){
@Override
public void visit(Spatial sx) {
if(sx instanceof Geometry){
Geometry geo=(Geometry)sx;
Material mat=geo.getMaterial();
String mat_name=mat==null?null:mat.getName();
if(mat_name==null){
System.err.println("Invalid material or missing name");
}else{
boolean exists=false;
Iterator<Entry> e_i=ENTRIES.iterator();
while(e_i.hasNext()){
if(e_i.next().geo==geo){
exists=true;
break;
}
}
if(!exists){
Entry e=new Entry();
e.geo=geo;
ENTRIES.add(e);
}
// Apply substance
}
}
}
});
}
示例10: CoursePath
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
/**
* Course path constructor. Locate the course path and organise the points
* into an ordered list. Rotate these points to create a smooth path.
* @param scene Root node of scene.
*/
public CoursePath(Node scene, BulletAppState bullet) {
// Locate each course point and create an array of those points ordered by
// the order data in the user data of the spatials.
Spatial coursePath = scene.getChild(COURSE_PATH_NODE_NAME);
final TreeMap<Integer, Spatial> points = new TreeMap<Integer, Spatial>();
coursePath.breadthFirstTraversal(new SceneGraphVisitor() {
public void visit(Spatial spatial) {
Integer order = spatial.getUserData(COURSE_ORDER_ATTR);
if (order != null) {
points.put(order, spatial);
}
}
});
coursePoints = points.values().toArray(new Spatial[0]);
// To create a smooth rotation along the course, each course point is
// rotated to look in the direction of the vector connecting the preceding
// point with the succeeding point.
for (int i = 0; i < coursePoints.length; ++i) {
Spatial current = coursePoints[i];
Spatial previous = i > 0
? coursePoints[i - 1] : coursePoints[coursePoints.length - 1];
Spatial next = coursePoints[(i + 1) % coursePoints.length];
Vector3f lookDirection
= previous.getLocalTranslation().subtract(next.getLocalTranslation());
current.getLocalRotation().lookAt(lookDirection,
new Vector3f(0.0f, 1.0f, 0.0f));
CollisionShape shape = CollisionShapeFactory.createBoxShape(current);
GhostControl physics = new GhostControl(shape);
current.addControl(physics);
bullet.getPhysicsSpace().add(physics);
}
// Install listener for collisions between player and node.
bullet.getPhysicsSpace()
.addCollisionListener(new CoursePointCollisionListener(this));
}
示例11: storeOriginalPathUserData
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
/**
* Stores ORIGINAL_NAME and ORIGINAL_PATH UserData to given Spatial and all
* sub-Spatials.
*
* @param spat
*/
public static void storeOriginalPathUserData(Spatial spat) {
//TODO: only stores for geometry atm
final ArrayList<String> geomMap = new ArrayList<String>();
if (spat != null) {
spat.depthFirstTraversal(new SceneGraphVisitor() {
@Override
public void visit(Spatial geom) {
Spatial curSpat = geom;
String geomName = curSpat.getName();
if (geomName == null) {
logger.log(Level.WARNING, "Null Spatial name!");
geomName = "null";
}
geom.setUserData("ORIGINAL_NAME", geomName);
logger.log(Level.FINE, "Set ORIGINAL_NAME for {0}", geomName);
String id = SpatialUtil.getSpatialPath(curSpat);
if (geomMap.contains(id)) {
logger.log(Level.WARNING, "Cannot create unique name for Spatial {0}: {1}", new Object[]{geom, id});
}
geomMap.add(id);
geom.setUserData("ORIGINAL_PATH", id);
logger.log(Level.FINE, "Set ORIGINAL_PATH for {0}", id);
}
});
} else {
logger.log(Level.SEVERE, "No Spatial available when trying to add Spatial paths.");
}
}
示例12: findTaggedSpatial
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
/**
* Finds a previously marked spatial in the supplied root Spatial, creates
* the name and path to be looked for from the given needle Spatial.
*
* @param root
* @param needle
* @return
*/
public static Spatial findTaggedSpatial(final Spatial root, final Spatial needle) {
if (needle == null) {
logger.log(Level.WARNING, "Trying to find null needle for {0}", root);
return null;
}
final String name = needle.getName();
final String path = getSpatialPath(needle);
if (name == null || path == null) {
logger.log(Level.WARNING, "Trying to find tagged Spatial with null name spatial for {0}.", root);
return null;
}
final Class clazz = needle.getClass();
String rootName = root.getUserData("ORIGINAL_NAME");
String rootPath = root.getUserData("ORIGINAL_PATH");
if (name.equals(rootName) && path.equals(rootPath)) {
return root;
}
final SpatialHolder holder = new SpatialHolder();
root.depthFirstTraversal(new SceneGraphVisitor() {
@Override
public void visit(Spatial spatial) {
String spName = spatial.getUserData("ORIGINAL_NAME");
String spPath = spatial.getUserData("ORIGINAL_PATH");
if (name.equals(spName) && path.equals(spPath) && clazz.isInstance(spatial)) {
if (holder.spatial == null) {
holder.spatial = spatial;
} else {
logger.log(Level.WARNING, "Found Spatial {0} twice in {1}", new Object[]{path, root});
}
}
}
});
return holder.spatial;
}
示例13: removeAnimData
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
public static void removeAnimData(Spatial root) {
root.depthFirstTraversal(new SceneGraphVisitor() {
@Override
public void visit(Spatial spat) {
AnimControl animControl = spat.getControl(AnimControl.class);
if (animControl != null) {
spat.removeControl(animControl);
SkeletonControl skeletonControl = spat.getControl(SkeletonControl.class);
if (skeletonControl != null) {
spat.removeControl(skeletonControl);
}
}
}
});
}
示例14: hasAnimations
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
/**
* Finds out if a spatial has animations.
*
* @param root
*/
public static boolean hasAnimations(final Spatial root) {
final AtomicBoolean animFound = new AtomicBoolean(false);
root.depthFirstTraversal(new SceneGraphVisitor() {
public void visit(Spatial spatial) {
if (spatial.getControl(AnimControl.class) != null) {
animFound.set(true);
}
}
});
return animFound.get();
}
示例15: DemoSceneProcessor
import com.jme3.scene.SceneGraphVisitor; //导入依赖的package包/类
public DemoSceneProcessor(MainApp app, Node visualAid) {
this.factory = app.getFactory();
visualAid.depthFirstTraversal(new SceneGraphVisitor() {
public void visit(Spatial s) {
if (s instanceof Geometry) {
visualAidGeos.add((Geometry)s);
}
}
});
hlMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
hlMaterial.setColor("Color", ColorRGBA.Black);
}