com.badlogic.gdx.graphics.VertexAttributes.Usage Java Examples

The following examples show how to use com.badlogic.gdx.graphics.VertexAttributes.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: 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 #2
Source File: Renderer20.java    From fluid-simulator-v2 with Apache License 2.0 6 votes vote down vote up
public Renderer20 (int maxVertices, boolean hasNormals, boolean hasColors, int numTexCoords, ShaderProgram shader) {
	this.maxVertices = maxVertices;
	this.numTexCoords = numTexCoords;
	this.shader = shader;

	VertexAttribute[] attribs = buildVertexAttributes(hasNormals, hasColors, numTexCoords);
	mesh = new Mesh(false, maxVertices, 0, attribs);

	vertices = new float[maxVertices * (mesh.getVertexAttributes().vertexSize / 4)];
	vertexSize = mesh.getVertexAttributes().vertexSize / 4;
	normalOffset = mesh.getVertexAttribute(Usage.Normal) != null ? mesh.getVertexAttribute(Usage.Normal).offset / 4 : 0;
	colorOffset = mesh.getVertexAttribute(Usage.ColorPacked) != null ? mesh.getVertexAttribute(Usage.ColorPacked).offset / 4
		: 0;
	texCoordOffset = mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? mesh
		.getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0;
}
 
Example #3
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 #4
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 #5
Source File: SimpleRoom.java    From gdx-vr with Apache License 2.0 6 votes vote down vote up
@Override
public void create() {
	assets = new AssetManager();
	String model = "Bambo_House.g3db";
	assets.load(model, Model.class);
	assets.finishLoading();
	modelInstance = new ModelInstance(assets.get(model, Model.class), new Matrix4().setToScaling(0.6f, 0.6f, 0.6f));

	DefaultShader.Config config = new Config();
	config.defaultCullFace = GL20.GL_NONE;
	ShaderProvider shaderProvider = new DefaultShaderProvider(config);
	modelBatch = new ModelBatch(shaderProvider);

	ModelBuilder builder = new ModelBuilder();
	float groundSize = 1000f;
	ground = new ModelInstance(builder.createRect(-groundSize, 0, groundSize, groundSize, 0, groundSize, groundSize, 0, -groundSize, -groundSize, 0, -groundSize, 0,
			1, 0, new Material(), Usage.Position | Usage.Normal), new Matrix4().setToTranslation(0, -0.01f, 0));
	environment = new Environment();
	environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
	environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

	VirtualReality.renderer.listeners.add(this);
	// VirtualReality.head.setCyclops(true);
}
 
Example #6
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 #7
Source File: PositionalLight.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
PositionalLight( RayHandler rayHandler, int rays, Color color, float distance, float x, float y, float directionDegree ) {
	super( rayHandler, rays, color, directionDegree, distance );
	start.x = x;
	start.y = y;
	sin = new float[ rays ];
	cos = new float[ rays ];
	endX = new float[ rays ];
	endY = new float[ rays ];

	lightMesh = new Mesh( VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute( Usage.Position, 2,
			"vertex_positions" ), new VertexAttribute( Usage.ColorPacked, 4, "quad_colors" ), new VertexAttribute(
			Usage.Generic, 1, "s" ) );
	softShadowMesh = new Mesh( VertexDataType.VertexArray, staticLight, vertexNum * 2, 0, new VertexAttribute(
			Usage.Position, 2, "vertex_positions" ), new VertexAttribute( Usage.ColorPacked, 4, "quad_colors" ),
			new VertexAttribute( Usage.Generic, 1, "s" ) );

	setMesh();
}
 
Example #8
Source File: DirectionalLight.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
/**
 * Creates directional light which source is at infinite distance,
 * direction and intensity is same everywhere
 * 
 * <p>-90 direction is straight from up
 * 
 * @param rayHandler
 *            not {@code null} instance of RayHandler
 * @param rays
 *            number of rays - more rays make light to look more realistic
 *            but will decrease performance, can't be less than MIN_RAYS
 * @param color
 *            color, set to {@code null} to use the default color
 * @param directionDegree
 *            direction in degrees
 */
public DirectionalLight(RayHandler rayHandler, int rays, Color color,
		float directionDegree) {
	
	super(rayHandler, rays, color, Float.POSITIVE_INFINITY, directionDegree);
	
	vertexNum = (vertexNum - 1) * 2;
	start = new Vector2[rayNum];
	end = new Vector2[rayNum];
	for (int i = 0; i < rayNum; i++) {
		start[i] = new Vector2();
		end[i] = new Vector2();
	}
	
	lightMesh = new Mesh(
			VertexDataType.VertexArray, staticLight, vertexNum, 0,
			new VertexAttribute(Usage.Position, 2, "vertex_positions"),
			new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
			new VertexAttribute(Usage.Generic, 1, "s"));
	softShadowMesh = new Mesh(
			VertexDataType.VertexArray, staticLight, vertexNum, 0,
			new VertexAttribute(Usage.Position, 2, "vertex_positions"),
			new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
			new VertexAttribute(Usage.Generic, 1, "s"));
	
	update();
}
 
