sharedmesh.java

来自「java 3d game jme 工程开发源代码」· Java 代码 · 共 639 行 · 第 1/2 页

JAVA
639
字号
     * 
     * @param indices
     *            the index array as an IntBuffer.
     */
    @Override
    public void setIndexBuffer(IntBuffer indices) {
        logger.warning("SharedMesh does not allow the manipulation"
                + "of the the mesh data.");
    }

    /**
     * Stores in the <code>storage</code> array the indices of triangle
     * <code>i</code>. If <code>i</code> is an invalid index, or if
     * <code>storage.length<3</code>, then nothing happens
     * 
     * @param i
     *            The index of the triangle to get.
     * @param storage
     *            The array that will hold the i's indexes.
     */
    @Override
    public void getTriangle(int i, int[] storage) {
        target.getTriangle(i, storage);
    }

    /**
     * Stores in the <code>vertices</code> array the vertex values of triangle
     * <code>i</code>. If <code>i</code> is an invalid triangle index,
     * nothing happens.
     * 
     * @param i
     * @param vertices
     */
    @Override
    public void getTriangle(int i, Vector3f[] vertices) {
        target.getTriangle(i, vertices);
    }

    /**
     * Returns the number of triangles the target TriMesh contains.
     * 
     * @return The current number of triangles.
     */
    @Override
    public int getTriangleCount() {
        return target.getTriangleCount();
    }

    /**
     * <code>copyTextureCoords</code> is not supported by SharedMesh.
     * 
     * @param fromIndex
     *            the coordinates to copy.
     * @param toIndex
     *            the texture unit to set them to.
     */
    @Override
    public void copyTextureCoordinates(int fromIndex, int toIndex, float factor) {
        logger.warning("SharedMesh does not allow the manipulation"
                + "of the the mesh data.");
    }

    /**
     * <code>getTextureBuffers</code> retrieves the target geometry's texture
     * information contained within a float buffer array.
     * 
     * @return the float buffers that contain the target geometry's texture
     *         information.
     */
    @Override
    public ArrayList<TexCoords> getTextureCoords() {
        return target.getTextureCoords();
    }

    /**
     * <code>getTextureAsFloatBuffer</code> retrieves the texture buffer of a
     * given texture unit.
     * 
     * @param textureUnit
     *            the texture unit to check.
     * @return the texture coordinates at the given texture unit.
     */
    @Override
    public TexCoords getTextureCoords(int textureUnit) {
        return target.getTextureCoords(textureUnit);
    }

    /**
     * retrieves the mesh as triangle vertices of the target mesh.
     */
    @Override
    public Vector3f[] getMeshAsTrianglesVertices(Vector3f[] verts) {
        return target.getMeshAsTrianglesVertices(verts);
    }

    /**
     * clearBuffers is not supported by SharedMesh
     */
    @Override
    public void clearBuffers() {
        logger.warning("SharedMesh does not allow the manipulation"
                + "of the the mesh data.");
    }

    /**
     * This function checks for intersection between the target trimesh and the
     * given one. On the first intersection, true is returned.
     * 
     * @param toCheck
     *            The intersection testing mesh.
     * @return True if they intersect.
     */
    @Override
    public boolean hasTriangleCollision(TriMesh toCheck) {
        target.setLocalTranslation(worldTranslation);
        target.setLocalRotation(worldRotation);
        target.setLocalScale(worldScale);
        target.updateWorldBound();
        return target.hasTriangleCollision(toCheck);
    }

    /**
     * This function finds all intersections between this trimesh and the
     * checking one. The intersections are stored as Integer objects of Triangle
     * indexes in each of the parameters.
     * 
     * @param toCheck
     *            The TriMesh to check.
     * @param thisIndex
     *            The array of triangle indexes intersecting in this mesh.
     * @param otherIndex
     *            The array of triangle indexes intersecting in the given mesh.
     */
    @Override
    public void findTriangleCollision(TriMesh toCheck,
            ArrayList<Integer> thisIndex, ArrayList<Integer> otherIndex) {
        target.setLocalTranslation(worldTranslation);
        target.setLocalRotation(worldRotation);
        target.setLocalScale(worldScale);
        target.updateWorldBound();
        target.findTriangleCollision(toCheck, thisIndex, otherIndex);
    }

    /**
     * <code>findTrianglePick</code> determines the triangles of the target
     * trimesh that are being touched by the ray. The indices of the triangles
     * are stored in the provided ArrayList.
     * 
     * @param toTest
     *            the ray to test.
     * @param results
     *            the indices to the triangles.
     */
    @Override
    public void findTrianglePick(Ray toTest, ArrayList<Integer> results) {
        target.setLocalTranslation(worldTranslation);
        target.setLocalRotation(worldRotation);
        target.setLocalScale(worldScale);
        target.updateWorldBound();
        target.findTrianglePick(toTest, results);
    }

    @Override
    public void write(JMEExporter e) throws IOException {
        OutputCapsule capsule = e.getCapsule(this);
        capsule.write(target, "target", null);
        super.write(e);
    }

    @Override
    public void read(JMEImporter e) throws IOException {
        InputCapsule capsule = e.getCapsule(this);
        target = (TriMesh) capsule.readSavable("target", null);
        super.read(e);
    }

    /**
     * @see Geometry#randomVertex(Vector3f)
     */
    @Override
    public Vector3f randomVertex(Vector3f fill) {
        return target.randomVertex(fill);
    }

    /**
     * <code>setTextureBuffer</code> is not supported by SharedMesh.
     * 
     * @param buff
     *            the new vertex buffer.
     */
    @Override
    public void setTextureCoords(TexCoords buff) {
        logger.warning("SharedMesh does not allow the manipulation"
                + "of the the mesh data.");
    }

    /**
     * <code>setTextureBuffer</code> not supported by SharedMesh
     * 
     * @param buff
     *            the new vertex buffer.
     */
    @Override
    public void setTextureCoords(TexCoords buff, int position) {
        logger.warning("SharedMesh does not allow the manipulation"
                + "of the the mesh data.");
    }

    @Override
    public void setTangentBuffer(FloatBuffer tangentBuf) {
        logger.warning("SharedMesh does not allow the manipulation"
                + "of the the mesh data.");
    }

    @Override
    public FloatBuffer getTangentBuffer() {
        return target.getTangentBuffer();
    }

    @Override
    public void setBinormalBuffer(FloatBuffer binormalBuf) {
        logger.warning("SharedMesh does not allow the manipulation"
                + "of the the mesh data.");
    }

    @Override
    public FloatBuffer getBinormalBuffer() {
        return target.getBinormalBuffer();
    }

    /**
     * <code>updateWorldBound</code> updates the bounding volume that contains
     * this geometry. The location of the geometry is based on the location of
     * all this node's parents.
     * 
     * @see com.jme.scene.Spatial#updateWorldBound()
     */
    @Override
    public void updateWorldBound() {
        if (target.getModelBound() != null) {
            worldBound = target.getModelBound().transform(getWorldRotation(),
                    getWorldTranslation(), getWorldScale(), worldBound);
        }
    }

    /**
     * <code>setModelBound</code> sets the bounding object for this geometry.
     * 
     * @param modelBound
     *            the bounding object for this geometry.
     */
    @Override
    public void setModelBound(BoundingVolume modelBound) {
        target.setModelBound(modelBound);
    }

    /**
     * <code>updateBound</code> recalculates the bounding object assigned to
     * the geometry. This resets it parameters to adjust for any changes to the
     * vertex information.
     */
    @Override
    public void updateModelBound() {
        if (target.getModelBound() != null) {
            target.updateModelBound();
            updateWorldBound();
        }
    }

    /**
     * returns the model bound of the target object.
     */
    @Override
    public BoundingVolume getModelBound() {
        return target.getModelBound();
    }

    /**
     * draw renders the target mesh, at the translation, rotation and scale of
     * this shared mesh.
     * 
     * @see com.jme.scene.Spatial#draw(com.jme.renderer.Renderer)
     */
    @Override
    public void draw(Renderer r) {
        if (!r.isProcessingQueue()) {
            if (r.checkAndAdd(this))
                return;
        }

        target.getWorldTranslation().set(getWorldTranslation());
        target.getWorldRotation().set(getWorldRotation());
        target.getWorldScale().set(getWorldScale());
        target.setDefaultColor(getDefaultColor());
        System.arraycopy(this.states, 0, target.states, 0, states.length);

        r.draw(target);
    }

    @Override
    public void lockMeshes(Renderer r) {
        target.lockMeshes(r);
    }

    @Override
    public boolean hasDirtyVertices() {
        return target.hasDirtyVertices;
    }

    @Override
    public ColorRGBA getDefaultColor() {
        if (defaultColor == null) {
            return target.getDefaultColor();
        } else {
            return defaultColor;
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?