com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder. 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: Terrain.java    From Mundus with Apache License 2.0 6 votes vote down vote up
private void setVertex(int index, MeshPartBuilder.VertexInfo info) {
    index *= stride;
    if (posPos >= 0) {
        vertices[index + posPos] = info.position.x;
        vertices[index + posPos + 1] = info.position.y;
        vertices[index + posPos + 2] = info.position.z;
    }
    if (uvPos >= 0) {
        vertices[index + uvPos] = info.uv.x;
        vertices[index + uvPos + 1] = info.uv.y;
    }
    if (norPos >= 0) {
        vertices[index + norPos] = info.normal.x;
        vertices[index + norPos + 1] = info.normal.y;
        vertices[index + norPos + 2] = info.normal.z;
    }
}
 
Example #2
Source File: ModelManager.java    From gdx-proto with Apache License 2.0 6 votes vote down vote up
public void createBillboardTest() {
	ModelBuilder mb = new ModelBuilder();
	mb.begin();

	long attr = Usage.TextureCoordinates | Usage.Position | Usage.Normal;
	TextureRegion region = Assets.getAtlas().findRegion("sprites/test-guy");
	Material mat = new Material(TextureAttribute.createDiffuse(region.getTexture()));
	boolean blended = true;
	float opacity = 1f;
	mat.set(new BlendingAttribute(blended, GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, opacity));
	MeshPartBuilder mpb = mb.part("rect", GL20.GL_TRIANGLES, attr, mat);
	mpb.setUVRange(region);
	// the coordinates are offset so that we can easily set the center position to align with the entity's body
	float sz = 2f; // size
	float b = -sz/2; // base
	float max = sz/2; // max
	Vector3 bl = new Vector3(b, b, 0f);
	Vector3 br = new Vector3(b, max, 0f);
	Vector3 tr = new Vector3(max, max, 0f);
	Vector3 tl = new Vector3(max, b, 0f);
	Vector3 norm = new Vector3(0f, 0f, 1f);
	mpb.rect(bl, tl, tr, br, norm);
	billboardTestModel = mb.end();
}
 
Example #3
Source File: ExportSharedIndexBufferTest.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
@Override
public void create() {
	Material material = new Material();
	ModelBuilder mb = new ModelBuilder();
	MeshPartBuilder mpb;
	mb.begin();
	
	mpb = mb.part("part1", GL20.GL_TRIANGLES, Usage.Position, material);
	BoxShapeBuilder.build(mpb, 1, 1, 1);
	
	mpb = mb.part("part2", GL20.GL_TRIANGLES, Usage.Position, material);
	mpb.setVertexTransform(new Matrix4().setToTranslation(2, 0, 0));
	BoxShapeBuilder.build(mpb, 1, 1, 1);
	
	Model model = mb.end();
	new GLTFExporter().export(model, Gdx.files.absolute("/tmp/ExportSharedIndexBufferTest.gltf"));
	Gdx.app.exit();
}
 
Example #4
Source File: UsefulMeshs.java    From Mundus with Apache License 2.0 6 votes vote down vote up
public static Model createAxes() {
    final float GRID_MIN = -10f;
    final float GRID_MAX = 10f;
    final float GRID_STEP = 1f;
    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();
    MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES,
            VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, new Material());
    builder.setColor(Color.LIGHT_GRAY);
    for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) {
        builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX);
        builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t);
    }
    builder = modelBuilder.part("axes", GL20.GL_LINES,
            VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, new Material());
    builder.setColor(Color.RED);
    builder.line(0, 0, 0, 100, 0, 0);
    builder.setColor(Color.GREEN);
    builder.line(0, 0, 0, 0, 100, 0);
    builder.setColor(Color.BLUE);
    builder.line(0, 0, 0, 0, 0, 100);
    return modelBuilder.end();
}
 
Example #5
Source File: HeightMapModel.java    From gdx-proto with Apache License 2.0 6 votes vote down vote up
public Triangle(int triZ, int triX, MeshPartBuilder.VertexInfo a, MeshPartBuilder.VertexInfo b, MeshPartBuilder.VertexInfo c) {
	zidx = triZ;
	xidx = triX;
	try {
		tris[triZ][triX] = this;
	} catch (ArrayIndexOutOfBoundsException e) {
		e.printStackTrace();
		Tools.sleep(500);
		System.out.println("tried ZX: " + triZ + ", " + triX);
		System.out.println("length ZX: " + tris.length + ", " + tris[0].length);
		System.exit(5);
	}
	this.a = a;
	this.b = b;
	this.c = c;
	this.calculateFaceNormal();
}
 
