当前位置: 首页>>代码示例>>Java>>正文


Java SceneGraphVisitorAdapter类代码示例

本文整理汇总了Java中com.jme3.scene.SceneGraphVisitorAdapter的典型用法代码示例。如果您正苦于以下问题:Java SceneGraphVisitorAdapter类的具体用法?Java SceneGraphVisitorAdapter怎么用?Java SceneGraphVisitorAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SceneGraphVisitorAdapter类属于com.jme3.scene包,在下文中一共展示了SceneGraphVisitorAdapter类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateMeshDataFromOriginal

import com.jme3.scene.SceneGraphVisitorAdapter; //导入依赖的package包/类
/**
 * Updates the mesh data of existing objects from an original file, adds new
 * nonexisting geometry objects to the root, including their parents if they
 * don't exist.
 *
 * @param root
 * @param original
 */
public static void updateMeshDataFromOriginal(final Spatial root, final Spatial original) {
    //loop through original to also find new geometry
    original.depthFirstTraversal(new SceneGraphVisitorAdapter() {
        @Override
        public void visit(Geometry geom) {
            //will always return same class type as 2nd param, so casting is safe
            Geometry spat = (Geometry) findTaggedSpatial(root, geom);
            if (spat != null) {
                spat.setMesh(geom.getMesh());
                logger.log(LogLevel.USERINFO, "Updated mesh for Geometry {0}", geom.getName());
            } else {
                addLeafWithNonExistingParents(root, geom);
            }
        }
    });
}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:25,代码来源:SpatialUtil.java

示例2: setColor

import com.jme3.scene.SceneGraphVisitorAdapter; //导入依赖的package包/类
/**
 * 给指定的spatial指定一个颜色,该方法主要改变spatial的material的Color
 * 属性,当没有该属性时会偿试添加一个,这要求该material的原形必须有一
 * 个"Color"属性的定义,该属性的verType必须是vector4.
 * @param spatial
 * @param color 
 */
public static void setColor(Spatial spatial, final ColorRGBA color) {
    spatial.depthFirstTraversal(new SceneGraphVisitorAdapter() {
        @Override
        public void visit(Geometry geom) {
            // 存在Color属性时更改颜色。
            Material mat = geom.getMaterial();
            if (mat != null) {
                MatParam colorParam = mat.getParam("Color");
                if (colorParam != null && colorParam.getVarType() == VarType.Vector4) {
                    ((ColorRGBA)colorParam.getValue()).set(color);
                    return;
                }
                // 不存在Color颜色时先看是否有Color属性的定义,如果有则添加该属性。
                MatParam colorDef = mat.getMaterialDef().getMaterialParam("Color");
                if (colorDef != null && colorDef.getVarType() == VarType.Vector4) {
                    // 这里需要重新创建一个,否则会引用同一个实例。
                    mat.setColor("Color", new ColorRGBA(color));
                }
            }
        }
    });
}
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:30,代码来源:GeometryUtils.java

示例3: setupIndicator

import com.jme3.scene.SceneGraphVisitorAdapter; //导入依赖的package包/类
protected void setupIndicator() {
    indicator = new Node("Indicator");
    indicator.setQueueBucket(Bucket.Translucent);
    root.attachChild(indicator);
    
    // Just in case the root node has been moved
    indicator.setLocalTranslation(root.getLocalTranslation().negate());
    indicator.setLocalRotation(root.getLocalRotation().inverse());
    
    // Setup the indicator material
    this.material = GuiGlobals.getInstance().createMaterial(color, false).getMaterial();
    material.getAdditionalRenderState().setWireframe(true);
    material.getAdditionalRenderState().setDepthFunc(TestFunction.Always);
    
    // Find all of the geometry children of our spatial
    spatial.depthFirstTraversal( new SceneGraphVisitorAdapter() {
            @Override
            public void visit( Geometry geom ) {
                // Make a copy of it
                Geometry copy = cloneGeometry(geom);
                indicator.attachChild(copy);
            }
        });        
}
 
开发者ID:jMonkeyEngine-Contributions,项目名称:Lemur,代码行数:25,代码来源:SelectionIndicator.java

示例4: registerAction_ShowWireframe

import com.jme3.scene.SceneGraphVisitorAdapter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void registerAction_ShowWireframe(SpatialExplorer se, SimpleApplication app) {
	se.treeItemActions.add(new Action("Show Wireframe", (evt) -> {
		Spatial target = ((TreeItem<Spatial>)evt.getSource()).getValue();
		app.enqueue(() -> {
			target.breadthFirstTraversal(new SceneGraphVisitorAdapter(){
				public void visit(Geometry geom) {
					RenderState r = geom.getMaterial().getAdditionalRenderState();
					boolean wireframe = false;
					try {
						Field f = r.getClass().getDeclaredField("wireframe");
						f.setAccessible(true);
						wireframe = (Boolean) f.get(r);
					} catch(Exception exc) {
						exc.printStackTrace();
					}
					r.setWireframe(!wireframe);
				}
			});
			return null;
		});
	}));
}
 
