com.jme3.scene.Mesh Java Examples

The following examples show how to use com.jme3.scene.Mesh. 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: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/*********************************************************************\
|* Render Calls                                                      *|
\*********************************************************************/
public int convertElementMode(Mesh.Mode mode) {
    switch (mode) {
        case Points:
            return GL_POINTS;
        case Lines:
            return GL_LINES;
        case LineLoop:
            return GL_LINE_LOOP;
        case LineStrip:
            return GL_LINE_STRIP;
        case Triangles:
            return GL_TRIANGLES;
        case TriangleFan:
            return GL_TRIANGLE_FAN;
        case TriangleStrip:
            return GL_TRIANGLE_STRIP;
        default:
            throw new UnsupportedOperationException("Unrecognized mesh mode: " + mode);
    }
}
 
Example #2
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 #3
Source File: TestTriangleStrip.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void simpleInitApp() {
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    Mesh teaMesh = teaGeom.getMesh();
    ModelConverter.generateStrips(teaMesh, true, false, 24, 0);

    // show normals as material
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");

    for (int y = -10; y < 10; y++){
        for (int x = -10; x < 10; x++){
            Geometry teaClone = new Geometry("teapot", teaMesh);
            teaClone.setMaterial(mat);

            teaClone.setLocalTranslation(x * .5f, 0, y * .5f);
            teaClone.setLocalScale(.5f);

            rootNode.attachChild(teaClone);
        }
    }

    cam.setLocation(new Vector3f(8.378951f, 5.4324f, 8.795956f));
    cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
}
 
Example #4
Source File: GenerateTangentsDialog.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected void processOk() {

    final NodeTree<?> nodeTree = getNodeTree();

    final TreeNode<?> node = getNode();
    final Geometry geometry = (Geometry) node.getElement();
    final Mesh newMesh = geometry.getMesh();
    final Mesh oldMesh = newMesh.deepClone();

    final ComboBox<AlgorithmType> algorithmTypeComboBox = getAlgorithmTypeComboBox();
    final AlgorithmType algorithmType = algorithmTypeComboBox.getSelectionModel().getSelectedItem();

    if (algorithmType == AlgorithmType.STANDARD) {
        final CheckBox splitMirroredCheckBox = getSplitMirroredCheckBox();
        TangentGenerator.useStandardGenerator(geometry, splitMirroredCheckBox.isSelected());
    } else {
        TangentGenerator.useMikktspaceGenerator(geometry);
    }

    final ChangeConsumer changeConsumer = notNull(nodeTree.getChangeConsumer());
    changeConsumer.execute(new ChangeMeshOperation(newMesh, oldMesh, geometry));

    super.processOk();
}
 
Example #5
Source File: RagUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Copy Vector3f data for the indexed vertex from the specified vertex
 * buffer.
 * <p>
 * A software skin update is required BEFORE reading vertex
 * positions/normals/tangents from an animated mesh
 *
 * @param mesh subject mesh (not null)
 * @param bufferType which buffer to read (5 legal values)
 * @param vertexIndex index into the mesh's vertices (&ge;0)
 * @param storeResult (modified if not null)
 * @return the data vector (either storeResult or a new instance)
 */
private static Vector3f vertexVector3f(Mesh mesh,
        VertexBuffer.Type bufferType, int vertexIndex,
        Vector3f storeResult) {
    assert bufferType == VertexBuffer.Type.BindPoseNormal
            || bufferType == VertexBuffer.Type.BindPosePosition
            || bufferType == VertexBuffer.Type.Binormal
            || bufferType == VertexBuffer.Type.Normal
            || bufferType == VertexBuffer.Type.Position : bufferType;
    if (storeResult == null) {
        storeResult = new Vector3f();
    }

    VertexBuffer vertexBuffer = mesh.getBuffer(bufferType);
    FloatBuffer floatBuffer = (FloatBuffer) vertexBuffer.getDataReadOnly();
    floatBuffer.position(3 * vertexIndex);
    storeResult.x = floatBuffer.get();
    storeResult.y = floatBuffer.get();
    storeResult.z = floatBuffer.get();

    return storeResult;
}
 