Example #6
Source File: ModelPlacementTool.java    From Mundus with Apache License 2.0 6 votes vote down vote up
@Override
public boolean mouseMoved(int screenX, int screenY) {
    if (this.model == null || modelInstance == null) return false;

    final ProjectContext context = getProjectManager().current();

    final Ray ray = getProjectManager().current().currScene.viewport.getPickRay(screenX, screenY);
    if (context.currScene.terrains.size > 0 && modelInstance != null) {
        MeshPartBuilder.VertexInfo vi = TerrainUtils.getRayIntersectionAndUp(context.currScene.terrains, ray);
        if (vi != null) {
            if (shouldRespectTerrainSlope) {
                modelInstance.transform.setToLookAt(DEFAULT_ORIENTATION, vi.normal);
            }
            modelInstance.transform.setTranslation(vi.position);
        }
    } else {
        tempV3.set(getProjectManager().current().currScene.cam.position);
        tempV3.add(ray.direction.nor().scl(200));
        modelInstance.transform.setTranslation(tempV3);
    }

    return false;
}
 
Example #7
Source File: ModelFactory.java    From GdxDemo3D with Apache License 2.0 6 votes vote down vote up
public static Model buildPlaneModel(final float width,
									final float height, final Material material, final float u1,
									final float v1, final float u2, final float v2) {

	ModelBuilder modelBuilder = new ModelBuilder();
	modelBuilder.begin();
	MeshPartBuilder bPartBuilder = modelBuilder.part("rect", GL20.GL_TRIANGLES,
			VertexAttributes.Usage.Position
					| VertexAttributes.Usage.Normal
					| VertexAttributes.Usage.TextureCoordinates, material);
	bPartBuilder.setUVRange(u1, v1, u2, v2);
	bPartBuilder.rect(-(width * 0.5f), -(height * 0.5f), 0, (width * 0.5f),
			-(height * 0.5f), 0, (width * 0.5f), (height * 0.5f), 0,
			-(width * 0.5f), (height * 0.5f), 0, 0, 0, -1);

	return (modelBuilder.end());
}
 
Example #8
Source File: Utils3D.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
public static void createFloor() {

		ModelBuilder modelBuilder = new ModelBuilder();
		modelBuilder.begin();
		MeshPartBuilder mpb = modelBuilder.part("parts", GL20.GL_TRIANGLES,
				Usage.Position | Usage.Normal | Usage.ColorUnpacked, new Material(
						ColorAttribute.createDiffuse(Color.WHITE)));
		mpb.setColor(1f, 1f, 1f, 1f);
//		mpb.box(0, -0.1f, 0, 10, .2f, 10);
		mpb.rect(-10, 0, -10, 
				-10, 0, 10,
				10, 0, 10,
				10, 0, -10, 0, 1, 0);
		floorModel = modelBuilder.end();
		floorInstance = new ModelInstance(floorModel);
		
		// TODO Set only when FBO is active
		floorInstance.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
	}
 
Example #9
Source File: Utils3D.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
private static void createAxes() {
	ModelBuilder modelBuilder = new ModelBuilder();
	modelBuilder.begin();
	MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material());
	builder.setColor(Color.LIGHT_GRAY);
	for (float t = GRID_MIN; t <= GRID_MAX; t+=GRID_STEP) {
		builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX);
		builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t);
	}
	builder = modelBuilder.part("axes", GL20.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material());
	builder.setColor(Color.RED);
	builder.line(0, 0, 0, 10, 0, 0);
	builder.setColor(Color.GREEN);
	builder.line(0, 0, 0, 0, 10, 0);
	builder.setColor(Color.BLUE);
	builder.line(0, 0, 0, 0, 0, 10);
	axesModel = modelBuilder.end();
	axesInstance = new ModelInstance(axesModel);
}
 
