Java Code Examples for com.jme3.scene.Mesh#getMode()

The following examples show how to use com.jme3.scene.Mesh#getMode() . 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: WrappedIndexBuffer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public WrappedIndexBuffer(Mesh mesh){
    super(mesh.getVertexCount(), mesh.getMode());
    this.ib = mesh.getIndexBuffer();
    switch (meshMode){
        case Points:
            numIndices = mesh.getTriangleCount();
            break;
        case Lines:
        case LineLoop:
        case LineStrip:
            numIndices = mesh.getTriangleCount() * 2;
            break;
        case Triangles:
        case TriangleStrip:
        case TriangleFan:
            numIndices = mesh.getTriangleCount() * 3;
            break;
        default:
            throw new UnsupportedOperationException();
    }
}
 
Example 2
Source File: WrappedIndexBuffer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void convertToList(Mesh mesh){
    IndexBuffer inBuf = mesh.getIndicesAsList();
    IndexBuffer outBuf = IndexBuffer.createIndexBuffer(mesh.getVertexCount(),
                                                       inBuf.size());

    for (int i = 0; i < inBuf.size(); i++){
        outBuf.put(i, inBuf.get(i));
    }

    mesh.clearBuffer(Type.Index);
    switch (mesh.getMode()){
        case LineLoop:
        case LineStrip:
            mesh.setMode(Mode.Lines);
            break;
        case TriangleStrip:
        case TriangleFan:
            mesh.setMode(Mode.Triangles);
            break;
        default:
            break;
    }
    mesh.setBuffer(Type.Index, 3, outBuf.getFormat(), outBuf.getBuffer());
}
 
Example 3
Source File: BIHTree.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public BIHTree(Mesh mesh, int maxTrisPerNode) {
    this.mesh = mesh;
    this.maxTrisPerNode = maxTrisPerNode;

    if (maxTrisPerNode < 1 || mesh == null) {
        throw new IllegalArgumentException();
    }

    bihSwapTmp = new float[9];

    FloatBuffer vb = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
    IndexBuffer ib = mesh.getIndexBuffer();
    if (ib == null) {
        ib = new VirtualIndexBuffer(mesh.getVertexCount(), mesh.getMode());
    } else if (mesh.getMode() != Mode.Triangles) {
        ib = new WrappedIndexBuffer(mesh);
    }

    numTris = ib.size() / 3;
    initTriList(vb, ib);
}
 
Example 4
Source File: WrappedIndexBuffer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public WrappedIndexBuffer(Mesh mesh){
    super(mesh.getVertexCount(), mesh.getMode());
    this.ib = mesh.getIndexBuffer();
    switch (meshMode){
        case Points:
            numIndices = mesh.getTriangleCount();
            break;
        case Lines:
        case LineLoop:
        case LineStrip:
            numIndices = mesh.getTriangleCount() * 2;
            break;
        case Triangles:
        case TriangleStrip:
        case TriangleFan:
            numIndices = mesh.getTriangleCount() * 3;
            break;
        default:
            throw new UnsupportedOperationException();
    }
}
 
Example 5
Source File: BIHTree.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public BIHTree(Mesh mesh, int maxTrisPerNode) {
    this.mesh = mesh;
    this.maxTrisPerNode = maxTrisPerNode;

    if (maxTrisPerNode < 1) {
        throw new IllegalArgumentException("maxTrisPerNode cannot be less than 1");
    }
    if (mesh == null) {
        throw new IllegalArgumentException("Mesh cannot be null");
    }

    bihSwapTmp = new float[9];

    VertexBuffer vBuffer = mesh.getBuffer(Type.Position);
    if(vBuffer == null){
        throw new IllegalArgumentException("A mesh should at least contain a Position buffer");
    }        
    IndexBuffer ib = mesh.getIndexBuffer();
    FloatBuffer vb = (FloatBuffer) vBuffer.getData();
    
    if (ib == null) {
        ib = new VirtualIndexBuffer(mesh.getVertexCount(), mesh.getMode());
    } else if (mesh.getMode() != Mode.Triangles) {
        ib = new WrappedIndexBuffer(mesh);
    }

    numTris = ib.size() / 3;
    initTriList(vb, ib);
}
 