Example #6
Source File: GeometryBatchFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void main(String[] args) {
    Mesh mesh = new Mesh();
    mesh.setBuffer(Type.Position, 3, new float[]{
                0, 0, 0,
                1, 0, 0,
                1, 1, 0,
                0, 1, 0
            });
    mesh.setBuffer(Type.Index, 2, new short[]{
                0, 1,
                1, 2,
                2, 3,
                3, 0
            });

    Geometry g1 = new Geometry("g1", mesh);

    ArrayList<Geometry> geoms = new ArrayList<Geometry>();
    geoms.add(g1);

    Mesh outMesh = new Mesh();
    mergeGeometries(geoms, outMesh);
    printMesh(outMesh);
}
 
Example #7
Source File: SilentTangentBinormalGenerator.java    From OpenRTS with MIT License 6 votes vote down vote up
public static void generate(Spatial scene, boolean splitMirrored) {
	if (scene instanceof Node) {
		Node node = (Node) scene;
		for (Spatial child : node.getChildren()) {
			generate(child, splitMirrored);
		}
	} else {
		Geometry geom = (Geometry) scene;
		Mesh mesh = geom.getMesh();

		// Check to ensure mesh has texcoords and normals before generating
		if (mesh.getBuffer(Type.TexCoord) != null && mesh.getBuffer(Type.Normal) != null) {
			generate(geom.getMesh(), true, splitMirrored);
		}
	}
}
 
Example #8
Source File: RagUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Determine which physics link should manage the specified mesh vertex.
 *
 * @param mesh the mesh containing the vertex (not null, unaffected)
 * @param vertexIndex the vertex index in the mesh (&ge;0)
 * @param iArray temporary storage for bone indices (not null, modified)
 * @param wArray temporary storage for bone weights (not null, modified)
 * @param managerMap a map from bone indices to bone/torso names (not null,
 * unaffected)
 * @return a bone/torso name
 */
private static String findManager(Mesh mesh, int vertexIndex, int[] iArray,
        float[] wArray, String[] managerMap) {
    vertexBoneIndices(mesh, vertexIndex, iArray);
    vertexBoneWeights(mesh, vertexIndex, wArray);
    Map<String, Float> weightMap = weightMap(iArray, wArray, managerMap);

    float bestTotalWeight = Float.NEGATIVE_INFINITY;
    String bestName = null;
    for (Map.Entry<String, Float> entry : weightMap.entrySet()) {
        float totalWeight = entry.getValue();
        if (totalWeight >= bestTotalWeight) {
            bestTotalWeight = totalWeight;
            bestName = entry.getKey();
        }
    }

    return bestName;
}
 
Example #9
Source File: GeometryBatchFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void printMesh(Mesh mesh) {
    for (int bufType = 0; bufType < Type.values().length; bufType++) {
        VertexBuffer outBuf = mesh.getBuffer(Type.values()[bufType]);
        if (outBuf == null) {
            continue;
        }

        System.out.println(outBuf.getBufferType() + ": ");
        for (int vert = 0; vert < outBuf.getNumElements(); vert++) {
            String str = "[";
            for (int comp = 0; comp < outBuf.getNumComponents(); comp++) {
                Object val = outBuf.getElementComponent(vert, comp);
                outBuf.setElementComponent(vert, comp, val);
                val = outBuf.getElementComponent(vert, comp);
                str += val;
                if (comp != outBuf.getNumComponents() - 1) {
                    str += ", ";
                }
            }
            str += "]";
            System.out.println(str);
        }
        System.out.println("------");
    }
}
 
