com.jme3.scene.VertexBuffer.Usage Java Examples
The following examples show how to use
com.jme3.scene.VertexBuffer.Usage.
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: JmeBatchRenderBackend.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
public Batch() { // setup mesh vertexPos.setupData(Usage.Stream, 2, VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(BATCH_MAX_VERTICES * 2)); vertexPosBuffer = (FloatBuffer) vertexPos.getData(); mesh.setBuffer(vertexPos); vertexTexCoord.setupData(Usage.Stream, 2, VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(BATCH_MAX_VERTICES * 2)); vertexTexCoordBuffer = (FloatBuffer) vertexTexCoord.getData(); mesh.setBuffer(vertexTexCoord); vertexColor.setupData(Usage.Stream, 4, VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(BATCH_MAX_VERTICES * 4)); vertexColorBuffer = (FloatBuffer) vertexColor.getData(); mesh.setBuffer(vertexColor); indexBuffer.setupData(Usage.Stream, 3, VertexBuffer.Format.UnsignedShort, BufferUtils.createShortBuffer(BATCH_MAX_QUADS * 2 * 3)); indexBufferBuffer = (ShortBuffer) indexBuffer.getData(); mesh.setBuffer(indexBuffer); material = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); material.setBoolean("VertexColor", true); renderState.setDepthTest(false); renderState.setDepthWrite(false); }
Example #2
Source File: Mesh.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Creates a {@link VertexBuffer} for the mesh or modifies * the existing one per the parameters given. * * @param type The type of the buffer * @param components Number of components * @param format Data format * @param buf The buffer data * * @throws UnsupportedOperationException If the buffer already set is * incompatible with the parameters given. */ public void setBuffer(Type type, int components, Format format, Buffer buf){ VertexBuffer vb = buffers.get(type.ordinal()); if (vb == null){ vb = new VertexBuffer(type); vb.setupData(Usage.Dynamic, components, format, buf); setBuffer(vb); }else{ if (vb.getNumComponents() != components || vb.getFormat() != format){ throw new UnsupportedOperationException("The buffer already set " + "is incompatible with the given parameters"); } vb.updateData(buf); updateCounts(); } }
Example #3
Source File: SkeletonPoints.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Creates a points with bone lengths data. If the data is supplied then the points will show both head and tail of each bone. * @param skeleton * the skeleton that will be shown * @param boneLengths * a map between the bone's index and the bone's length */ public SkeletonPoints(Skeleton skeleton, Map<Integer, Float> boneLengths) { this.skeleton = skeleton; this.setMode(Mode.Points); int pointsCount = skeleton.getBoneCount(); if (boneLengths != null) { this.boneLengths = boneLengths; pointsCount *= 2; } VertexBuffer pb = new VertexBuffer(Type.Position); FloatBuffer fpb = BufferUtils.createFloatBuffer(pointsCount * 3); pb.setupData(Usage.Stream, 3, Format.Float, fpb); this.setBuffer(pb); this.updateCounts(); }
Example #4
Source File: SkeletonInterBoneWire.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Creates buffers for points. Each line has POINT_AMOUNT of points. * @param skeleton * the skeleton that will be showed * @param boneLengths * the lengths of the bones */ public SkeletonInterBoneWire(Skeleton skeleton, Map<Integer, Float> boneLengths) { this.skeleton = skeleton; for (Bone bone : skeleton.getRoots()) { this.countConnections(bone); } this.setMode(Mode.Points); this.boneLengths = boneLengths; VertexBuffer pb = new VertexBuffer(Type.Position); FloatBuffer fpb = BufferUtils.createFloatBuffer(POINT_AMOUNT * connectionsAmount * 3); pb.setupData(Usage.Stream, 3, Format.Float, fpb); this.setBuffer(pb); this.updateCounts(); }
Example #5
Source File: WireFrustum.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static void initGeom(Mesh m, Vector3f[] points) { if (points != null) m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(points)); m.setBuffer(Type.Index, 2, new short[]{ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7, } ); m.getBuffer(Type.Index).setUsage(Usage.Static); m.setMode(Mode.Lines); }
Example #6
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
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 #7
Source File: RenderDeviceJme.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public RenderDeviceJme(NiftyJmeDisplay display) { this.display = display; quadColor = new VertexBuffer(Type.Color); quadColor.setNormalized(true); ByteBuffer bb = BufferUtils.createByteBuffer(4 * 4); quadColor.setupData(Usage.Stream, 4, Format.UnsignedByte, bb); quad.setBuffer(quadColor); quadModTC.setUsage(Usage.Stream); // Load the 3 material types separately to avoid // reloading the shader when the defines change. // Material with a single color (no texture or vertex color) colorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); // Material with a texture and a color (no vertex color) textureColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); // Material with vertex color, used for gradients (no texture) vertexColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); vertexColorMaterial.setBoolean("VertexColor", true); // Shared render state for all materials renderState.setDepthTest(false); renderState.setDepthWrite(false); }
Example #8
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void renderMesh(Mesh mesh, int lod, int count) { if (mesh.getVertexCount() == 0) return; if (context.pointSize != mesh.getPointSize()) { gl.glPointSize(mesh.getPointSize()); context.pointSize = mesh.getPointSize(); } if (context.lineWidth != mesh.getLineWidth()) { gl.glLineWidth(mesh.getLineWidth()); context.lineWidth = mesh.getLineWidth(); } checkTexturingUsed(); if (vbo) { renderMeshVBO(mesh, lod, count); } else { boolean dynamic = false; if (mesh.getNumLodLevels() == 0) { IntMap<VertexBuffer> bufs = mesh.getBuffers(); for (Entry<VertexBuffer> entry : bufs) { if (entry.getValue().getUsage() != VertexBuffer.Usage.Static) { dynamic = true; break; } } } else { dynamic = true; } if (!dynamic) { // dealing with a static object, generate display list renderMeshDisplayList(mesh); } else { renderMeshDefault(mesh, lod, count); } } }
Example #9
Source File: OGLESShaderRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/*********************************************************************\ |* Vertex Buffers and Attributes *| \*********************************************************************/ private int convertUsage(Usage usage) { switch (usage) { case Static: return GLES20.GL_STATIC_DRAW; case Dynamic: return GLES20.GL_DYNAMIC_DRAW; case Stream: return GLES20.GL_STREAM_DRAW; default: throw new RuntimeException("Unknown usage type."); } }
Example #10
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private int convertUsage(Usage usage) { switch (usage) { case Static: return GL.GL_STATIC_DRAW; case Dynamic: return GL.GL_DYNAMIC_DRAW; case Stream: return GL2ES2.GL_STREAM_DRAW; default: throw new RuntimeException("Unknown usage type: " + usage); } }
Example #11
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void renderMesh(Mesh mesh, int lod, int count) { GL gl = GLContext.getCurrentGL(); if (context.pointSize != mesh.getPointSize()) { gl.getGL2().glPointSize(mesh.getPointSize()); context.pointSize = mesh.getPointSize(); } if (context.lineWidth != mesh.getLineWidth()) { gl.glLineWidth(mesh.getLineWidth()); context.lineWidth = mesh.getLineWidth(); } checkTexturingUsed(); if (vbo) { renderMeshVBO(mesh, lod, count); } else { boolean dynamic = false; if (mesh.getNumLodLevels() == 0) { IntMap<VertexBuffer> bufs = mesh.getBuffers(); for (Entry<VertexBuffer> entry : bufs) { if (entry.getValue().getUsage() != VertexBuffer.Usage.Static) { dynamic = true; break; } } } else { dynamic = true; } if (!dynamic) { // dealing with a static object, generate display list renderMeshDisplayList(mesh); } else { renderMeshDefault(mesh, lod, count); } } }
Example #12
Source File: LwjglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/*********************************************************************\ |* Vertex Buffers and Attributes *| \*********************************************************************/ private int convertUsage(Usage usage) { switch (usage) { case Static: return GL_STATIC_DRAW; case Dynamic: return GL_DYNAMIC_DRAW; case Stream: return GL_STREAM_DRAW; default: throw new UnsupportedOperationException("Unknown usage type."); } }
Example #13
Source File: LwjglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void updateVertexArray(Mesh mesh) { int id = mesh.getId(); if (id == -1) { IntBuffer temp = intBuf1; ARBVertexArrayObject.glGenVertexArrays(temp); id = temp.get(0); mesh.setId(id); } if (context.boundVertexArray != id) { ARBVertexArrayObject.glBindVertexArray(id); context.boundVertexArray = id; } VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData); if (interleavedData != null && interleavedData.isUpdateNeeded()) { updateBufferData(interleavedData); } IntMap<VertexBuffer> buffers = mesh.getBuffers(); 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 setVertexAttrib(vb); } else { // interleaved setVertexAttrib(vb, interleavedData); } } }
Example #14
Source File: MeshLoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void startFaces(String count) throws SAXException { int numFaces = parseInt(count); int indicesPerFace = 0; switch (mesh.getMode()) { case Triangles: indicesPerFace = 3; break; case Lines: indicesPerFace = 2; break; case Points: indicesPerFace = 1; break; default: throw new SAXException("Strips or fans not supported!"); } int numIndices = indicesPerFace * numFaces; vb = new VertexBuffer(VertexBuffer.Type.Index); if (!usesBigIndices) { sb = BufferUtils.createShortBuffer(numIndices); ib = null; vb.setupData(Usage.Static, indicesPerFace, Format.UnsignedShort, sb); } else { ib = BufferUtils.createIntBuffer(numIndices); sb = null; vb.setupData(Usage.Static, indicesPerFace, Format.UnsignedInt, ib); } mesh.setBuffer(vb); }
Example #15
Source File: MeshLoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void startBoneAssigns() { if (mesh != sharedMesh && usesSharedVerts) { // will use bone assignments from shared mesh (?) return; } // current mesh will have bone assigns //int vertCount = mesh.getVertexCount(); // each vertex has // - 4 bone weights // - 4 bone indices // create array-backed buffers for software skinning for access speed weightsFloatData = FloatBuffer.allocate(vertCount * 4); indicesData = ByteBuffer.allocate(vertCount * 4); VertexBuffer weights = new VertexBuffer(Type.BoneWeight); VertexBuffer indices = new VertexBuffer(Type.BoneIndex); weights.setupData(Usage.CpuOnly, 4, Format.Float, weightsFloatData); indices.setupData(Usage.CpuOnly, 4, Format.UnsignedByte, indicesData); mesh.setBuffer(weights); mesh.setBuffer(indices); //creating empty buffers for HW skinning //the buffers will be setup if ever used. VertexBuffer weightsHW = new VertexBuffer(Type.HWBoneWeight); VertexBuffer indicesHW = new VertexBuffer(Type.HWBoneIndex); //setting usage to cpuOnly so that the buffer is not send empty to the GPU indicesHW.setUsage(Usage.CpuOnly); weightsHW.setUsage(Usage.CpuOnly); mesh.setBuffer(weightsHW); mesh.setBuffer(indicesHW); }
Example #16
Source File: MeshLoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void startLodFaceList(String submeshindex, String numfaces) { int index = Integer.parseInt(submeshindex); mesh = geoms.get(index).getMesh(); int faceCount = Integer.parseInt(numfaces); VertexBuffer originalIndexBuffer = mesh.getBuffer(Type.Index); vb = new VertexBuffer(VertexBuffer.Type.Index); if (originalIndexBuffer.getFormat() == Format.UnsignedInt) { // LOD buffer should also be integer ib = BufferUtils.createIntBuffer(faceCount * 3); sb = null; vb.setupData(Usage.Static, 3, Format.UnsignedInt, ib); } else { sb = BufferUtils.createShortBuffer(faceCount * 3); ib = null; vb.setupData(Usage.Static, 3, Format.UnsignedShort, sb); } List<VertexBuffer> levels = lodLevels.get(index); if (levels == null) { // Create the LOD levels list levels = new ArrayList<VertexBuffer>(); // Add the first LOD level (always the original index buffer) levels.add(originalIndexBuffer); lodLevels.put(index, levels); } levels.add(vb); }
Example #17
Source File: SkeletonPoints.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public SkeletonPoints(Skeleton skeleton){ this.skeleton = skeleton; setMode(Mode.Points); VertexBuffer pb = new VertexBuffer(Type.Position); FloatBuffer fpb = BufferUtils.createFloatBuffer(skeleton.getBoneCount() * 3); pb.setupData(Usage.Stream, 3, Format.Float, fpb); setBuffer(pb); setPointSize(7); updateCounts(); }
Example #18
Source File: Mesh.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void read(JmeImporter im) throws IOException { InputCapsule in = im.getCapsule(this); meshBound = (BoundingVolume) in.readSavable("modelBound", null); vertCount = in.readInt("vertCount", -1); elementCount = in.readInt("elementCount", -1); maxNumWeights = in.readInt("max_num_weights", -1); mode = in.readEnum("mode", Mode.class, Mode.Triangles); elementLengths = in.readIntArray("elementLengths", null); modeStart = in.readIntArray("modeStart", null); collisionTree = (BIHTree) in.readSavable("collisionTree", null); elementLengths = in.readIntArray("elementLengths", null); modeStart = in.readIntArray("modeStart", null); pointSize = in.readFloat("pointSize", 1f); // in.readStringSavableMap("buffers", null); buffers = (IntMap<VertexBuffer>) in.readIntSavableMap("buffers", null); for (Entry<VertexBuffer> entry : buffers){ buffersList.add(entry.getValue()); } //creating hw animation buffers empty so that they are put in the cache if(isAnimated()){ VertexBuffer hwBoneIndex = new VertexBuffer(Type.HWBoneIndex); hwBoneIndex.setUsage(Usage.CpuOnly); setBuffer(hwBoneIndex); VertexBuffer hwBoneWeight = new VertexBuffer(Type.HWBoneWeight); hwBoneWeight.setUsage(Usage.CpuOnly); setBuffer(hwBoneWeight); } Savable[] lodLevelsSavable = in.readSavableArray("lodLevels", null); if (lodLevelsSavable != null) { lodLevels = new VertexBuffer[lodLevelsSavable.length]; System.arraycopy( lodLevelsSavable, 0, lodLevels, 0, lodLevels.length); } }
Example #19
Source File: ParticleTriMesh.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void setImagesXY(int imagesX, int imagesY) { this.imagesX = imagesX; this.imagesY = imagesY; if (imagesX != 1 || imagesY != 1){ uniqueTexCoords = true; getBuffer(VertexBuffer.Type.TexCoord).setUsage(Usage.Stream); } }
Example #20
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private int convertUsage(Usage usage) { switch (usage) { case Static: return gl.GL_STATIC_DRAW; case Dynamic: return gl.GL_DYNAMIC_DRAW; case Stream: return gl.GL_STREAM_DRAW; default: throw new RuntimeException("Unknown usage type: " + usage); } }
Example #21
Source File: RenderDeviceJme.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public RenderDeviceJme(NiftyJmeDisplay display){ this.display = display; quadColor = new VertexBuffer(Type.Color); quadColor.setNormalized(true); ByteBuffer bb = BufferUtils.createByteBuffer(4 * 4); quadColor.setupData(Usage.Stream, 4, Format.UnsignedByte, bb); quad.setBuffer(quadColor); quadModTC.setUsage(Usage.Stream); niftyMat = new Material(display.getAssetManager(), "Common/MatDefs/Nifty/Nifty.j3md"); niftyMat.getAdditionalRenderState().setDepthTest(false); }
Example #22
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void renderMeshDefault(Mesh mesh, int lod, int count) { VertexBuffer indices = null; VertexBuffer interleavedData = mesh.getBuffer(Type.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 { continue; } if (vb.getBufferType() == Type.Index) { indices = vb; } else { if (vb.getStride() == 0) { // not interleaved setVertexAttrib(vb); } else { // interleaved setVertexAttrib(vb, interleavedData); } } } if (indices != null) { drawTriangleList(indices, mesh, count); } else { gl.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount()); } clearVertexAttribs(); clearTextureUnits(); }
Example #23
Source File: ParticleTriMesh.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void setImagesXY(int imagesX, int imagesY) { this.imagesX = imagesX; this.imagesY = imagesY; if (imagesX != 1 || imagesY != 1){ uniqueTexCoords = true; getBuffer(VertexBuffer.Type.TexCoord).setUsage(Usage.Stream); } }
Example #24
Source File: GLRenderer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/*********************************************************************\ |* Vertex Buffers and Attributes *| \*********************************************************************/ private int convertUsage(Usage usage) { switch (usage) { case Static: return GL.GL_STATIC_DRAW; case Dynamic: return GL.GL_DYNAMIC_DRAW; case Stream: return GL.GL_STREAM_DRAW; default: throw new UnsupportedOperationException("Unknown usage type."); } }
Example #25
Source File: GLRenderer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void updateVertexArray(Mesh mesh, VertexBuffer instanceData) { int id = mesh.getId(); if (id == -1) { IntBuffer temp = intBuf1; gl3.glGenVertexArrays(temp); id = temp.get(0); mesh.setId(id); } if (context.boundVertexArray != id) { gl3.glBindVertexArray(id); context.boundVertexArray = id; } VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData); if (interleavedData != null && interleavedData.isUpdateNeeded()) { updateBufferData(interleavedData); } if (instanceData != null) { setVertexAttrib(instanceData, null); } for (VertexBuffer vb : mesh.getBufferList().getArray()) { if (vb.getBufferType() == Type.InterleavedData || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers || vb.getBufferType() == Type.Index) { continue; } if (vb.getStride() == 0) { // not interleaved setVertexAttrib(vb); } else { // interleaved setVertexAttrib(vb, interleavedData); } } }
Example #26
Source File: GdxRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/*********************************************************************\ |* Vertex Buffers and Attributes *| \*********************************************************************/ private int convertUsage(Usage usage) { switch (usage) { case Static: return GL20.GL_STATIC_DRAW; case Dynamic: return GL20.GL_DYNAMIC_DRAW; case Stream: return GL20.GL_STREAM_DRAW; default: throw new RuntimeException("Unknown usage type."); } }
Example #27
Source File: MeshLoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
private void startVertexBuffer(Attributes attribs) throws SAXException { if (parseBool(attribs.getValue("positions"), false)) { vb = new VertexBuffer(Type.Position); fb = BufferUtils.createFloatBuffer(vertCount * 3); vb.setupData(Usage.Static, 3, Format.Float, fb); mesh.setBuffer(vb); } if (parseBool(attribs.getValue("normals"), false)) { vb = new VertexBuffer(Type.Normal); fb = BufferUtils.createFloatBuffer(vertCount * 3); vb.setupData(Usage.Static, 3, Format.Float, fb); mesh.setBuffer(vb); } if (parseBool(attribs.getValue("colours_diffuse"), false)) { vb = new VertexBuffer(Type.Color); fb = BufferUtils.createFloatBuffer(vertCount * 4); vb.setupData(Usage.Static, 4, Format.Float, fb); mesh.setBuffer(vb); } if (parseBool(attribs.getValue("tangents"), false)) { int dimensions = parseInt(attribs.getValue("tangent_dimensions"), 3); vb = new VertexBuffer(Type.Tangent); fb = BufferUtils.createFloatBuffer(vertCount * dimensions); vb.setupData(Usage.Static, dimensions, Format.Float, fb); mesh.setBuffer(vb); } if (parseBool(attribs.getValue("binormals"), false)) { vb = new VertexBuffer(Type.Binormal); fb = BufferUtils.createFloatBuffer(vertCount * 3); vb.setupData(Usage.Static, 3, Format.Float, fb); mesh.setBuffer(vb); } int texCoords = parseInt(attribs.getValue("texture_coords"), 0); for (int i = 0; i < texCoords; i++) { int dims = parseInt(attribs.getValue("texture_coord_dimensions_" + i), 2); if (dims < 1 || dims > 4) { throw new SAXException("Texture coord dimensions must be 1 <= dims <= 4"); } if (i <= 7) { vb = new VertexBuffer(TEXCOORD_TYPES[i]); } else { // more than 8 texture coordinates are not supported by ogre. throw new SAXException("More than 8 texture coordinates not supported"); } fb = BufferUtils.createFloatBuffer(vertCount * dims); vb.setupData(Usage.Static, dims, Format.Float, fb); mesh.setBuffer(vb); } }
Example #28
Source File: TestCustomAnim.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp() { AmbientLight al = new AmbientLight(); rootNode.addLight(al); DirectionalLight dl = new DirectionalLight(); dl.setDirection(Vector3f.UNIT_XYZ.negate()); rootNode.addLight(dl); Box box = new Box(1, 1, 1); VertexBuffer weightsHW = new VertexBuffer(Type.HWBoneWeight); VertexBuffer indicesHW = new VertexBuffer(Type.HWBoneIndex); indicesHW.setUsage(Usage.CpuOnly); weightsHW.setUsage(Usage.CpuOnly); box.setBuffer(weightsHW); box.setBuffer(indicesHW); // Setup bone weight buffer FloatBuffer weights = FloatBuffer.allocate(box.getVertexCount() * 4); VertexBuffer weightsBuf = new VertexBuffer(Type.BoneWeight); weightsBuf.setupData(Usage.CpuOnly, 4, Format.Float, weights); box.setBuffer(weightsBuf); // Setup bone index buffer ByteBuffer indices = ByteBuffer.allocate(box.getVertexCount() * 4); VertexBuffer indicesBuf = new VertexBuffer(Type.BoneIndex); indicesBuf.setupData(Usage.CpuOnly, 4, Format.UnsignedByte, indices); box.setBuffer(indicesBuf); // Create bind pose buffers box.generateBindPose(); // Create skeleton bone = new Joint("root"); bone.setLocalTransform(new Transform(Vector3f.ZERO, Quaternion.IDENTITY, Vector3f.UNIT_XYZ)); armature = new Armature(new Joint[] { bone }); // Assign all verticies to bone 0 with weight 1 for (int i = 0; i < box.getVertexCount() * 4; i += 4) { // assign vertex to bone index 0 indices.array()[i + 0] = 0; indices.array()[i + 1] = 0; indices.array()[i + 2] = 0; indices.array()[i + 3] = 0; // set weight to 1 only for first entry weights.array()[i + 0] = 1; weights.array()[i + 1] = 0; weights.array()[i + 2] = 0; weights.array()[i + 3] = 0; } // Maximum number of weights per bone is 1 box.setMaxNumWeights(1); // Create model Geometry geom = new Geometry("box", box); geom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m")); Node model = new Node("model"); model.attachChild(geom); // Create skeleton control SkinningControl skinningControl = new SkinningControl(armature); model.addControl(skinningControl); rootNode.attachChild(model); }
Example #29
Source File: ParticlePointMesh.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void initParticleData(ParticleEmitter emitter, int numParticles) { setMode(Mode.Points); this.emitter = emitter; // set positions FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles); //if the buffer is already set only update the data VertexBuffer buf = getBuffer(VertexBuffer.Type.Position); if (buf != null) { buf.updateData(pb); } else { VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position); pvb.setupData(Usage.Stream, 3, Format.Float, pb); setBuffer(pvb); } // set colors ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4); buf = getBuffer(VertexBuffer.Type.Color); if (buf != null) { buf.updateData(cb); } else { VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color); cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb); cvb.setNormalized(true); setBuffer(cvb); } // set sizes FloatBuffer sb = BufferUtils.createFloatBuffer(numParticles); buf = getBuffer(VertexBuffer.Type.Size); if (buf != null) { buf.updateData(sb); } else { VertexBuffer svb = new VertexBuffer(VertexBuffer.Type.Size); svb.setupData(Usage.Stream, 1, Format.Float, sb); setBuffer(svb); } // set UV-scale FloatBuffer tb = BufferUtils.createFloatBuffer(numParticles*4); buf = getBuffer(VertexBuffer.Type.TexCoord); if (buf != null) { buf.updateData(tb); } else { VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord); tvb.setupData(Usage.Stream, 4, Format.Float, tb); setBuffer(tvb); } updateCounts(); }
Example #30
Source File: Mesh.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Generates the {@link Type#BindPosePosition}, {@link Type#BindPoseNormal}, * and {@link Type#BindPoseTangent} * buffers for this mesh by duplicating them based on the position and normal * buffers already set on the mesh. * This method does nothing if the mesh has no bone weight or index * buffers. * * @param forSoftwareAnim Should be true if the bind pose is to be generated. */ public void generateBindPose(boolean forSoftwareAnim){ if (forSoftwareAnim){ VertexBuffer pos = getBuffer(Type.Position); if (pos == null || getBuffer(Type.BoneIndex) == null) { // ignore, this mesh doesn't have positional data // or it doesn't have bone-vertex assignments, so its not animated return; } VertexBuffer bindPos = new VertexBuffer(Type.BindPosePosition); bindPos.setupData(Usage.CpuOnly, pos.getNumComponents(), pos.getFormat(), BufferUtils.clone(pos.getData())); setBuffer(bindPos); // XXX: note that this method also sets stream mode // so that animation is faster. this is not needed for hardware skinning pos.setUsage(Usage.Stream); VertexBuffer norm = getBuffer(Type.Normal); if (norm != null) { VertexBuffer bindNorm = new VertexBuffer(Type.BindPoseNormal); bindNorm.setupData(Usage.CpuOnly, norm.getNumComponents(), norm.getFormat(), BufferUtils.clone(norm.getData())); setBuffer(bindNorm); norm.setUsage(Usage.Stream); } VertexBuffer tangents = getBuffer(Type.Tangent); if (tangents != null) { VertexBuffer bindTangents = new VertexBuffer(Type.BindPoseTangent); bindTangents.setupData(Usage.CpuOnly, tangents.getNumComponents(), tangents.getFormat(), BufferUtils.clone(tangents.getData())); setBuffer(bindTangents); tangents.setUsage(Usage.Stream); }// else hardware setup does nothing, mesh already in bind pose } }