Example #10
Source File: HeightMapModel.java    From gdx-proto with Apache License 2.0 6 votes vote down vote up
private void setVertexPositions() {
	// store vertex info for second pass where we calculate vertex normals for per-vertex lighting
	float[][] pts = heightMap.heights;
	float blockSize = heightMap.getWidthScale();
	float heightScale = heightMap.getHeightScale();
	float width = heightMap.getWidthWorld();
	float depth = heightMap.getDepthWorld();
	for (int z = 0; z < pts.length; z++) {
		for (int x = 0; x < pts[z].length; x++) {
			float y = pts[z][x];
			MeshPartBuilder.VertexInfo thisVert = new MeshPartBuilder.VertexInfo();
			thisVert.setPos(x * blockSize, y * heightScale, z * blockSize);
			// set texture UV
			float u = (x * blockSize) / width;
			float v = (z * blockSize) / depth;
			float scl = heightScale;
			scl = 1f;
			thisVert.setUV(u * scl, v * scl);
			vertexInfos[z][x] = thisVert;
		}
	}
}
 
Example #11
Source File: HeightMapModel.java    From gdx-proto with Apache License 2.0 6 votes vote down vote up
private void buildTriangles() {
	//System.out.printf("chunk: startXZ: %d, %d -- length: %d\n", startX, startZ, length);
	int count = 0;
	MeshPartBuilder.VertexInfo right;
	MeshPartBuilder.VertexInfo down;
	MeshPartBuilder.VertexInfo downRight;
	for (int z = 0; z < vertexInfos.length - 1; z++) {
		for (int x = 0; x < (vertexInfos[0].length - 1); x++) {
			MeshPartBuilder.VertexInfo vert = vertexInfos[z][x];
			right = vertexInfos[z][x+1];
			down = vertexInfos[z+1][x];
			downRight = vertexInfos[z+1][x+1];
			// each z row has two trianagles forming a rect
			int xIdx = x*2;
			Triangle top = new Triangle(z, xIdx, vert, down, right);
			Triangle bottom = new Triangle(z, xIdx+1, downRight, right, down);
			count += 2;
		}
	}
	System.out.println("built " + count + " triangles");
}
 
Example #12
Source File: Tools.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
public static String fmt(MeshPartBuilder.VertexInfo vi, String name) {
	if (name == null) name = "";
	StringBuilder sb = new StringBuilder();
	sb.append("VertexInfo: ").append(name).append("\n");
	sb.append("\t").append(fmt(vi.position, "position")).append("\n");
	sb.append("\t").append(fmt(vi.color)).append("\n");
	sb.append("\t").append(fmt(vi.normal, "normal"));
	return sb.toString();
}
 
Example #13
Source File: Box.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
/** create some boxes to fill the level with some test geometry */
public static void createBoxes(int count) {
	ModelBuilder main = new ModelBuilder();
	ModelBuilder mb = new ModelBuilder();
	Material material = new Material();
	if (Main.isClient()) {
		material.set(TextureAttribute.createDiffuse(Assets.manager.get("textures/marble.jpg", Texture.class)));
	}
	main.begin();
	//float x = GameWorld.WORLD_WIDTH;
	//float y = GameWorld.WORLD_DEPTH;
	for (int i = 0; i < count; i++) {
		//float w = MathUtils.random(minW, maxW);
		float w = 8f;
		float d = 8f;
		float h = (i+1)*5f;
		tmp.set(10f + (w+2) * i, 0f, 10f + (d+2) * i);
		if (Main.isClient()) {
			mb.begin();
			MeshPartBuilder mpb = mb.part("part-" + i, GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, material);
			mpb.box(w, h, d);
			Model boxModel = mb.end();
			Node node = main.node("box-" + i, boxModel);
			node.translation.set(tmp);
			q.idt();
			node.rotation.set(q);
		}
		//node.translation.set(MathUtils.random(x), 0f, MathUtils.random(y));
		//q.set(Vector3.X, -90);
		mtx.set(q);
		mtx.setTranslation(tmp);
		btCollisionObject obj = Physics.inst.createBoxObject(tmp.set(w/2, h/2, d/2));
		obj.setWorldTransform(mtx);
		Physics.applyStaticGeometryCollisionFlags(obj);
		Physics.inst.addStaticGeometryToWorld(obj);
	}
	Model finalModel = main.end();
	instance = new ModelInstance(finalModel);
}
 
Example #14
Source File: HeightMapModel.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
private void calculateVertexNormals() {
	int count = 0;
	for (int z = 0; z < vertexInfos.length; z++) {
		for (int x = 0; x < vertexInfos[z].length; x++) {
			MeshPartBuilder.VertexInfo vert = vertexInfos[z][x];
			// calculate normals
			vert.setNor(calculateNormalForVertex(z, x));

		}
	}
	System.out.print("vertex count: " + count + ", ");

}
 