Example #9
Source File: FullscreenQuad.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
private Mesh createFullscreenQuad() {
	// vertex coord
	verts[X1] = -1;
	verts[Y1] = -1;

	verts[X2] = 1;
	verts[Y2] = -1;

	verts[X3] = 1;
	verts[Y3] = 1;

	verts[X4] = -1;
	verts[Y4] = 1;

	// tex coords
	verts[U1] = 0f;
	verts[V1] = 0f;

	verts[U2] = 1f;
	verts[V2] = 0f;

	verts[U3] = 1f;
	verts[V3] = 1f;

	verts[U4] = 0f;
	verts[V4] = 1f;

	Mesh tmpMesh = new Mesh( VertexDataType.VertexArray, true, 4, 0, new VertexAttribute( Usage.Position, 2, "a_position" ),
			new VertexAttribute( Usage.TextureCoordinates, 2, "a_texCoord0" ) );

	tmpMesh.setVertices( verts );
	return tmpMesh;
}
 
Example #10
Source File: Renderer20.java    From fluid-simulator-v2 with Apache License 2.0 5 votes vote down vote up
private VertexAttribute[] buildVertexAttributes (boolean hasNormals, boolean hasColor, int numTexCoords) {
	Array<VertexAttribute> attribs = new Array<VertexAttribute>();
	attribs.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
	if (hasNormals) attribs.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
	if (hasColor) attribs.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
	for (int i = 0; i < numTexCoords; i++) {
		attribs.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + i));
	}
	VertexAttribute[] array = new VertexAttribute[attribs.size];
	for (int i = 0; i < attribs.size; i++)
		array[i] = attribs.get(i);
	return array;
}
 
Example #11
Source File: FluidSimulatorGeneric.java    From fluid-simulator-v2 with Apache License 2.0 5 votes vote down vote up
public FluidSimulatorGeneric(FluidSimulatorStarter fluidSimulatorStarter) {
		this.game = fluidSimulatorStarter;
		// LibGDX single batches cannot have a size more than 5460
		batch = new SpriteBatch(IS_DESKTOP ? 5460 : ANDROID_SIZE);
		font = new BitmapFont();
		camera = new OrthographicCamera(WORLD_WIDTH, WORLD_HEIGHT);
		camera.position.set(0, (WORLD_HEIGHT / 2) - 1, 0);
		immediateRenderer = new ImmediateModeRenderer20(SIZE*6, false, true, 0);
		irt = new Renderer20(SIZE*6, false, true, 1);
		irt2 = new ImmediateModeRenderer20(SIZE*11, false, true, 1);
		shapeRenderer = new ShapeRenderer(SIZE);
		renderer = new Box2DDebugRenderer(true, true, false, true, false, false);
		
		//3D
		camera3D = new PerspectiveCamera(67, WORLD_WIDTH, WORLD_HEIGHT);
		camera3D.position.set(0, 130f, 250f);
		camera3D.lookAt(0,150f,0);
		camera3D.near = 0.1f;
		camera3D.far = 500f;
		camera3D.update();
		ModelBuilder modelBuilder = new ModelBuilder();
//        model = modelBuilder.createSphere(5f, 5f, 5f, 4, 4, GL10.GL_TRIANGLES,
//                new Material(ColorAttribute.createDiffuse(Color.GREEN)),
//                Usage.Position | Usage.Normal);
        model = modelBuilder.createBox(5f, 5f, 5f,
            new Material(ColorAttribute.createDiffuse(Color.GREEN)),
            Usage.Position | Usage.Normal);
        instance = new ModelInstance(model);
        modelBatch = new ModelBatch();
        environment = new Environment();
        environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
        environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, 0, -0.8f, -0.2f));
        camController = new Camera3DController(camera3D);
        camController.setFluidSimulator(this);
		
		world = new World(new Vector2(0, -9.8f), false);
		world.setContactListener(this);
	}
 
