com.badlogic.gdx.graphics.g3d.model.MeshPart Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g3d.model.MeshPart. 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: GLTFExporter.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
/** convenient method to export a single mesh 
 * primitiveType can be any of OpenGL primitive: 
 * {@link com.badlogic.gdx.graphics.GL20#GL_POINTS}, 
 * {@link com.badlogic.gdx.graphics.GL20#GL_LINES}, 
 * {@link com.badlogic.gdx.graphics.GL20#GL_LINE_STRIP}, 
 * {@link com.badlogic.gdx.graphics.GL20#GL_TRIANGLES}, 
 * {@link com.badlogic.gdx.graphics.GL20#GL_TRIANGLE_STRIP},
 * {@link com.badlogic.gdx.graphics.GL20#GL_TRIANGLE_FAN},
 * etc..
 * */
public void export(Mesh mesh, int primitiveType, FileHandle file){
	GLTFScene scene = beginSingleScene(file);
	
	GLTFNode glNode = obtainNode();
	scene.nodes = new Array<Integer>();
	scene.nodes.add(root.nodes.size-1);
	
	GLTFMesh gltfMesh = obtainMesh();
	glNode.mesh = root.meshes.size-1;
	
	MeshPart meshPart = new MeshPart();
	meshPart.mesh = mesh;
	meshPart.offset = 0;
	meshPart.primitiveType = primitiveType;
	meshPart.size = mesh.getNumIndices();
	if(meshPart.size == 0) meshPart.size = mesh.getNumVertices();
	
	gltfMesh.primitives = new Array<GLTFPrimitive>();
	GLTFPrimitive primitive = meshExporter.exportMeshPart(meshPart);
	gltfMesh.primitives.add(primitive);
	
	end(file);
}
 
Example #2
Source File: Terrain.java    From Mundus with Apache License 2.0 6 votes vote down vote up
public void init() {
    final int numVertices = this.vertexResolution * vertexResolution;
    final int numIndices = (this.vertexResolution - 1) * (vertexResolution - 1) * 6;

    mesh = new Mesh(true, numVertices, numIndices, attribs);
    this.vertices = new float[numVertices * stride];
    mesh.setIndices(buildIndices());
    buildVertices();
    mesh.setVertices(vertices);

    MeshPart meshPart = new MeshPart(null, mesh, 0, numIndices, GL20.GL_TRIANGLES);
    meshPart.update();
    ModelBuilder mb = new ModelBuilder();
    mb.begin();
    mb.part(meshPart, material);
    model = mb.end();
    modelInstance = new ModelInstance(model);
    modelInstance.transform = transform;
}
 
Example #3
Source File: GLTFMeshExporter.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
GLTFPrimitive exportMeshPart(MeshPart meshPart) {
	Mesh mesh = meshPart.mesh;
	GLTFPrimitive primitive = new GLTFPrimitive();
	primitive.attributes = new ObjectMap<String, Integer>();
	primitive.mode = mapPrimitiveMode(meshPart.primitiveType);
	
	GLTFPrimitive layout = layouts.get(mesh);
	if(layout != null){
		copyLayout(primitive, layout);
	}else{
		layouts.put(mesh, primitive);
		exportMesh(primitive, mesh);
	}
	
	// mesh may not have indices
	if(mesh.getNumIndices() > 0)
	{
		ShortBuffer outBuffer = base.binManager.beginShorts(meshPart.size);
		ShortBuffer inBuffer = mesh.getIndicesBuffer();
		if(meshPart.offset == 0 && meshPart.size == mesh.getNumIndices()){
			outBuffer.put(mesh.getIndicesBuffer());
		}else{
			short[] localIndices = new short[meshPart.size];
			inBuffer.position(meshPart.offset);
			inBuffer.get(localIndices);
			outBuffer.put(localIndices);
		}
		inBuffer.rewind();
		
		GLTFAccessor accessor = base.obtainAccessor();
		accessor.type = GLTFTypes.TYPE_SCALAR;
		accessor.componentType = GLTFTypes.C_SHORT;
		accessor.count = meshPart.size;
		accessor.bufferView = base.binManager.end();
		
		primitive.indices = base.root.accessors.size-1;
	}
	
	return primitive;
}
 