Example 6
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void drawTriangleList(VertexBuffer indexBuf, Mesh mesh, int count) {
        Mesh.Mode mode = mesh.getMode();

        Buffer indexData = indexBuf.getData();
        indexData.clear();
        if (mesh.getMode() == Mode.Hybrid) {
            int[] modeStart = mesh.getModeStart();
            int[] elementLengths = mesh.getElementLengths();

            int elMode = convertElementMode(Mode.Triangles);
            int fmt = convertVertexFormat(indexBuf.getFormat());
//            int elSize = indexBuf.getFormat().getComponentSize();
//            int listStart = modeStart[0];
            int stripStart = modeStart[1];
            int fanStart = modeStart[2];
            int curOffset = 0;
            for (int i = 0; i < elementLengths.length; i++) {
                if (i == stripStart) {
                    elMode = convertElementMode(Mode.TriangleStrip);
                } else if (i == fanStart) {
                    elMode = convertElementMode(Mode.TriangleStrip);
                }
                int elementLength = elementLengths[i];
                indexData.position(curOffset);
                gl.glDrawElements(elMode,
                        elementLength,
                        fmt,
                        indexData);
                curOffset += elementLength;
            }
        } else {
            gl.glDrawElements(convertElementMode(mode),
                    indexData.capacity(),
                    convertVertexFormat(indexBuf.getFormat()),
                    indexData);
        }
    }
 
Example 7
Source File: AbstractRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void drawTriangleList(VertexBuffer indexBuf, Mesh mesh, int count) {
    Mesh.Mode mode = mesh.getMode();
    Buffer indexData = indexBuf.getData();
    indexData.clear();
    if (mesh.getMode() == Mode.Hybrid) {
        int[] modeStart = mesh.getModeStart();
        int[] elementLengths = mesh.getElementLengths();

        Mode elMode = Mode.Triangles;
        // int elSize = indexBuf.getFormat().getComponentSize();
        // int listStart = modeStart[0];
        int stripStart = modeStart[1];
        int fanStart = modeStart[2];
        int curOffset = 0;
        for (int i = 0; i < elementLengths.length; i++) {
            if (i == stripStart) {
                elMode = Mode.TriangleStrip;
            }
            else if (i == fanStart) {
                elMode = Mode.TriangleStrip;
            }
            int elementLength = elementLengths[i];
            indexData.position(curOffset);
            drawElements(elMode, elementLength, indexBuf.getFormat(), indexData);
            curOffset += elementLength;
        }
    }
    else {
        drawElements(mode, indexData.capacity(), indexBuf.getFormat(), indexData);
    }
}
 
Example 8
Source File: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void renderMesh(Mesh mesh, int lod, int count) {
        if (mesh.getVertexCount() == 0) {
            return;
        }

        if (context.pointSprite && mesh.getMode() != Mode.Points){
            // XXX: Hack, disable point sprite mode if mesh not in point mode
            if (context.boundTextures[0] != null){
                if (context.boundTextureUnit != 0){
                    glActiveTexture(GL_TEXTURE0);
                    context.boundTextureUnit = 0;
                }
                glDisable(GL_POINT_SPRITE);
                glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
                context.pointSprite = false;
            }
        }

        if (context.pointSize != mesh.getPointSize()) {
            glPointSize(mesh.getPointSize());
            context.pointSize = mesh.getPointSize();
        }
        if (context.lineWidth != mesh.getLineWidth()) {
            glLineWidth(mesh.getLineWidth());
            context.lineWidth = mesh.getLineWidth();
        }

        statistics.onMeshDrawn(mesh, lod);
//        if (GLContext.getCapabilities().GL_ARB_vertex_array_object){
//            renderMeshVertexArray(mesh, lod, count);
//        }else{
            renderMeshDefault(mesh, lod, count);
//        }
    }
 