Example #12
Source File: FullscreenQuad.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private Mesh createFullscreenQuad () {
	// vertex coord
	verts[X1] = -1;
	verts[Y1] = -1;

	verts[X2] = 1;
	verts[Y2] = -1;

	verts[X3] = 1;
	verts[Y3] = 1;

	verts[X4] = -1;
	verts[Y4] = 1;

	// tex coords
	verts[U1] = 0f;
	verts[V1] = 0f;

	verts[U2] = 1f;
	verts[V2] = 0f;

	verts[U3] = 1f;
	verts[V3] = 1f;

	verts[U4] = 0f;
	verts[V4] = 1f;

	Mesh tmpMesh = new Mesh(VertexDataType.VertexArray, true, 4, 0, new VertexAttribute(Usage.Position, 2, "a_position"),
		new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0"));

	tmpMesh.setVertices(verts);
	return tmpMesh;
}
 
Example #13
Source File: GameWorldRenderer.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private void createBackPlane () {
	plane = new Mesh(true, 4, 4, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
		new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));

	// @formatter:off
	float size = 10f;
	float verts[] = {-size / 2, 0, size / 2, size / 2, 0, size / 2, size / 2, 0, -size / 2, -size / 2, 0, -size / 2};
	// float verts[] = {size, 0, size, size, 0, 0, 0, 0, 0, 0, 0, size};

	float normals[] = {0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0};
	// @formatter:on

	int vidx = 0, nidx = 0;
	int length = 6 * 4;
	float[] vertices = new float[length];
	for (int i = 0; i < length;) {
		vertices[i++] = verts[vidx++];
		vertices[i++] = verts[vidx++];
		vertices[i++] = verts[vidx++];
		vertices[i++] = normals[nidx++];
		vertices[i++] = normals[nidx++];
		vertices[i++] = normals[nidx++];
	}

	plane.setVertices(vertices);
	plane.setIndices(new short[] {0, 1, 2, 3});
}
 
Example #14
Source File: LightMap.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
private Mesh createLightMapMesh() {
	float[] verts = new float[VERT_SIZE];
	// vertex coord
	verts[X1] = -1;
	verts[Y1] = -1;

	verts[X2] = 1;
	verts[Y2] = -1;

	verts[X3] = 1;
	verts[Y3] = 1;

	verts[X4] = -1;
	verts[Y4] = 1;

	// tex coords
	verts[U1] = 0f;
	verts[V1] = 0f;

	verts[U2] = 1f;
	verts[V2] = 0f;

	verts[U3] = 1f;
	verts[V3] = 1f;

	verts[U4] = 0f;
	verts[V4] = 1f;

	Mesh tmpMesh = new Mesh(true, 4, 0, new VertexAttribute(
			Usage.Position, 2, "a_position"), new VertexAttribute(
			Usage.TextureCoordinates, 2, "a_texCoord"));

	tmpMesh.setVertices(verts);
	return tmpMesh;

}
 
Example #15
Source File: DirectionalLight.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
/**
 * Directional lights simulate light source that locations is at infinite
 * distance. Direction and intensity is same everywhere. -90 direction is
 * straight from up.
 * 
 * @param rayHandler
 * @param rays
 * @param color
 * @param directionDegree
 */
public DirectionalLight( RayHandler rayHandler, int rays, Color color, float directionDegree ) {

	super( rayHandler, rays, color, directionDegree, Float.POSITIVE_INFINITY );

	vertexNum = (vertexNum - 1) * 2;

	start = new Vector2[ rayNum ];
	end = new Vector2[ rayNum ];
	for( int i = 0; i < rayNum; i++ ) {
		start[i] = new Vector2();
		end[i] = new Vector2();
	}
	setDirection( direction );

	// lightMesh = new Mesh(staticLight, vertexNum, 0, new VertexAttribute(
	// Usage.Position, 2, "vertex_positions"), new VertexAttribute(
	// Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(
	// Usage.Generic, 1, "s"));
	//
	// softShadowMesh = new Mesh(staticLight, vertexNum, 0,
	// new VertexAttribute(Usage.Position, 2, "vertex_positions"),
	// new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
	// new VertexAttribute(Usage.Generic, 1, "s"));

	lightMesh = new Mesh( VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute( Usage.Position, 2,
			"vertex_positions" ), new VertexAttribute( Usage.ColorPacked, 4, "quad_colors" ), new VertexAttribute(
			Usage.Generic, 1, "s" ) );

	softShadowMesh = new Mesh( VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute( Usage.Position, 2,
			"vertex_positions" ), new VertexAttribute( Usage.ColorPacked, 4, "quad_colors" ), new VertexAttribute(
			Usage.Generic, 1, "s" ) );

	update();
}
 