Example #15
Source File: HeightMapModel.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
private void createGround() {
	if (++timesCreated > 1) {
		throw new GdxRuntimeException("can't create heightmap more than one time");
	}
	vertexInfos = new MeshPartBuilder.VertexInfo[heightMap.heights.length][heightMap.heights[0].length];
	int trisHeight = (heightMap.getWidth() - 1);
	int trisWidth = (heightMap.getWidth() - 1) * 2;
	System.out.printf("tris zHeight,xWidth: %d, %d\n", trisHeight, trisWidth);
	tris = new Triangle[trisHeight][trisWidth];
	setVertexPositions(); // iterate through height map points, setting world coordinates
	buildTriangles(); // abstraction of the triangles that create the mesh
	// useful for calculating vertex normals, since each triangle stores a face normal
	// but somewhat wasteful of memory
	// TODO: optimize
	calculateVertexNormals(); // calculate vertex normals for per-vertex lighting
	final int chunkSize = 32;
	int z = 0;
	int zRemain = (int) Math.ceil(heightMap.getDepth() / chunkSize);
	if (zRemain == 0) zRemain = 1;
	int baseXRemain = (int) Math.ceil(heightMap.getWidth() / chunkSize);
	if (baseXRemain == 0) baseXRemain = 1;
	System.out.println("z chunks: " + zRemain + ", x chunks: " + baseXRemain);
	while (zRemain > 0) {
		int xRemain = baseXRemain;
		int x = 0;
		while (xRemain > 0) {
			buildGroundModels(x, z, chunkSize);
			xRemain--;
			x += chunkSize*2;
		}
		zRemain--;
		z += chunkSize;
	}
}
 
Example #16
Source File: UsefulMeshs.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public static Model createArrowStub(Material mat, Vector3 from, Vector3 to) {
    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();
    MeshPartBuilder meshBuilder;
    // line
    meshBuilder = modelBuilder.part("line", GL20.GL_LINES,
            VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, mat);
    meshBuilder.line(from.x, from.y, from.z, to.x, to.y, to.z);
    // stub
    Node node = modelBuilder.node();
    node.translation.set(to.x, to.y, to.z);
    meshBuilder = modelBuilder.part("stub", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal, mat);
    BoxShapeBuilder.build(meshBuilder, 2, 2, 2);
    return modelBuilder.end();
}
 
Example #17
Source File: Terrain.java    From Mundus with Apache License 2.0 5 votes vote down vote up
private MeshPartBuilder.VertexInfo calculateVertexAt(MeshPartBuilder.VertexInfo out, int x, int z) {
    final float dx = (float) x / (float) (vertexResolution - 1);
    final float dz = (float) z / (float) (vertexResolution - 1);
    final float height = heightData[z * vertexResolution + x];

    out.position.set(dx * this.terrainWidth, height, dz * this.terrainDepth);
    out.uv.set(dx, dz).scl(uvScale);

    return out;
}
 
Example #18
Source File: GrassRenderer.java    From Radix with MIT License 5 votes vote down vote up
@Override
public void renderTop(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    float u = getU(atlasIndex);
    float v = getV(atlasIndex);
    builder.setUVRange(u, v, u, v);

    MeshPartBuilder.VertexInfo c00 = new MeshPartBuilder.VertexInfo().setPos(x1, y, z1).setNor(0, 1, 0);
    MeshPartBuilder.VertexInfo c01 = new MeshPartBuilder.VertexInfo().setPos(x1, y, z2).setNor(0, 1, 0);
    MeshPartBuilder.VertexInfo c10 = new MeshPartBuilder.VertexInfo().setPos(x2, y, z1).setNor(0, 1, 0);
    MeshPartBuilder.VertexInfo c11 = new MeshPartBuilder.VertexInfo().setPos(x2, y, z2).setNor(0, 1, 0);

    IChunk chunk = RadixClient.getInstance().getWorld().getChunk((int) x1, (int) z1);
    Biome biome;
    if(chunk != null) {
        biome = chunk.getBiome();
    } else {
        biome = RadixAPI.instance.getBiomeByID(0);
    }
    int[] color = biome.getGrassColor((int) y - 1);
    float r = color[0]/255f;
    float g = color[1]/255f;
    float b = color[2]/255f;
    if(pcld == null) {
        builder.setColor(r*lightLevel, g*lightLevel, b*lightLevel, 1);
    } else {
        c00.setCol(r*pcld.l00, g*pcld.l00, b*pcld.l00, 1);
        c01.setCol(r*pcld.l01, g*pcld.l01, b*pcld.l01, 1);
        c10.setCol(r*pcld.l10, g*pcld.l10, b*pcld.l10, 1);
        c11.setCol(r*pcld.l11, g*pcld.l11, b*pcld.l11, 1);
    }

    builder.rect(c01, c11, c10, c00);
}
 