Example #10
Source File: SkeletonControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void resetToBind() {
        for (int i = 0; i < targets.length; i++) {
            Mesh mesh = targets[i];
            if (targets[i].getBuffer(Type.BindPosePosition) != null) {
//                VertexBuffer bi = mesh.getBuffer(Type.BoneIndex);
//                ByteBuffer bib = (ByteBuffer) bi.getData();
//                if (!bib.hasArray())
//                    mesh.prepareForAnim(true); // prepare for software animation

                VertexBuffer bindPos = mesh.getBuffer(Type.BindPosePosition);
                VertexBuffer bindNorm = mesh.getBuffer(Type.BindPoseNormal);
                VertexBuffer pos = mesh.getBuffer(Type.Position);
                VertexBuffer norm = mesh.getBuffer(Type.Normal);
                FloatBuffer pb = (FloatBuffer) pos.getData();
                FloatBuffer nb = (FloatBuffer) norm.getData();
                FloatBuffer bpb = (FloatBuffer) bindPos.getData();
                FloatBuffer bnb = (FloatBuffer) bindNorm.getData();
                pb.clear();
                nb.clear();
                bpb.clear();
                bnb.clear();
                pb.put(bpb).clear();
                nb.put(bnb).clear();
            }
        }
    }
 
Example #11
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void renderMeshVertexArray(Mesh mesh, int lod, int count, VertexBuffer instanceData) {
        if (mesh.getId() == -1) {
            updateVertexArray(mesh, instanceData);
        } else {
            // TODO: Check if it was updated
        }

        if (context.boundVertexArray != mesh.getId()) {
            gl3.glBindVertexArray(mesh.getId());
            context.boundVertexArray = mesh.getId();
        }

//        IntMap<VertexBuffer> buffers = mesh.getBuffers();
        VertexBuffer indices;
        if (mesh.getNumLodLevels() > 0) {
            indices = mesh.getLodLevel(lod);
        } else {
            indices = mesh.getBuffer(Type.Index);
        }
        if (indices != null) {
            drawTriangleList(indices, mesh, count);
        } else {
            drawTriangleArray(mesh.getMode(), count, mesh.getVertexCount());
        }
        clearVertexAttribs();
    }
 
Example #12
Source File: Converter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static Mesh convert(IndexedMesh mesh) {
    Mesh jmeMesh = new Mesh();

    jmeMesh.setBuffer(Type.Index, 3, BufferUtils.createShortBuffer(mesh.numTriangles * 3));
    jmeMesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(mesh.numVertices * 3));

    IndexBuffer indicess = jmeMesh.getIndexBuffer();
    FloatBuffer vertices = jmeMesh.getFloatBuffer(Type.Position);

    for (int i = 0; i < mesh.numTriangles * 3; i++) {
        indicess.put(i, mesh.triangleIndexBase.getInt(i * 4));
    }

    for (int i = 0; i < mesh.numVertices * 3; i++) {
        vertices.put(i, mesh.vertexBase.getFloat(i * 4));
    }
    jmeMesh.updateCounts();
    jmeMesh.updateBound();
    jmeMesh.getFloatBuffer(Type.Position).clear();

    return jmeMesh;
}
 
Example #13
Source File: TestTangentGen.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(20);
    Sphere sphereMesh = new Sphere(32, 32, 1);
    sphereMesh.setTextureMode(Sphere.TextureMode.Projected);
    sphereMesh.updateGeometry(32, 32, 1, false, false);
    addMesh("Sphere", sphereMesh, new Vector3f(-1, 0, 0));

    Quad quadMesh = new Quad(1, 1);
    quadMesh.updateGeometry(1, 1);
    addMesh("Quad", quadMesh, new Vector3f(1, 0, 0));

    Mesh strip = createTriangleStripMesh();
    addMesh("strip", strip, new Vector3f(0, -3, 0));
    
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1, -1, -1).normalizeLocal());
    dl.setColor(ColorRGBA.White);
    rootNode.addLight(dl);
}
 