Example 9
Source File: WrappedIndexBuffer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void convertToList(Mesh mesh){
    IndexBuffer inBuf = mesh.getIndicesAsList();
    IndexBuffer outBuf = IndexBuffer.createIndexBuffer(mesh.getVertexCount(),
                                                       inBuf.size());

    for (int i = 0; i < inBuf.size(); i++){
        outBuf.put(i, inBuf.get(i));
    }

    mesh.clearBuffer(Type.Index);
    switch (mesh.getMode()){
        case LineLoop:
        case LineStrip:
            mesh.setMode(Mode.Lines);
            break;
        case TriangleStrip:
        case TriangleFan:
            mesh.setMode(Mode.Triangles);
            break;
        default:
            break;
    }
    if (outBuf instanceof IndexIntBuffer){
        mesh.setBuffer(Type.Index, 3, (IntBuffer)outBuf.getBuffer());
    }else{
        mesh.setBuffer(Type.Index, 3, (ShortBuffer)outBuf.getBuffer());
    }
}
 
Example 10
Source File: TangentBinormalGenerator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void generate(Mesh mesh, boolean approxTangents) {
    int[] index = new int[3];
    Vector3f[] v = new Vector3f[3];
    Vector2f[] t = new Vector2f[3];
    for (int i = 0; i < 3; i++) {
        v[i] = new Vector3f();
        t[i] = new Vector2f();
    }
    
    if (mesh.getBuffer(Type.Normal) == null){
        throw new IllegalArgumentException("The given mesh has no normal data!");
    }

    VertexData[] vertices;
    switch (mesh.getMode()) {
        case Triangles:
            vertices = processTriangles(mesh, index, v, t); break;
        case TriangleStrip:
            vertices = processTriangleStrip(mesh, index, v, t); break;
        case TriangleFan:
            vertices = processTriangleFan(mesh, index, v, t); break;
        default: throw new UnsupportedOperationException(
                mesh.getMode() + " is not supported.");
    }

    processTriangleData(mesh, vertices, approxTangents);
}
 
Example 11
Source File: MeshPropertyBuilder.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@Override
@FxThread
protected void buildForImpl(@NotNull final Object object, @Nullable final Object parent, @NotNull final VBox container,
                            @NotNull final ModelChangeConsumer changeConsumer) {

    if (!(object instanceof Mesh)) return;

    final Mesh mesh = (Mesh) object;
    final Mesh.Mode mode = mesh.getMode();

    final int id = mesh.getId();
    final int instanceCount = mesh.getInstanceCount();
    final int vertexCount = mesh.getVertexCount();
    final int numLodLevels = mesh.getNumLodLevels();
    final int triangleCount = mesh.getTriangleCount();

    final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> idControl =
            new DefaultSinglePropertyControl<>(id, Messages.MODEL_PROPERTY_ID, changeConsumer);

    idControl.setSyncHandler(Mesh::getId);
    idControl.setToStringFunction(value -> Integer.toString(value));
    idControl.setEditObject(mesh);

    final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> instanceCountControl =
            new DefaultSinglePropertyControl<>(instanceCount, Messages.MODEL_PROPERTY_INSTANCE_COUNT, changeConsumer);

    instanceCountControl.setSyncHandler(Mesh::getInstanceCount);
    instanceCountControl.setToStringFunction(value -> Integer.toString(value));
    instanceCountControl.setEditObject(mesh);

    final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> vertexCountControl =
            new DefaultSinglePropertyControl<>(vertexCount, Messages.MODEL_PROPERTY_VERTEX_COUNT, changeConsumer);

    vertexCountControl.setSyncHandler(Mesh::getVertexCount);
    vertexCountControl.setToStringFunction(value -> Integer.toString(value));
    vertexCountControl.setEditObject(mesh);

    final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> triangleCountControl =
            new DefaultSinglePropertyControl<>(triangleCount, Messages.MODEL_PROPERTY_TRIANGLE_COUNT, changeConsumer);

    triangleCountControl.setSyncHandler(Mesh::getTriangleCount);
    triangleCountControl.setToStringFunction(value -> Integer.toString(value));
    triangleCountControl.setEditObject(mesh);

    final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> numLodLevelsControl =
            new DefaultSinglePropertyControl<>(numLodLevels, Messages.MODEL_PROPERTY_NUM_LOD_LEVELS, changeConsumer);

    numLodLevelsControl.setSyncHandler(Mesh::getNumLodLevels);
    numLodLevelsControl.setToStringFunction(value -> Integer.toString(value));
    numLodLevelsControl.setEditObject(mesh);

    final EnumPropertyControl<ModelChangeConsumer, Mesh, Mesh.Mode> modeControl =
            new EnumPropertyControl<>(mode, Messages.MODEL_PROPERTY_MODE, changeConsumer, MODES);
    modeControl.setApplyHandler(Mesh::setMode);
    modeControl.setSyncHandler(Mesh::getMode);
    modeControl.setEditObject(mesh);

    FXUtils.addToPane(idControl, container);
    FXUtils.addToPane(instanceCountControl, container);
    FXUtils.addToPane(vertexCountControl, container);
    FXUtils.addToPane(triangleCountControl, container);
    FXUtils.addToPane(numLodLevelsControl, container);
    FXUtils.addToPane(modeControl, container);
}
 