Example #4
Source File: Benchmark.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
protected void assertConsistent(Model model) {
	
	final long expectedAttributes = VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates;
	
	assertEquals(0, model.animations.size);
	// assertEquals(1, model.materials.size); TODO GLTF should collect that?
	assertEquals(4, model.meshes.size);
	// assertEquals(1, model.meshParts.size); TODO GLTF should collect that?
	assertEquals(4, model.nodes.size);
	
	for(Node node : model.nodes){
		assertEquals(0, node.getChildCount());
		assertEquals(1, node.parts.size);
		MeshPart mp = node.parts.first().meshPart;
		assertEquals(0, mp.offset);
		assertEquals(GL20.GL_TRIANGLES, mp.primitiveType); 
		assertEquals(36864, mp.size);
		assertEquals(expectedAttributes, mp.mesh.getVertexAttributes().getMask());
		boolean isIndexed = mp.mesh.getNumIndices() > 0;
		if(isIndexed){ // XXX OBJ doesn't have indexed meshes
			assertEquals(24576, mp.mesh.getNumVertices());
			assertEquals(36864, mp.mesh.getNumIndices());
		}else{
			assertEquals(36864, mp.mesh.getNumVertices());
		}
	}
}
 
Example #5
Source File: RainRenderer.java    From Cubes with MIT License 5 votes vote down vote up
private RainMesh() {
  mesh = new Mesh(true, MAX_VERTICES, MAX_INDICES, VERTEX_ATTRIBUTES);
  meshPart = new MeshPart();
  meshPart.mesh = mesh;
  meshPart.primitiveType = GL20.GL_TRIANGLES;
  meshPart.offset = 0;
  mesh.setIndices(indices);
}
 
Example #6
Source File: AreaMesh.java    From Cubes with MIT License 5 votes vote down vote up
public AreaMesh(VertexAttributes vertexAttributes) {
  mesh = new Mesh(true, MAX_VERTICES, MAX_INDICES, vertexAttributes);
  meshPart = new MeshPart();
  meshPart.mesh = mesh;
  meshPart.primitiveType = GL20.GL_TRIANGLES;
  meshPart.offset = 0;
  mesh.setIndices(indices);

  int components = CubesVertexAttributes.components(vertexAttributes);
  maxVertexOffset = MAX_VERTICES * components;

  renderable.material = Assets.blockItemSheet.getMaterial();
  renderable.name = "AreaMesh";
}
 
Example #7
Source File: LevelBuilder.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
/** bullet bodies are offset from model instances by a 90 degree rotation on X axis, boolean set to true handles this */
private static void setupStaticModel(Array<MeshPart> meshParts, Matrix4 matrix, boolean performVisualToPhysicalRotation) {
	//Log.debug("create static model at: " + matrix.getTranslation(tmp));
	btCollisionObject obj = new btCollisionObject();
	btCollisionShape shape = new btBvhTriangleMeshShape(meshParts);
	obj.setCollisionShape(shape);
	Physics.applyStaticGeometryCollisionFlags(obj);
	mtx.set(matrix);
	if (performVisualToPhysicalRotation) {
		mtx.rotate(Vector3.X, -90);
	}
	obj.setWorldTransform(mtx);
	Physics.inst.addStaticGeometryToWorld(obj);
}
 
Example #8
Source File: HeadlessModel.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
private Node loadNode (Node parent, ModelNode modelNode) {
	Node node = new Node();
	node.id = modelNode.id;
	node.parent = parent;

	if (modelNode.translation != null) node.translation.set(modelNode.translation);
	if (modelNode.rotation != null) node.rotation.set(modelNode.rotation);
	if (modelNode.scale != null) node.scale.set(modelNode.scale);
	// FIXME create temporary maps for faster lookup?
	if (modelNode.parts != null) {
		for (ModelNodePart modelNodePart : modelNode.parts) {
			MeshPart meshPart = null;

			if (modelNodePart.meshPartId != null) {
				for (MeshPart part : meshParts) {
					if (modelNodePart.meshPartId.equals(part.id)) {
						meshPart = part;
						break;
					}
				}
			}

			if (meshPart == null) throw new GdxRuntimeException("Invalid node: " + node.id);
			NodePart nodePart = new NodePart();
			nodePart.meshPart = meshPart;
			// nodePart.material = meshMaterial;
			node.parts.add(nodePart);
			if (modelNodePart.bones != null) nodePartBones.put(nodePart, modelNodePart.bones);
		}
	}

	if (modelNode.children != null) {
		for (ModelNode child : modelNode.children) {
			node.children.add(loadNode(node, child));
		}
	}

	return node;
}