Example #14
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private int convertElementMode(Mesh.Mode mode) {
    switch (mode) {
        case Points:
            return gl.GL_POINTS;
        case Lines:
            return gl.GL_LINES;
        case LineLoop:
            return gl.GL_LINE_LOOP;
        case LineStrip:
            return gl.GL_LINE_STRIP;
        case Triangles:
            return gl.GL_TRIANGLES;
        case TriangleFan:
            return gl.GL_TRIANGLE_FAN;
        case TriangleStrip:
            return gl.GL_TRIANGLE_STRIP;
        default:
            throw new UnsupportedOperationException("Unrecognized mesh mode: " + mode);
    }
}
 
Example #15
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 #16
Source File: TextureAtlas.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static void applyAtlasCoords(List<Geometry> geometries, Mesh outMesh, TextureAtlas atlas) {
    int globalVertIndex = 0;

    for (Geometry geom : geometries) {
        Mesh inMesh = geom.getMesh();
        geom.computeWorldMatrix();

        int geomVertCount = inMesh.getVertexCount();

        VertexBuffer inBuf = inMesh.getBuffer(Type.TexCoord);
        VertexBuffer outBuf = outMesh.getBuffer(Type.TexCoord);

        if (inBuf == null || outBuf == null) {
            continue;
        }

        atlas.applyCoords(geom, globalVertIndex, outMesh);

        globalVertIndex += geomVertCount;
    }
}
 
Example #17
Source File: TestGeometryShader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Mesh mesh = new Mesh();
    mesh.setBuffer(VertexBuffer.Type.Index, 1, BufferUtils.createIntBuffer(new int[]{1}));
    mesh.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(new float[]{0, 0, 0}));
    mesh.setMode(Mesh.Mode.Points);
    mesh.setBound(new BoundingBox(new Vector3f(0, 0, 0), 10, 10, 10));
    mesh.updateCounts();
    Geometry geometry = new Geometry("Test", mesh);
    geometry.updateGeometricState();
    geometry.setMaterial(new Material(assetManager, "Materials/Geom/SimpleGeom.j3md"));
    //geometry.getMaterial().getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
    //geometry.setMaterial(assetManager.loadMaterial("Materials/Geom/SimpleTess.j3md"));
    rootNode.attachChild(geometry);

    Geometry geometry1 = new Geometry("T1", new Sphere(10, 10, 1));
    geometry1.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    rootNode.attachChild(geometry1);

}
 
Example #18
Source File: UVCoordinatesGenerator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * This method returns the bounding tube of the given mesh.
 * 
 * @param mesh
 *            the mesh
 * @return bounding tube of the given mesh
 */
/* package */static BoundingTube getBoundingTube(Mesh mesh) {
    Vector3f center = new Vector3f();
    float maxx = -Float.MAX_VALUE, minx = Float.MAX_VALUE;
    float maxy = -Float.MAX_VALUE, miny = Float.MAX_VALUE;
    float maxz = -Float.MAX_VALUE, minz = Float.MAX_VALUE;

    FloatBuffer positions = mesh.getFloatBuffer(VertexBuffer.Type.Position);
    int limit = positions.limit();
    for (int i = 0; i < limit; i += 3) {
        float x = positions.get(i);
        float y = positions.get(i + 1);
        float z = positions.get(i + 2);
        center.addLocal(x, y, z);
        maxx = x > maxx ? x : maxx;
        minx = x < minx ? x : minx;
        maxy = y > maxy ? y : maxy;
        miny = y < miny ? y : miny;
        maxz = z > maxz ? z : maxz;
        minz = z < minz ? z : minz;
    }
    center.divideLocal(limit / 3);

    float radius = Math.max(maxx - minx, maxy - miny) * 0.5f;
    return new BoundingTube(radius, maxz - minz, center);
}
 