Example 12
Source File: SilentTangentBinormalGenerator.java    From OpenRTS with MIT License 4 votes vote down vote up
public static void generate(Mesh mesh, boolean approxTangents, boolean splitMirrored) {
	int[] index = new int[3];
	Vector3f[] v = new Vector3f[3];
	Vector2f[] t = new Vector2f[3];
	for (int i = 0; i < 3; i++) {
		v[i] = new Vector3f();
		t[i] = new Vector2f();
	}

	if (mesh.getBuffer(Type.Normal) == null) {
		throw new IllegalArgumentException("The given mesh has no normal data!");
	}

	List<VertexData> vertices;
	switch (mesh.getMode()) {
		case Triangles:
			vertices = processTriangles(mesh, index, v, t, splitMirrored);
			if (splitMirrored) {
				splitVertices(mesh, vertices, splitMirrored);
			}
			break;
		case TriangleStrip:
			vertices = processTriangleStrip(mesh, index, v, t);
			break;
		case TriangleFan:
			vertices = processTriangleFan(mesh, index, v, t);
			break;
		default:
			throw new UnsupportedOperationException(mesh.getMode() + " is not supported.");
	}

	processTriangleData(mesh, vertices, approxTangents, splitMirrored);

	// if the mesh has a bind pose, we need to generate the bind pose for the tangent buffer
	if (mesh.getBuffer(Type.BindPosePosition) != null) {

		VertexBuffer tangents = mesh.getBuffer(Type.Tangent);
		if (tangents != null) {
			VertexBuffer bindTangents = new VertexBuffer(Type.BindPoseTangent);
			bindTangents.setupData(Usage.CpuOnly, 4, Format.Float, BufferUtils.clone(tangents.getData()));

			if (mesh.getBuffer(Type.BindPoseTangent) != null) {
				mesh.clearBuffer(Type.BindPoseTangent);
			}
			mesh.setBuffer(bindTangents);
			tangents.setUsage(Usage.Stream);
		}
	}
}
 
Example 13
Source File: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * drawTriangleList_Array uses Vertex Array
 * @param indexBuf
 * @param mesh
 * @param count
 */
