Java Code Examples for com.jme3.scene.Geometry#getName()

The following examples show how to use com.jme3.scene.Geometry#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractModelFileConverter.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Generate names for the materials.
 */
private void generateNames(@NotNull final ObjectDictionary<String, Geometry> mapping,
                           @NotNull final Geometry geometry) {

    final Material material = geometry.getMaterial();
    final String originalName = material.getName();
    final String name = StringUtils.isEmpty(geometry.getName()) ? "geom" : geometry.getName();

    String resultName = StringUtils.isEmpty(originalName) ? "embedded-mat-" + name : originalName;

    if (!mapping.containsKey(resultName)) {
        mapping.put(resultName, geometry);
    } else {
        for (int i = 1; mapping.containsKey(resultName); i++) {
            resultName = (StringUtils.isEmpty(originalName) ? "embedded-mat-" : originalName) + name + "_" + i;
        }
        mapping.put(resultName, geometry);
    }
}
 
Example 2
Source File: AbstractTransformControl.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@JmeThread
protected void detectPickedAxis(@NotNull final EditorTransformSupport editorControl,
                                @NotNull final CollisionResult collisionResult) {

    final Geometry geometry = collisionResult.getGeometry();
    final String geometryName = geometry.getName();

    if (geometryName.contains(getNodeX())) {
        editorControl.setPickedAxis(PickedAxis.X);
    } else if (geometryName.contains(getNodeY())) {
        editorControl.setPickedAxis(PickedAxis.Y);
    } else if (geometryName.contains(getNodeZ())) {
        editorControl.setPickedAxis(PickedAxis.Z);
    }
}
 
Example 3
Source File: SelectionIndicator.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Geometry cloneGeometry( Geometry geom ) {
    // We don't really clone because 1) we are likely to
    // be a control in that hierarchy and that's weird, 2)
    // we don't want to clone the controls, 3) it gives us
    // a chance to give the geometry a better non-lookup-confusing
    // and finally, 4) we only need the mesh anyway.
    Geometry copy = new Geometry( "Indicator:" + geom.getName() );
    copy.setUserData(SelectionState.UD_IGNORE, true);
    copy.setMesh(geom.getMesh());
    copy.setMaterial(material);    
    copyTransforms(copy, geom);
    return copy;
}
 
Example 4
Source File: TestTangentSpace.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createDebugTangents(Geometry geom) {
    Geometry debug = new Geometry(
            "Debug " + geom.getName(),
            TangentBinormalGenerator.genTbnLines(geom.getMesh(), 0.8f)
    );
    Material debugMat = assetManager.loadMaterial("Common/Materials/VertexColor.j3m");
    debug.setMaterial(debugMat);
    debug.setCullHint(Spatial.CullHint.Never);
    debug.getLocalTranslation().set(geom.getWorldTranslation());
    debugNode.attachChild(debug);
}
 
Example 5
Source File: RenderManager.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Preloads a scene for rendering.
 * <p>
 * After invocation of this method, the underlying
 * renderer would have uploaded any textures, shaders and meshes
 * used by the given scene to the video driver. 
 * Using this method is useful when wishing to avoid the initial pause
 * when rendering a scene for the first time. Note that it is not 
 * guaranteed that the underlying renderer will actually choose to upload
 * the data to the GPU so some pause is still to be expected.
 * 
 * @param scene The scene to preload
 */
public void preloadScene(Spatial scene) {
    if (scene instanceof Node) {
        // recurse for all children
        Node n = (Node) scene;
        List<Spatial> children = n.getChildren();
        for (int i = 0; i < children.size(); i++) {
            preloadScene(children.get(i));
        }
    } else if (scene instanceof Geometry) {
        // add to the render queue
        Geometry gm = (Geometry) scene;
        if (gm.getMaterial() == null) {
            throw new IllegalStateException("No material is set for Geometry: " + gm.getName());
        }

        gm.getMaterial().preload(this);
        Mesh mesh = gm.getMesh();
        if (mesh != null) {
            for (Entry<VertexBuffer> entry : mesh.getBuffers()) {
                VertexBuffer buf = entry.getValue();
                if (buf.getData() != null) {
                    renderer.updateBufferData(buf);
                }
            }
        }
    }
}
 
Example 6
Source File: ModelImportDialog.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
/**
 * Export all embedded materials from the external model.
 *
 * @param materialsFolder    the materials folder.
 * @param overwriteMaterials true if we can overwrite existing materials.
 * @param geometries         the found geometries in the model.
 */