Example #19
Source File: TestGimpactShape.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private RigidBodyControl drop(Vector3f offset, String model, float scale, float mass) {
    scale *= scaleMod;
    Node n = (Node) assetManager.loadModel(model);
    n.setLocalTranslation(offset);
    n.rotate(0, 0, -FastMath.HALF_PI);

    Geometry tp = ((Geometry) n.getChild(0));
    tp.scale(scale);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    tp.setMaterial(mat);

    Mesh mesh = tp.getMesh();
    GImpactCollisionShape shape = new GImpactCollisionShape(mesh);
    shape.setScale(new Vector3f(scale, scale, scale));

    RigidBodyControl control = new RigidBodyControl(shape, mass);
    n.addControl(control);
    addObject(n);
    return control;
}
 
Example #20
Source File: TestLeakingGL.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf){
    rootNode.detachAllChildren();
    for (int y = -15; y < 15; y++){
        for (int x = -15; x < 15; x++){
            Mesh sphMesh = original.deepClone();
            Geometry sphere = new Geometry("sphere", sphMesh);

            sphere.setMaterial(solidColor);
            sphere.setLocalTranslation(x * 1.5f, 0, y * 1.5f);
            rootNode.attachChild(sphere);
        }
    }
}
 
Example #21
Source File: JmeMesh.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public JmeMesh(Geometry geom, Mesh mesh) {
    super(Children.LEAF);
    this.geom = geom;
    this.mesh = mesh;
    lookupContents.add(geom);
    lookupContents.add(mesh);
    lookupContents.add(this);
    setName("Mesh");
}
 
Example #22
Source File: Converter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static IndexedMesh convert(Mesh mesh) {
    IndexedMesh jBulletIndexedMesh = new IndexedMesh();
    jBulletIndexedMesh.triangleIndexBase = ByteBuffer.allocate(mesh.getTriangleCount() * 3 * 4);
    jBulletIndexedMesh.vertexBase = ByteBuffer.allocate(mesh.getVertexCount() * 3 * 4);

    IndexBuffer indices = mesh.getIndicesAsList();
    
    FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
    vertices.rewind();

    int verticesLength = mesh.getVertexCount() * 3;
    jBulletIndexedMesh.numVertices = mesh.getVertexCount();
    jBulletIndexedMesh.vertexStride = 12; //3 verts * 4 bytes per.
    for (int i = 0; i < verticesLength; i++) {
        float tempFloat = vertices.get();
        jBulletIndexedMesh.vertexBase.putFloat(tempFloat);
    }

    int indicesLength = mesh.getTriangleCount() * 3;
    jBulletIndexedMesh.numTriangles = mesh.getTriangleCount();
    jBulletIndexedMesh.triangleIndexStride = 12; //3 index entries * 4 bytes each.
    for (int i = 0; i < indicesLength; i++) {
        jBulletIndexedMesh.triangleIndexBase.putInt(indices.get(i));
    }
    vertices.rewind();
    vertices.clear();

    return jBulletIndexedMesh;
}
 
Example #23
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 #24
Source File: Curve.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void createLinearMesh() {
    float[] array = new float[spline.getControlPoints().size() * 3];
    short[] indices = new short[(spline.getControlPoints().size() - 1) * 2];
    int i = 0;
    int cpt = 0;
    int k = 0;
    int j = 0;
    for (Iterator<Vector3f> it = spline.getControlPoints().iterator(); it.hasNext();) {
        Vector3f vector3f = it.next();
        array[i] = vector3f.getX();
        i++;
        array[i] = vector3f.getY();
        i++;
        array[i] = vector3f.getZ();
        i++;
        if (it.hasNext()) {
            k = j;
            indices[cpt] = (short) k;
            cpt++;
            k++;
            indices[cpt] = (short) k;
            cpt++;
            j++;
        }
    }

    this.setMode(Mesh.Mode.Lines);
    this.setBuffer(VertexBuffer.Type.Position, 3, array);
    this.setBuffer(VertexBuffer.Type.Index, 2, indices);
    this.updateBound();
    this.updateCounts();
}
 