开发者ID:davidB,项目名称:jme3_ext_spatial_explorer,代码行数:24,代码来源:Helper.java

示例5: registerAction_ShowBound

import com.jme3.scene.SceneGraphVisitorAdapter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void registerAction_ShowBound(SpatialExplorer se, SimpleApplication app) {
	Material matModel = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
	matModel.setColor("Color", ColorRGBA.Orange);
	Material matWorld = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
	matWorld.setColor("Color", ColorRGBA.Red);

	se.treeItemActions.add(new Action("Show Bounds", (evt) -> {
		Spatial target = ((TreeItem<Spatial>)evt.getSource()).getValue();
		app.enqueue(() -> {
			target.breadthFirstTraversal(new SceneGraphVisitorAdapter(){
				public void visit(Geometry geom) {
					ShowBoundsControl ctrl = geom.getControl(ShowBoundsControl.class);
					if (ctrl != null) {
						geom.removeControl(ctrl);
					} else {
						geom.addControl(new ShowBoundsControl(matModel, matWorld));
					}
				}
			});
			return null;
		});
	}));
}
 
开发者ID:davidB,项目名称:jme3_ext_spatial_explorer,代码行数:25,代码来源:Helper.java

示例6: AnimationController

import com.jme3.scene.SceneGraphVisitorAdapter; //导入依赖的package包/类
/**
 * Constructor which gets animation controls from character spatial recursively
 * and create animation channels.
 * @param character the character spatial
 */
public AnimationController(final Spatial character) {
    SceneGraphVisitorAdapter visitor = new SceneGraphVisitorAdapter() {
        @Override
        public void visit(final Geometry geometry) {
            super.visit(geometry);
            checkForAnimControl(geometry);
        }

        @Override
        public void visit(final Node node) {
            super.visit(node);
            checkForAnimControl(node);
        }

        /**
         * Checks whether spatial has animation control and constructs animation channel
         * of it has.
         * @param spatial the sptial
         */
        private void checkForAnimControl(final Spatial spatial) {
            AnimControl animControl = spatial.getControl(AnimControl.class);
            if (animControl == null) {
                return;
            }
            final AnimChannel animChannel = animControl.createChannel();
            animControls.put(spatial.getName(), animControl);
            animChannels.put(spatial.getName(), animChannel);
        }
    };
    character.depthFirstTraversal(visitor);
}
 
开发者ID:bubblecloud,项目名称:jme3-open-asset-pack,代码行数:37,代码来源:AnimationController.java

示例7: addToCharacter

import com.jme3.scene.SceneGraphVisitorAdapter; //导入依赖的package包/类
public void addToCharacter(BuffInfoParameters params) {
    characterNode = (Node) params.buffControl.getSpatial();

    SceneGraphVisitor visitor = new SceneGraphVisitorAdapter() {
        @Override
        public void visit(Geometry geom) {
            Material material = geom.getMaterial();
            MatParam param = material.getParam("Diffuse");
            if (param != null) {
                geometries.add(geom);
                material.setColor("Diffuse", color);
            }
        }
    };

    characterNode.depthFirstTraversal(visitor);

    if (params.justCreated) {
        AudioNode sound = new AudioNode(Globals.assets,
                "Effects/Sound/Petrify.wav");
        sound.setPositional(true);
        sound.setReverbEnabled(false);
        sound.setVolume(1f);
        characterNode.attachChild(sound);
        sound.play();
    }
}
 
开发者ID:TripleSnail,项目名称:Arkhados,代码行数:28,代码来源:PetrifyInfo.java

示例8: addToCharacter

import com.jme3.scene.SceneGraphVisitorAdapter; //导入依赖的package包/类
public void addToCharacter(BuffInfoParameters params) {
    characterNode = (Node) params.buffControl.getSpatial();

    SceneGraphVisitor visitor = new SceneGraphVisitorAdapter() {
        @Override
        public void visit(Geometry geom) {
            Material material = geom.getMaterial();
            MatParam param = material.getParam("Diffuse");
            if (param != null) {
                geometries.add(geom);
                // TODO: Take ghost like entities into account
                geom.setQueueBucket(RenderQueue.Bucket.Transparent);
                material.setColor("Diffuse", color);
                material.getAdditionalRenderState()
                        .setBlendMode(RenderState.BlendMode.Alpha);
            }
        }
    };

    characterNode.depthFirstTraversal(visitor);

    if (params.justCreated) {
        AudioNode sound = new AudioNode(Globals.assets,
                "Effects/Sound/Shadow.wav");
        sound.setPositional(true);
        sound.setReverbEnabled(false);
        sound.setVolume(1f);
        characterNode.attachChild(sound);
        sound.play();
    }
}
 