Example #19
Source File: Tools.java    From gdx-proto with Apache License 2.0 4 votes vote down vote up
public static void print(MeshPartBuilder.VertexInfo vi) {
	System.out.println(fmt(vi, null));
}
 
Example #20
Source File: Tools.java    From gdx-proto with Apache License 2.0 4 votes vote down vote up
public static void print(MeshPartBuilder.VertexInfo vi, String name) {
	System.out.println(fmt(vi, name));
}
 
Example #21
Source File: LevelBuilder.java    From gdx-proto with Apache License 2.0 4 votes vote down vote up
public static void createLevel() {
	// graphical representation of the ground
	Log.debug("createLevel - create ground");
	if (Main.isClient()) {
		ModelBuilder mb = new ModelBuilder();
		mb.begin();
		Vector3 bl = new Vector3();
		Vector3 tl = new Vector3();
		Vector3 tr = new Vector3();
		Vector3 br = new Vector3();
		Vector3 norm = new Vector3(0f, 1f, 0f);
		// the size of each rect that makes up the ground
		Texture groundTex = Assets.manager.get("textures/ground1.jpg", Texture.class);
		Material groundMat = new Material(TextureAttribute.createDiffuse(groundTex));
		MeshPartBuilder mpb = mb.part("ground", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, groundMat);
		float u1 = 0f;
		float v1 = 0f;
		float u2 = groundPieceSize / 5f;
		float v2 = groundPieceSize / 5f;
		mpb.setUVRange(u1, v1, u2, v2);
		bl.set(0, 0, 0);
		tl.set(0, 0, groundPieceSize);
		tr.set(groundPieceSize, 0, groundPieceSize);
		br.set(groundPieceSize, 0, 0);
		//mpb.rect(bl, tl, tr, br, norm);
		int divisions = ((int) groundPieceSize) / 4;
		mpb.patch(bl, tl, tr, br, norm, divisions, divisions);
		Model groundModel = mb.end();
		models.add(groundModel);
		groundPieces.clear();
		int count = 0;
		for (int x = 0; x < GameWorld.WORLD_WIDTH; x += groundPieceSize) {
			for (int z = 0; z < GameWorld.WORLD_DEPTH; z += groundPieceSize) {
				count++;
				ModelInstance groundPiece = new ModelInstance(groundModel);
				groundPiece.transform.setToTranslation(x, 0f, z);
				groundPieces.add(groundPiece);
			}
		}
		Log.debug("createLevel - created " + count + " groundPieces");
	}

	// physical representation of the ground
	btCollisionObject groundObj = new btCollisionObject();
	btCollisionShape groundShape = new btStaticPlaneShape(Vector3.Y, 0f);
	groundObj.setCollisionShape(groundShape);
	Physics.applyStaticGeometryCollisionFlags(groundObj);
	Physics.inst.addStaticGeometryToWorld(groundObj);

	if (Main.isServer()) {
		Log.debug("createLevel - create static models");
		// server creates static models here, client will create the models when received from server upon connection
		createStaticModels(25);
	}

	Log.debug("createLevel - create boxes");
	Box.createBoxes(10);
}
 
Example #22
Source File: Tools.java    From gdx-proto with Apache License 2.0 4 votes vote down vote up
public static String fmt(MeshPartBuilder.VertexInfo vi) {
	return fmt(vi, null);
}
 
Example #23
Source File: Terrain.java    From gdx-proto with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a plane, used for testing
 * @param size the size of the plane
 * @return
 */