Example #16
Source File: ChainLight.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
/**
 * Creates chain light from specified vertices
 * 
 * @param rayHandler
 *            not {@code null} instance of RayHandler
 * @param rays
 *            number of rays - more rays make light to look more realistic
 *            but will decrease performance, can't be less than MIN_RAYS
 * @param color
 *            color, set to {@code null} to use the default color
 * @param distance
 *            distance of light
 * @param rayDirection
 *            direction of rays
 *            <ul>
 *            <li>1 = left</li>
 *            <li>-1 = right</li>
 *            </ul>
 * @param chain
 *            float array of (x, y) vertices from which rays will be
 *            evenly distributed
 */
public ChainLight(RayHandler rayHandler, int rays, Color color,
		float distance, int rayDirection, float[] chain) {
	
	super(rayHandler, rays, color, distance, 0f);
	rayStartOffset = ChainLight.defaultRayStartOffset;
	this.rayDirection = rayDirection;
	vertexNum = (vertexNum - 1) * 2;
	endX = new float[rays];
	endY = new float[rays];
	startX = new float[rays];
	startY = new float[rays];
	this.chain = (chain != null) ?
				 new FloatArray(chain) : new FloatArray();
	
	lightMesh = new Mesh(
			VertexDataType.VertexArray, false, vertexNum, 0,
			new VertexAttribute(Usage.Position, 2, "vertex_positions"),
			new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
			new VertexAttribute(Usage.Generic, 1, "s"));
	softShadowMesh = new Mesh(
			VertexDataType.VertexArray, false, vertexNum * 2,
			0, new VertexAttribute(Usage.Position, 2, "vertex_positions"),
			new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
			new VertexAttribute(Usage.Generic, 1, "s"));
	setMesh();
}
 
Example #17
Source File: G3dtLoader.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private static VertexAttribute[] createVertexAttributes (boolean hasNormals, int uvs) {
	VertexAttribute[] attributes = new VertexAttribute[1 + (hasNormals ? 1 : 0) + uvs];
	int idx = 0;
	attributes[idx++] = new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE);
	if (hasNormals) attributes[idx++] = new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE);
	for (int i = 0; i < uvs; i++) {
		attributes[idx++] = new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + i);
	}
	return attributes;
}
 
Example #18
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 #19
Source File: LightMap.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private Mesh createLightMapMesh() {
	// vertex coord
	verts[X1] = -1;
	verts[Y1] = -1;

	verts[X2] = 1;
	verts[Y2] = -1;

	verts[X3] = 1;
	verts[Y3] = 1;

	verts[X4] = -1;
	verts[Y4] = 1;

	// tex coords
	verts[U1] = 0f;
	verts[V1] = 0f;

	verts[U2] = 1f;
	verts[V2] = 0f;

	verts[U3] = 1f;
	verts[V3] = 1f;

	verts[U4] = 0f;
	verts[V4] = 1f;

	Mesh tmpMesh = new Mesh( true, 4, 0, new VertexAttribute( Usage.Position, 2, "a_position" ), new VertexAttribute(
			Usage.TextureCoordinates, 2, "a_texCoord" ) );

	tmpMesh.setVertices( verts );
	return tmpMesh;

}
 
Example #20
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 #21
Source File: ViewportQuadMesh.java    From gdx-vfx with Apache License 2.0 4 votes vote down vote up
public ViewportQuadMesh() {
	this(new VertexAttribute(Usage.Position, 2, "a_position"),
			new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0"));
}
 
Example #22
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 #23
Source File: PositionalLight.java    From box2dlights with Apache License 2.0 3 votes vote down vote up
/** 
 * Creates new positional light and automatically adds it to the specified
 * {@link RayHandler} instance.
 * 
 * @param rayHandler
 *            not null instance of RayHandler
 * @param rays
 *            number of rays - more rays make light to look more realistic
 *            but will decrease performance, can't be less than MIN_RAYS
 * @param color
 *            light color
 * @param distance
 *            light distance (if applicable)
 * @param x
 *            horizontal position in world coordinates
 * @param y
 *            vertical position in world coordinates
 * @param directionDegree
 *            direction in degrees (if applicable) 
 */
public PositionalLight(RayHandler rayHandler, int rays, Color color, float distance, float x, float y, float directionDegree) {
	super(rayHandler, rays, color, distance, directionDegree);
	start.x = x;
	start.y = y;

	lightMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum, 0, new VertexAttribute(Usage.Position, 2,
		"vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
		new VertexAttribute(Usage.Generic, 1, "s"));
	softShadowMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum * 2, 0, new VertexAttribute(Usage.Position, 2,
		"vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
		new VertexAttribute(Usage.Generic, 1, "s"));
	setMesh();
}