开发者ID:TripleSnail,项目名称:Arkhados,代码行数:32,代码来源:ShadowInfo.java

示例9: add

import com.jme3.scene.SceneGraphVisitorAdapter; //导入依赖的package包/类
public void add(Spatial sp) {
    sp.depthFirstTraversal(new SceneGraphVisitorAdapter() {
        @Override
        public void visit(Geometry geom) {
            add(geom);
        }
    });
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:9,代码来源:GeometryOptimizer.java

示例10: replaceLocatedTextures

import com.jme3.scene.SceneGraphVisitorAdapter; //导入依赖的package包/类
private void replaceLocatedTextures(Spatial spat, final ProjectAssetManager mgr) {
    spat.depthFirstTraversal(new SceneGraphVisitorAdapter() {
        @Override
        public void visit(Geometry geom) {
            Material mat = geom.getMaterial();
            if (mat != null) {
                Collection<MatParam> params = mat.getParams();
                for (Iterator<MatParam> it = params.iterator(); it.hasNext();) {
                    MatParam matParam = it.next();
                    VarType paramType = matParam.getVarType();
                    String paramName = matParam.getName();
                    switch (paramType) {
                        case Texture2D:
                        case Texture3D:
                        case TextureArray:
                        case TextureBuffer:
                        case TextureCubeMap:
                            try {
                                Texture tex = mat.getTextureParam(paramName).getTextureValue();
                                AssetKey curKey = tex.getKey();
                                UberAssetInfo newInfo = UberAssetLocator.getInfo(curKey);
                                if (newInfo != null) {
                                    if (newInfo.getNewAssetName() != null) {
                                        logger.log(Level.INFO, "Create new key with name {0}", newInfo.getNewAssetName());
                                        TextureKey newKey = new TextureKey(newInfo.getNewAssetName());
                                        Beans.copyProperties(curKey, newKey);
                                        Texture texture = mgr.loadTexture(newKey);
                                        if (texture != null) {
                                            mat.setTextureParam(paramName, paramType, texture);
                                            geom.setMaterial(mat);
                                            logger.log(Level.INFO, "Apply relocated texture {0} for {1}", new Object[]{geom, newKey.getName()});
                                        } else {
                                            logger.log(Level.WARNING, "Could not find relocated texture!");
                                        }
                                    } else {
                                        logger.log(Level.SEVERE, "Don't have name for previously relocated asset {0}, something went wrong!", curKey);
                                    }
                                }
                            } catch (Exception ex) {
                                Exceptions.printStackTrace(ex);
                            }
                            break;
                        default:
                    }
                }
            }
            super.visit(geom);
        }
    });
}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:51,代码来源:ImportModel.java

示例11: registerAction_ShowSkeleton

import com.jme3.scene.SceneGraphVisitorAdapter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void registerAction_ShowSkeleton(SpatialExplorer se, SimpleApplication app) {
	se.treeItemActions.add(new Action("Show Skeleton", (evt) -> {
		Spatial target = ((TreeItem<Spatial>)evt.getSource()).getValue();
		app.enqueue(() -> {
			target.breadthFirstTraversal(new SceneGraphVisitorAdapter(){
				public void visit(Node n) {
					String name = "skeletonDebugger.";
					int i = -1;
					Spatial child;
					do {
						i++;
						child = n.getChild(name + i);
					} while (child != null && !(child instanceof SkeletonDebugger));
					if (child != null) {
						n.detachChild(child);
					} else {
						Skeleton sk = null;
						SkeletonControl sc = n.getControl(SkeletonControl.class);
						if (sc != null) {
							sk = sc.getSkeleton();
						}
						AnimControl control = n.getControl(AnimControl.class);
						if (sk == null && control != null) {
							sk = control.getSkeleton();
						}
						if (sk != null) {
							final SkeletonDebugger skeletonDebug = new SkeletonDebugger(name + i, sk);
							final Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
							mat.setColor("Color", ColorRGBA.Green);
							mat.getAdditionalRenderState().setDepthTest(false);
							skeletonDebug.setMaterial(mat);
							n.attachChild(skeletonDebug);
						}
					}
				}
			});
			return null;
		});
	}));
}
 
开发者ID:davidB,项目名称:jme3_ext_spatial_explorer,代码行数:42,代码来源:Actions4Animation.java


注:本文中的com.jme3.scene.SceneGraphVisitorAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。