@BackgroundThread
private void exportMaterials(@NotNull final Path materialsFolder, final boolean overwriteMaterials,
                             @NotNull final Array<Geometry> geometries) {

    if (geometries.isEmpty()) {
        return;
    }

    final ObjectDictionary<String, String> resultNameToKey = DictionaryFactory.newObjectDictionary();

    for (final Geometry geometry : geometries) {

        final Material material = geometry.getMaterial();
        final String originalName = material.getName();
        final String name = StringUtils.isEmpty(geometry.getName()) ? "geom" : geometry.getName();
        final String resultName = StringUtils.isEmpty(originalName) ? "embedded-mat-" + name : originalName;

        final String newKey = resultNameToKey.get(resultName);
        if (newKey != null) {
            material.setKey(new MaterialKey(newKey));
            continue;
        }

        final Path resultFile = materialsFolder.resolve(resultName + "." + FileExtensions.JME_MATERIAL);

        if (!Files.exists(resultFile) || overwriteMaterials) {
            try (PrintWriter pout = new PrintWriter(Files.newOutputStream(resultFile, WRITE, TRUNCATE_EXISTING, CREATE))) {
                pout.println(MaterialSerializer.serializeToString(material));
            } catch (final IOException e) {
                throw new RuntimeException(e);
            }
        }

        final Path assetFile = notNull(getAssetFile(resultFile));
        final String assetPath = toAssetPath(assetFile);

        material.setKey(new MaterialKey(assetPath));
        resultNameToKey.put(resultName, assetPath);
    }
}
 
Example 7
Source File: RenderManager.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Flattens the given scene graph into the ViewPort's RenderQueue,
 * checking for culling as the call goes down the graph recursively.
 * <p>
 * First, the scene is checked for culling based on the <code>Spatial</code>s
 * {@link Spatial#setCullHint(com.jme3.scene.Spatial.CullHint) cull hint},
 * if the camera frustum contains the scene, then this method is recursively
 * called on its children.
 * <p>
 * When the scene's leaves or {@link Geometry geometries} are reached,
 * they are each enqueued into the 
 * {@link ViewPort#getQueue() ViewPort's render queue}.
 * <p>
 * In addition to enqueuing the visible geometries, this method
 * also scenes which cast or receive shadows, by putting them into the
 * RenderQueue's 
 * {@link RenderQueue#addToShadowQueue(com.jme3.scene.Geometry, com.jme3.renderer.queue.RenderQueue.ShadowMode) 
 * shadow queue}. Each Spatial which has its 
 * {@link Spatial#setShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode) shadow mode}
 * set to not off, will be put into the appropriate shadow queue, note that
 * this process does not check for frustum culling on any 
 * {@link ShadowMode#Cast shadow casters}, as they don't have to be
 * in the eye camera frustum to cast shadows on objects that are inside it.
 * 
 * @param scene The scene to flatten into the queue
 * @param vp The ViewPort provides the {@link ViewPort#getCamera() camera}
 * used for culling and the {@link ViewPort#getQueue() queue} used to 
 * contain the flattened scene graph.
 */
public void renderScene(Spatial scene, ViewPort vp) {
    if (scene.getParent() == null) {
        vp.getCamera().setPlaneState(0);
    }
    // check culling first.
    if (!scene.checkCulling(vp.getCamera())) {
        // move on to shadow-only render
        if ((scene.getShadowMode() != RenderQueue.ShadowMode.Off || scene instanceof Node) && scene.getCullHint()!=Spatial.CullHint.Always) {
            renderShadow(scene, vp.getQueue());
        }
        return;
    }

    scene.runControlRender(this, vp);
    if (scene instanceof Node) {
        // recurse for all children
        Node n = (Node) scene;
        List<Spatial> children = n.getChildren();
        //saving cam state for culling
        int camState = vp.getCamera().getPlaneState();
        for (int i = 0; i < children.size(); i++) {
            //restoring cam state before proceeding children recusively
            vp.getCamera().setPlaneState(camState);
            renderScene(children.get(i), vp);

        }
    } else if (scene instanceof Geometry) {

        // add to the render queue
        Geometry gm = (Geometry) scene;
        if (gm.getMaterial() == null) {
            throw new IllegalStateException("No material is set for Geometry: " + gm.getName());
        }

        vp.getQueue().addToQueue(gm, scene.getQueueBucket());

        // add to shadow queue if needed
        RenderQueue.ShadowMode shadowMode = scene.getShadowMode();
        if (shadowMode != RenderQueue.ShadowMode.Off) {
            vp.getQueue().addToShadowQueue(gm, shadowMode);
        }
    }
}