public static TerrainChunk CreatePlaneChunk (float size) {
	TerrainChunk chunk = new TerrainChunk();
	// graphical representation of the ground
	Log.debug("createLevel - create ground");
	if (Main.isClient()) {
		ModelBuilder mb = new ModelBuilder();
		mb.begin();
		Vector3 bl = new Vector3();
		Vector3 tl = new Vector3();
		Vector3 tr = new Vector3();
		Vector3 br = new Vector3();
		Vector3 norm = new Vector3(0f, 1f, 0f);
		// the size of each rect that makes up the ground
		Texture groundTex = Assets.manager.get("textures/ground1.jpg", Texture.class);
		Material groundMat = new Material(TextureAttribute.createDiffuse(groundTex));
		MeshPartBuilder mpb = mb.part("ground", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates,
			groundMat);
		float u1 = 0f;
		float v1 = 0f;
		float u2 = size / 5f;
		float v2 = size / 5f;
		mpb.setUVRange(u1, v1, u2, v2);
		bl.set(0, 0, 0);
		tl.set(0, 0, size);
		tr.set(size, 0, size);
		br.set(size, 0, 0);
		// mpb.rect(bl, tl, tr, br, norm);
		int divisions = ((int)size) / 4;
		mpb.patch(bl, tl, tr, br, norm, divisions, divisions);
		Model groundModel = mb.end();
		chunk.modelInstance = new ModelInstance(groundModel);
	}

	// physical representation of the ground
	btCollisionObject groundObj = new btCollisionObject();
	btCollisionShape groundShape = new btStaticPlaneShape(Vector3.Y, 0f);
	groundObj.setCollisionShape(groundShape);
	Physics.applyStaticGeometryCollisionFlags(groundObj);
	Physics.inst.addStaticGeometryToWorld(groundObj);

	chunk.body = groundObj;
	return chunk;
}
 
Example #24
Source File: UsefulMeshs.java    From Mundus with Apache License 2.0 4 votes vote down vote up
public static Model torus(Material mat, float width, float height, int divisionsU, int divisionsV) {

        ModelBuilder modelBuilder = new ModelBuilder();
        modelBuilder.begin();
        MeshPartBuilder builder = modelBuilder.part("torus", GL20.GL_TRIANGLES, VertexAttributes.Usage.Position, mat);
        // builder.setColor(Color.LIGHT_GRAY);

        MeshPartBuilder.VertexInfo curr1 = v0.set(null, null, null, null);
        curr1.hasUV = curr1.hasNormal = false;
        curr1.hasPosition = true;

        MeshPartBuilder.VertexInfo curr2 = v1.set(null, null, null, null);
        curr2.hasUV = curr2.hasNormal = false;
        curr2.hasPosition = true;
        short i1, i2, i3 = 0, i4 = 0;

        int i, j, k;
        double s, t, twopi;
        twopi = 2 * Math.PI;

        for (i = 0; i < divisionsV; i++) {
            for (j = 0; j <= divisionsU; j++) {
                for (k = 1; k >= 0; k--) {
                    s = (i + k) % divisionsV + 0.5;
                    t = j % divisionsU;

                    curr1.position.set(
                            (float) ((width + height * Math.cos(s * twopi / divisionsV))
                                    * Math.cos(t * twopi / divisionsU)),
                            (float) ((width + height * Math.cos(s * twopi / divisionsV))
                                    * Math.sin(t * twopi / divisionsU)),
                            (float) (height * Math.sin(s * twopi / divisionsV)));
                    k--;
                    s = (i + k) % divisionsV + 0.5;
                    curr2.position.set(
                            (float) ((width + height * Math.cos(s * twopi / divisionsV))
                                    * Math.cos(t * twopi / divisionsU)),
                            (float) ((width + height * Math.cos(s * twopi / divisionsV))
                                    * Math.sin(t * twopi / divisionsU)),
                            (float) (height * Math.sin(s * twopi / divisionsV)));
                    // curr2.uv.set((float) s, 0);
                    i1 = builder.vertex(curr1);
                    i2 = builder.vertex(curr2);
                    builder.rect(i4, i2, i1, i3);
                    i4 = i2;
                    i3 = i1;
                }
            }
        }

        return modelBuilder.end();
    }
 
Example #25
Source File: Terrain.java    From Mundus with Apache License 2.0 4 votes vote down vote up
/**
 * Calculates normal of a vertex at x,y based on the verticesOnZ of the
 * surrounding vertices
 */
private MeshPartBuilder.VertexInfo calculateNormalAt(MeshPartBuilder.VertexInfo out, int x, int y) {
    out.normal.set(getNormalAt(x, y));
    return out;
}