public void drawTriangleList_Array(VertexBuffer indexBuf, Mesh mesh, int count) {
    if (verboseLogging) {
        logger.log(Level.INFO, "drawTriangleList_Array(Count = {0})", count);
    }

    if (indexBuf.getBufferType() != Type.Index) {
        throw new IllegalArgumentException("Only index buffers are allowed as triangle lists.");
    }

    boolean useInstancing = count > 1 && caps.contains(Caps.MeshInstancing);
    if (useInstancing) {
        throw new IllegalArgumentException("Caps.MeshInstancing is not supported.");
    }

    int vertCount = mesh.getVertexCount();
    Buffer indexData = indexBuf.getData();
    indexData.clear();

    if (mesh.getMode() == Mode.Hybrid) {
        int[] modeStart = mesh.getModeStart();
        int[] elementLengths = mesh.getElementLengths();

        int elMode = convertElementMode(Mode.Triangles);
        int fmt = convertFormat(indexBuf.getFormat());
        int elSize = indexBuf.getFormat().getComponentSize();
        int listStart = modeStart[0];
        int stripStart = modeStart[1];
        int fanStart = modeStart[2];
        int curOffset = 0;
        for (int i = 0; i < elementLengths.length; i++) {
            if (i == stripStart) {
                elMode = convertElementMode(Mode.TriangleStrip);
            } else if (i == fanStart) {
                elMode = convertElementMode(Mode.TriangleStrip);
            }
            int elementLength = elementLengths[i];

            indexBuf.getData().position(curOffset);
            if (verboseLogging) {
                logger.log(Level.INFO, "glDrawElements(): {0}, {1}", new Object[]{elementLength, curOffset});
            }

            Gdx.gl20.glDrawElements(elMode, elementLength, fmt, indexBuf.getData());

            curOffset += elementLength * elSize;
        }
    } else {
        if (verboseLogging) {
            logger.log(Level.INFO, "glDrawElements(), indexBuf.capacity ({0}), vertCount ({1})", new Object[]{indexBuf.getData().capacity(), vertCount});
        }

        Gdx.gl20.glDrawElements(
                convertElementMode(mesh.getMode()),
                indexBuf.getData().capacity(),
                convertFormat(indexBuf.getFormat()),
                indexBuf.getData());
    }
}
 
Example 14
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * drawTriangleList_Array uses Vertex Array
 * @param indexBuf
 * @param mesh
 * @param count
 */
public void drawTriangleList_Array(VertexBuffer indexBuf, Mesh mesh, int count) {
    if (verboseLogging) {
        logger.log(Level.INFO, "drawTriangleList_Array(Count = {0})", count);
    }

    if (indexBuf.getBufferType() != VertexBuffer.Type.Index) {
        throw new IllegalArgumentException("Only index buffers are allowed as triangle lists.");
    }

    boolean useInstancing = count > 1 && caps.contains(Caps.MeshInstancing);
    if (useInstancing) {
        throw new IllegalArgumentException("Caps.MeshInstancing is not supported.");
    }

    int vertCount = mesh.getVertexCount();
    Buffer indexData = indexBuf.getData();
    indexData.clear();

    if (mesh.getMode() == Mode.Hybrid) {
        int[] modeStart = mesh.getModeStart();
        int[] elementLengths = mesh.getElementLengths();

        int elMode = convertElementMode(Mode.Triangles);
        int fmt = convertFormat(indexBuf.getFormat());
        int elSize = indexBuf.getFormat().getComponentSize();
        int listStart = modeStart[0];
        int stripStart = modeStart[1];
        int fanStart = modeStart[2];
        int curOffset = 0;
        for (int i = 0; i < elementLengths.length; i++) {
            if (i == stripStart) {
                elMode = convertElementMode(Mode.TriangleStrip);
            } else if (i == fanStart) {
                elMode = convertElementMode(Mode.TriangleStrip);
            }
            int elementLength = elementLengths[i];

            indexBuf.getData().position(curOffset);
            if (verboseLogging) {
                logger.log(Level.INFO, "glDrawElements(): {0}, {1}", new Object[]{elementLength, curOffset});
            }

            GLES20.glDrawElements(elMode, elementLength, fmt, indexBuf.getData());

            curOffset += elementLength * elSize;
        }
    } else {
        if (verboseLogging) {
            logger.log(Level.INFO, "glDrawElements(), indexBuf.capacity ({0}), vertCount ({1})", new Object[]{indexBuf.getData().capacity(), vertCount});
        }

        GLES20.glDrawElements(
                convertElementMode(mesh.getMode()),
                indexBuf.getData().capacity(),
                convertFormat(indexBuf.getFormat()),
                indexBuf.getData());
    }
}