Example #25
Source File: MeshCollisionShape.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void createCollisionMesh(Mesh mesh, Vector3f worldScale) {
    this.scale = worldScale;
    bulletMesh = Converter.convert(mesh);
    this.numVertices = bulletMesh.numVertices;
    this.numTriangles = bulletMesh.numTriangles;
    this.vertexStride = bulletMesh.vertexStride;
    this.triangleIndexStride = bulletMesh.triangleIndexStride;
    this.triangleIndexBase = bulletMesh.triangleIndexBase;
    this.vertexBase = bulletMesh.vertexBase;
    createShape();
}
 
Example #26
Source File: GeometryOptimizer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void optimize2() {
    for(Mesh mesh : meshSet) {
        mesh.setInterleaved();
        for(VertexBuffer vb : mesh.getBufferList()) {
            System.out.println(
                    "type = "+vb.getBufferType()
                    + "stride = "+vb.getStride()
                    + "offset "+vb.getOffset()
                    );
            
        }
        System.out.println("done");
    }
}
 
Example #27
Source File: ModelConverter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void optimizeScene(Spatial source, boolean toFixed){
    if (source instanceof Geometry){
        Geometry geom = (Geometry) source;
        Mesh mesh = geom.getMesh();
        optimize(mesh, toFixed);
    }else if (source instanceof Node){
        Node node = (Node) source;
        for (int i = node.getQuantity() - 1; i >= 0; i--){
            Spatial child = node.getChild(i);
            optimizeScene(child, toFixed);
        }
    }
}
 
Example #28
Source File: BIHTree.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void read(JmeImporter im) throws IOException {
    InputCapsule ic = im.getCapsule(this);
    mesh = (Mesh) ic.readSavable("mesh", null);
    root = (BIHNode) ic.readSavable("root", null);
    maxTrisPerNode = ic.readInt("tris_per_node", 0);
    pointData = ic.readFloatArray("points", null);
    triIndices = ic.readIntArray("indices", null);
}
 
Example #29
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderMeshVBO(Mesh mesh, int lod, int count) {
    VertexBuffer indices = null;
    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
        updateBufferData(interleavedData);
    }
    IntMap<VertexBuffer> buffers = mesh.getBuffers();
    if (mesh.getNumLodLevels() > 0) {
        indices = mesh.getLodLevel(lod);
    } else {
        indices = buffers.get(Type.Index.ordinal());
    }
    for (Entry<VertexBuffer> entry : buffers) {
        VertexBuffer vb = entry.getValue();

        if (vb.getBufferType() == Type.InterleavedData
                || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
                || vb.getBufferType() == Type.Index) {
            continue;
        }

        if (vb.getStride() == 0) {
            // not interleaved
            setVertexAttribVBO(vb, null);
        } else {
            // interleaved
            setVertexAttribVBO(vb, interleavedData);
        }
    }

    if (indices != null) {
        drawTriangleListVBO(indices, mesh, count);
    } else {
        gl.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
    }
    clearVertexAttribs();
    clearTextureUnits();
}
 
Example #30
Source File: Curve.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createLinearMesh() {
    float[] array = new float[spline.getControlPoints().size() * 3];
    short[] indices = new short[(spline.getControlPoints().size() - 1) * 2];
    int i = 0;
    int cpt = 0;
    int k;
    int j = 0;
    for (Iterator<Vector3f> it = spline.getControlPoints().iterator(); it.hasNext();) {
        Vector3f vector3f = it.next();
        array[i] = vector3f.getX();
        i++;
        array[i] = vector3f.getY();
        i++;
        array[i] = vector3f.getZ();
        i++;
        if (it.hasNext()) {
            k = j;
            indices[cpt] = (short) k;
            cpt++;
            k++;
            indices[cpt] = (short) k;
            cpt++;
            j++;
        }
    }

    this.setMode(Mesh.Mode.Lines);
    this.setBuffer(VertexBuffer.Type.Position, 3, array);
    this.setBuffer(VertexBuffer.Type.Index, 2, indices);
    this.updateBound();
    this.updateCounts();
}