Java 类com.badlogic.gdx.graphics.VertexAttributes 实例源码
项目:GDX-Engine
文件:TestCamera.java
@Override
public void create() {
rotationSpeed = 0.5f;
mesh = new Mesh(true, 4, 6,
new VertexAttribute(VertexAttributes.Usage.Position, 3,"attr_Position"),
new VertexAttribute(Usage.TextureCoordinates, 2, "attr_texCoords"));
texture = new Texture(Gdx.files.internal("data/Jellyfish.jpg"));
mesh.setVertices(new float[] {
-1024f, -1024f, 0, 0, 1,
1024f, -1024f, 0, 1, 1,
1024f, 1024f, 0, 1, 0,
-1024f, 1024f, 0, 0, 0
});
mesh.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
xScale = Gdx.graphics.getWidth()/(float)TARGET_WIDTH;
yScale = Gdx.graphics.getHeight()/(float)TARGET_HEIGHT;
font = loadBitmapFont("default.fnt", "default.png");
scale = Math.min(xScale, yScale);
cam.zoom = 1/scale;
// cam.project(start_position);
cam.position.set(0, 0, 0);
batch = new SpriteBatch();
}
项目:nhglib
文件:DepthMapShader.java
private String createPrefix(Renderable renderable) {
String prefix = "";
if (params.useBones) {
prefix += "#define numBones " + 12 + "\n";
final int n = renderable.meshPart.mesh.getVertexAttributes().size();
for (int i = 0; i < n; i++) {
final VertexAttribute attr = renderable.meshPart.mesh.getVertexAttributes().get(i);
if (attr.usage == VertexAttributes.Usage.BoneWeight) {
prefix += "#define boneWeight" + attr.unit + "Flag\n";
}
}
}
return prefix;
}
项目:nhglib
文件:MainDef.java
@Override
public void create() {
super.create();
geometryPass = new ShaderProgram(
Gdx.files.internal("shaders/g_buffer.vert"),
Gdx.files.internal("shaders/g_buffer.frag"));
lightingPass = new ShaderProgram(
Gdx.files.internal("shaders/deferred_shader.vert"),
Gdx.files.internal("shaders/deferred_shader.frag"));
ModelBuilder mb = new ModelBuilder();
Model cube = mb.createBox(1, 1, 1, new Material(),
VertexAttributes.Usage.Position |
VertexAttributes.Usage.Normal |
VertexAttributes.Usage.TextureCoordinates);
cubeMesh = cube.meshes.first();
}
项目:LibGDX-PBR
文件:PBRShader.java
protected final int[] getAttributeLocations(Renderable renderable) {
final IntIntMap attributes = new IntIntMap();
final VertexAttributes attrs = renderable.meshPart.mesh.getVertexAttributes();
final int c = attrs.size();
for (int i = 0; i < c; i++) {
final VertexAttribute attr = attrs.get(i);
final int location = program.getAttributeLocation(attr.alias);
if (location >= 0)
attributes.put(attr.getKey(), location);
}
tempArray.clear();
final int n = attrs.size();
for (int i = 0; i < n; i++) {
tempArray.add(attributes.get(attrs.get(i).getKey(), -1));
}
return tempArray.items;
}
项目:LibGDX-PBR
文件:PBRSadherTexture.java
protected final int[] getAttributeLocations(Renderable renderable) {
final IntIntMap attributes = new IntIntMap();
final VertexAttributes attrs = renderable.meshPart.mesh.getVertexAttributes();
final int c = attrs.size();
for (int i = 0; i < c; i++) {
final VertexAttribute attr = attrs.get(i);
final int location = program.getAttributeLocation(attr.alias);
if (location >= 0)
attributes.put(attr.getKey(), location);
}
tempArray.clear();
final int n = attrs.size();
for (int i = 0; i < n; i++) {
tempArray.add(attributes.get(attrs.get(i).getKey(), -1));
}
return tempArray.items;
}
项目:exterminate
文件:Ground.java
public void makeMesh() {
int rayon = Math.max(ExterminateGame.rendu, ExterminateGame.MAX_VIEW_DISTANCE)+5;
int nbTriangles=ChunkBuilder.GRIDSIZE*ChunkBuilder.GRIDSIZE*2*rayon*2*rayon*2;
int nbVertex=(ChunkBuilder.GRIDSIZE+1)*(ChunkBuilder.GRIDSIZE+1)*rayon*2*rayon*2;
FloatBuffer vertexL = org.lwjgl.BufferUtils.createFloatBuffer(nbVertex*ChunkBuilder.SOL_VERTICE_SIZE);
IntBuffer indicesL = org.lwjgl.BufferUtils.createIntBuffer(nbTriangles*3);
mesh = new UniMesh(true, true, nbVertex, nbTriangles*3, new VertexAttributes(VertexAttribute.Position(), VertexAttribute.NormalPacked(), VertexAttribute.TexCoords(0), VertexAttribute.ColorPacked()));
mesh.setVertices(vertexL, 0, nbVertex*ChunkBuilder.SOL_VERTICE_SIZE);
mesh.setIndices(indicesL, 0, nbTriangles*3);
mesh.setCapacity(0);
usedSol = new boolean[rayon*2*rayon*2];
forChunk = new Chunk[rayon*2*rayon*2];
for(int i=0;i<rayon*2*rayon*2;i++) {
usedSol[i] = false;
}
UniVertexBufferObject.showMem();
}
项目:eamaster
文件:SimulationRunner.java
public SimulationRunner() {
logger.info("Loading models");
ModelBuilder builder = new ModelBuilder();
models.put("box", builder.createBox(5f, 5f, 5f,
new Material(ColorAttribute.createDiffuse(new Color(0.8f, 0f, 0f, 0f))),
VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal));
G3dModelLoader loader = new G3dModelLoader(new JsonReader());
models.put("hub", loader.loadModel(Gdx.files.internal("data/hubreal.g3dj")));
models.put("rim", loader.loadModel(Gdx.files.internal("data/rimreal.g3dj")));
models.put("spoke", loader.loadModel(Gdx.files.internal("data/spoke.g3dj")));
Bullet.init();
logger.info("Initialized Bullet");
}
项目:Mundus
文件:Terrain.java
private Terrain(int vertexResolution) {
this.transform = new Matrix4();
this.attribs = MeshBuilder.createAttributes(VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal
| VertexAttributes.Usage.TextureCoordinates);
this.posPos = attribs.getOffset(VertexAttributes.Usage.Position, -1);
this.norPos = attribs.getOffset(VertexAttributes.Usage.Normal, -1);
this.uvPos = attribs.getOffset(VertexAttributes.Usage.TextureCoordinates, -1);
this.stride = attribs.vertexSize / 4;
this.vertexResolution = vertexResolution;
this.heightData = new float[vertexResolution * vertexResolution];
this.terrainTexture = new TerrainTexture();
this.terrainTexture.setTerrain(this);
material = new Material();
material.set(new TerrainTextureAttribute(TerrainTextureAttribute.ATTRIBUTE_SPLAT0, terrainTexture));
}
项目:Mundus
文件:UsefulMeshs.java
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();
}
项目:Mundus
文件:ScaleTool.java
public ScaleTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker,
ShapeRenderer shapeRenderer, ModelBatch batch, CommandHistory history) {
super(projectManager, goPicker, handlePicker, batch, history);
this.shapeRenderer = shapeRenderer;
ModelBuilder modelBuilder = new ModelBuilder();
Model xPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_X)),
Vector3.Zero, new Vector3(15, 0, 0));
Model yPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_Y)),
Vector3.Zero, new Vector3(0, 15, 0));
Model zPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_Z)),
Vector3.Zero, new Vector3(0, 0, 15));
Model xyzPlaneHandleModel = modelBuilder.createBox(3, 3, 3,
new Material(ColorAttribute.createDiffuse(COLOR_XYZ)),
VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
xHandle = new ScaleHandle(X_HANDLE_ID, xPlaneHandleModel);
yHandle = new ScaleHandle(Y_HANDLE_ID, yPlaneHandleModel);
zHandle = new ScaleHandle(Z_HANDLE_ID, zPlaneHandleModel);
xyzHandle = new ScaleHandle(XYZ_HANDLE_ID, xyzPlaneHandleModel);
handles = new ScaleHandle[] { xHandle, yHandle, zHandle, xyzHandle };
}
项目:GdxDemo3D
文件:NavMeshGraph.java
/**
* Creates Vector3 objects from the vertices of the mesh. The resulting array follows the ordering of the provided
* index array.
*
* @param mesh
* @param indices
* @return
*/
private static Vector3[] createVertexVectors(Mesh mesh, short[] indices) {
FloatBuffer verticesBuffer = mesh.getVerticesBuffer();
int positionOffset = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Position).offset / 4;
int vertexSize = mesh.getVertexSize() / 4;
Vector3[] vertexVectors = new Vector3[mesh.getNumIndices()];
for (int i = 0; i < indices.length; i++) {
short index = indices[i];
int a = index * vertexSize + positionOffset;
float x = verticesBuffer.get(a++);
float y = verticesBuffer.get(a++);
float z = verticesBuffer.get(a);
vertexVectors[index] = new Vector3(x, y, z);
}
return vertexVectors;
}
项目:libgdxcn
文件:DecalBatch.java
/** Initializes the batch with the given amount of decal objects the buffer is able to hold when full.
*
* @param size Maximum size of decal objects to hold in memory */
public void initialize (int size) {
vertices = new float[size * Decal.SIZE];
mesh = new Mesh(Mesh.VertexDataType.VertexArray, false, size * 4, size * 6, new VertexAttribute(
VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(
VertexAttributes.Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(
VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
short[] indices = new short[size * 6];
int v = 0;
for (int i = 0; i < indices.length; i += 6, v += 4) {
indices[i] = (short)(v);
indices[i + 1] = (short)(v + 2);
indices[i + 2] = (short)(v + 1);
indices[i + 3] = (short)(v + 1);
indices[i + 4] = (short)(v + 2);
indices[i + 5] = (short)(v + 3);
}
mesh.setIndices(indices);
}
项目:libgdxcn
文件:MeshBuilder.java
/** @param usage bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal and
* TextureCoordinates is supported. */
public static VertexAttributes createAttributes (long usage) {
final Array<VertexAttribute> attrs = new Array<VertexAttribute>();
if ((usage & Usage.Position) == Usage.Position)
attrs.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
if ((usage & Usage.Color) == Usage.Color) attrs.add(new VertexAttribute(Usage.Color, 4, ShaderProgram.COLOR_ATTRIBUTE));
if ((usage & Usage.ColorPacked) == Usage.ColorPacked)
attrs.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
if ((usage & Usage.Normal) == Usage.Normal)
attrs.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
if ((usage & Usage.TextureCoordinates) == Usage.TextureCoordinates)
attrs.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
final VertexAttribute attributes[] = new VertexAttribute[attrs.size];
for (int i = 0; i < attributes.length; i++)
attributes[i] = attrs.get(i);
return new VertexAttributes(attributes);
}
项目:libgdxcn
文件:IndexBufferObjectShaderTest.java
@Override
public void create () {
String vertexShader = "attribute vec4 a_position; \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoords;\n"
+ "varying vec4 v_color;" + "varying vec2 v_texCoords;" + "void main() \n"
+ "{ \n" + " v_color = vec4(a_color.x, a_color.y, a_color.z, 1); \n"
+ " v_texCoords = a_texCoords; \n" + " gl_Position = a_position; \n" + "} \n";
String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec4 v_color;\n"
+ "varying vec2 v_texCoords;\n" + "uniform sampler2D u_texture;\n" + "void main() \n"
+ "{ \n" + " gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n"
+ "}";
shader = new ShaderProgram(vertexShader, fragmentShader);
vbo = new VertexBufferObject(true, 3, new VertexAttribute(VertexAttributes.Usage.Position, 2, "a_position"),
new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, "a_texCoords"), new VertexAttribute(
VertexAttributes.Usage.ColorPacked, 4, "a_color"));
float[] vertices = new float[] {-1, -1, 0, 0, Color.toFloatBits(1f, 0f, 0f, 1f), 0, 1, 0.5f, 1.0f,
Color.toFloatBits(0f, 1f, 0f, 1f), 1, -1, 1, 0, Color.toFloatBits(0f, 0f, 1f, 1f)};
vbo.setVertices(vertices, 0, vertices.length);
ibo = new IndexBufferObject(true, 3);
ibo.setIndices(new short[] {0, 1, 2}, 0, 3);
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
}
项目:HelixEngine
文件:TileHighlightDisplayable.java
public TileHighlightDisplayable() {
ModelBuilder modelBuilder = new ModelBuilder();
Model model
= modelBuilder.createRect(0, 0, Z_OFFSET,
1, 0, Z_OFFSET,
1, 1, Z_OFFSET,
0, 1, Z_OFFSET,
0, 0, 1,
GL20.GL_TRIANGLES,
new Material(
new ColorAttribute(
ColorAttribute.createDiffuse(color)),
new BlendingAttribute(
GL20.GL_SRC_ALPHA,
GL20.GL_ONE_MINUS_SRC_ALPHA)),
VertexAttributes.Usage.Position |
VertexAttributes.Usage.TextureCoordinates);
instance = new ModelInstance(model);
}
项目:gaiasky
文件:MeshBuilder2.java
/** @param usage bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal and
* TextureCoordinates is supported. */
public static VertexAttributes createAttributes(long usage) {
final Array<VertexAttribute> attrs = new Array<VertexAttribute>();
if ((usage & Usage.Position) == Usage.Position)
attrs.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
if ((usage & Usage.ColorUnpacked) == Usage.ColorUnpacked)
attrs.add(new VertexAttribute(Usage.ColorUnpacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
if ((usage & Usage.ColorPacked) == Usage.ColorPacked)
attrs.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
if ((usage & Usage.Normal) == Usage.Normal)
attrs.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
if ((usage & Usage.TextureCoordinates) == Usage.TextureCoordinates)
attrs.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
final VertexAttribute attributes[] = new VertexAttribute[attrs.size];
for (int i = 0; i < attributes.length; i++)
attributes[i] = attrs.get(i);
return new VertexAttributes(attributes);
}
项目:libgdx-opencl
文件:LibraryTest.java
@Override
public void create ()
{
// Init camera
this.camera = new PerspectiveCamera(70, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
this.camera.position.set(0,0,-20);
this.camera.lookAt(0,0,0);
this.camera.near = 0.05f;
this.camera.far = 600.0f;
this.camera.update();
// Init test shader
this.testShader = ShaderLoader.loadShader("test");
// Init test buffer
this.testBufferObject = new DynamicVertexBufferObject(3, new VertexAttributes(new VertexAttribute(Usage.Position, 4, "a_position")));
float[] vertices = new float[]
{
-10,0,0,1,0,2.5f,0,1,10,0,0,1
};
this.testBufferObject.setVertices(vertices, 0, vertices.length);
}
项目:BotLogic
文件:MeshAssembler.java
public VertexAttribute[] getVertexAttributes() {
if (attributes == null){
this.attributes = new ArrayList<VertexAttribute>();
}
this.attributes.clear();
if (isUsing(MeshVertexData.AttributeType.Position)) {
attributes.add(new VertexAttribute(VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
}
if (isUsing(MeshVertexData.AttributeType.Normal)) {
attributes.add(new VertexAttribute(VertexAttributes.Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
}
if (isUsing(MeshVertexData.AttributeType.TextureCord)) {
attributes.add(new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE+ "0"));
}
if (isUsing(MeshVertexData.AttributeType.Color)) {
attributes.add(new VertexAttribute(VertexAttributes.Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
}
return attributes.toArray(new VertexAttribute[attributes.size()]);
}
项目:ingress-indonesia-dev
文件:VertexBufferObjectSubData.java
public VertexBufferObjectSubData(boolean paramBoolean, int paramInt, VertexAttribute[] paramArrayOfVertexAttribute)
{
this.isStatic = paramBoolean;
this.attributes = new VertexAttributes(paramArrayOfVertexAttribute);
this.byteBuffer = BufferUtils.newByteBuffer(paramInt * this.attributes.vertexSize);
this.isDirect = true;
if (paramBoolean);
for (int i = 35044; ; i = 35048)
{
this.usage = i;
this.buffer = this.byteBuffer.asFloatBuffer();
this.bufferHandle = createBufferObject();
this.buffer.flip();
this.byteBuffer.flip();
return;
}
}
项目:ingress-indonesia-dev
文件:VertexBufferObject.java
public VertexBufferObject(boolean paramBoolean, int paramInt, VertexAttributes paramVertexAttributes)
{
this.isStatic = paramBoolean;
this.attributes = paramVertexAttributes;
this.attributeIndexCache = new int[paramVertexAttributes.size()];
this.byteBuffer = BufferUtils.newUnsafeByteBuffer(paramInt * this.attributes.vertexSize);
this.buffer = this.byteBuffer.asFloatBuffer();
this.buffer.flip();
this.byteBuffer.flip();
if (paramBoolean);
for (int i = 35044; ; i = 35048)
{
this.usage = i;
this.bufferHandle = createBufferObject();
return;
}
}
项目:ingress-indonesia-dev
文件:n.java
private static s a(int paramInt, VertexAttributes paramVertexAttributes, FloatBuffer paramFloatBuffer, ShortBuffer paramShortBuffer1, ShortBuffer paramShortBuffer2)
{
paramFloatBuffer.flip();
paramShortBuffer1.flip();
paramShortBuffer2.flip();
Mesh localMesh = new Mesh(true, paramFloatBuffer.limit() / paramInt, paramShortBuffer1.limit(), paramVertexAttributes);
localMesh.setVertices(paramFloatBuffer.array(), 0, paramFloatBuffer.limit());
localMesh.setIndices(paramShortBuffer1.array(), 0, paramShortBuffer1.limit());
short[] arrayOfShort = new short[paramShortBuffer2.limit()];
System.arraycopy(paramShortBuffer2.array(), 0, arrayOfShort, 0, arrayOfShort.length);
s locals = new s(localMesh, arrayOfShort);
paramFloatBuffer.clear();
paramShortBuffer1.clear();
paramShortBuffer2.clear();
return locals;
}
项目:Cubes_2
文件:AreaMesh.java
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);
}
项目:Cubes
文件:AreaMesh.java
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);
}
项目:exterminate
文件:UniVertexBufferObject.java
/** Constructs a new interleaved VertexBufferObject.
*
* @param isStatic whether the vertex data is static.
* @param numVertices the maximum number of vertices
* @param attributes the {@link VertexAttributes}. */
public UniVertexBufferObject (boolean isStatic, int numVertices, VertexAttributes attributes) {
this.isStatic = isStatic;
this.attributes = attributes;
capacity = this.attributes.vertexSize * numVertices;
bufferHandle = createBufferObject();
usage = isStatic ? GL20.GL_STATIC_DRAW : GL20.GL_DYNAMIC_DRAW;
}
项目:Argent
文件:WorldObjectCharacter.java
public static WorldObjectCharacter createDefaultPlayerCharacter(GameWorld.Generic world) {
modelBuilder.begin();
MeshPartBuilder builder = modelBuilder.part("player_body", GL30.GL_TRIANGLES, VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates, Reference.Defaults.Models.material());
CapsuleShapeBuilder.build(builder, 75, 500, 64);
WorldObject obj = new WorldObject(world, new ModelInstance(modelBuilder.end()));
if(world instanceof GameWorld.Physics) {
world.addInstance(new BulletEntity<>(world, obj.transform(), obj));
}else{
world.addInstance(obj);
}
return new WorldObjectCharacter(obj);
}
项目:Chemtris
文件:Hydrogen.java
public Hydrogen(int ve, boolean[][][] mtx, PerspectiveCamera cam) {
super(ve, mtx, cam);
//begin building the model
hydrogen_builder.begin();
//first node
Node electron_1 = hydrogen_builder.node();
electron_1.id = Hydrogen.VE_1;
//make the cube
hydrogen_builder.part(Hydrogen.VE_1, GL20.GL_TRIANGLES, VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal,
new Material(ColorAttribute.createDiffuse(new Color(195f/255f,207f/255f,255f/255f,1f))))
.box(1f, 1f, 1f);
//end the model
Model hModel = hydrogen_builder.end();
atom = new ModelInstance(hModel,2,10,2);
shadow = new ModelInstance(hModel,2,10,2);
frame = new ModelInstance(hModel,2,10,2);
frame.transform.scl(.01f);
for(int i = 0; i < shadow.materials.size; ++i){
shadow.materials.get(i).set(ColorAttribute.createDiffuse(105/255f,105/255f,105/255f,1f));
frame.materials.get(i).set(ColorAttribute.createDiffuse(Color.WHITE));
}
}
项目:origin
文件:Icosahedron.java
/**
* создать икосаэдр
* @param depth глубина для деления треугольников
* @param mult на это умножаем кажду вершину (радиус)
*/
public Icosahedron(int depth, float mult)
{
_mult = mult;
for (int i = 0; i < indices.length; i++)
{
subdivide(
vdata[indices[i][0]],
vdata[indices[i][1]],
vdata[indices[i][2]],
depth
);
}
_mesh = new Mesh(
true, _vertices.size(), 0,
new VertexAttribute(
VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE
)
// new VertexAttribute(VertexAttributes.Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)
);
float[] v = new float[_vertices.size()];
for (int i = 0; i < v.length; i++)
{
v[i] = _vertices.get(i);
}
_mesh.setVertices(v);
}
项目:origin
文件:GridChunk.java
private void makeWater()
{
final float x = _gx + _cx;
final float y = _gy + _cy;
_waterMesh = new Mesh(
true,
4,
6,
new VertexAttribute(VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
new VertexAttribute(VertexAttributes.Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE),
new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE)
);
float[] vertices = new float[]{
x, WATER_LEVEL, y, 0, 1, 0, 0, 0,
x + CHUNK_SIZE, WATER_LEVEL, y, 0, 1, 0, 1, 0,
x, WATER_LEVEL, y + CHUNK_SIZE, 0, 1, 0, 0, 1,
x + CHUNK_SIZE, WATER_LEVEL, y + CHUNK_SIZE, 0, 1, 0, 1, 1
};
short[] indices = new short[]{
0, 2, 1,
1, 2, 3
};
_waterMesh.setVertices(vertices);
_waterMesh.setIndices(indices);
}
项目:DoubleHelix
文件:BillboardDecalBatch.java
public void initialize (int size) {
vertices = new float[size * BillboardDecal.VERTEX_SIZE];
Mesh.VertexDataType vertexDataType = Mesh.VertexDataType.VertexArray;
if(Gdx.gl30 != null) {
vertexDataType = Mesh.VertexDataType.VertexBufferObjectWithVAO;
}
mesh = new Mesh(vertexDataType, false, size, 0, new VertexAttribute(
VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(
VertexAttributes.Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(
VertexAttributes.Usage.Generic, 1, SIZE_ATTRIBUTE), new VertexAttribute(
VertexAttributes.Usage.Generic, 1, ROTATION_ATTRIBUTE));
}
项目:libgdx-shaders
文件:FrameBufferScreen.java
private void build() {
region = new TextureRegion(assetManager.<Texture>get("img/lena.png"));
shaderManager.createFrameBuffer("frameBuffer01");
final MeshBuilder meshBuilder = new MeshBuilder();
meshBuilder.begin(VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked | VertexAttributes.Usage.TextureCoordinates, GL20.GL_TRIANGLES);
meshBuilder.rect(
0f, 200f, 0f,
200f, 200f, 0f,
200f, 0f, 0f,
0f, 0f, 0f,
0f, 0f, 0f);
rectangle = meshBuilder.end();
}
项目:Radix
文件:GameRenderer.java
private void drawBlockSelection() {
int curProgressInt = Math.round(RadixClient.getInstance().getPlayer().getBreakPercent() * 10) - 1;
if ((blockBreakModel == null || blockBreakStage != curProgressInt) && curProgressInt >= 0) {
if (blockBreakModel != null)
blockBreakModel.dispose();
blockBreakStage = curProgressInt;
ModelBuilder builder = new ModelBuilder();
blockBreakModel = builder.createBox(1f, 1f, 1f,
new Material(TextureAttribute.createDiffuse(blockBreakStages[blockBreakStage]),
new BlendingAttribute(),
FloatAttribute.createAlphaTest(0.25f)),
VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates);
blockBreakModelInstance = new ModelInstance(blockBreakModel);
}
Vec3i curBlk = RadixClient.getInstance().getSelectedBlock();
if (curBlk != null && curProgressInt >= 0) {
Gdx.gl.glPolygonOffset(100000, 2000000);
blockOverlayBatch.begin(RadixClient.getInstance().getCamera());
blockBreakModelInstance.transform.translate(curBlk.x + 0.5f, curBlk.y + 0.5f, curBlk.z + 0.5f);
blockOverlayBatch.render(blockBreakModelInstance);
blockBreakModelInstance.transform.translate(-(curBlk.x + 0.5f), -(curBlk.y + 0.5f), -(curBlk.z + 0.5f));
blockOverlayBatch.end();
Gdx.gl.glPolygonOffset(100000, -2000000);
}
}
项目:Radix
文件:GreedyMesher.java
public Mesh meshFaces(List<Face> faces, MeshBuilder builder) {
builder.begin(VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates | VertexAttributes.Usage.ColorPacked | VertexAttributes.Usage.Normal, GL20.GL_TRIANGLES);
builder.ensureVertices(faces.size() * 4);
for (Face f : faces) {
f.render(builder);
}
return builder.end();
}
项目:Mundus
文件:Skybox.java
private Model createModel() {
ModelBuilder modelBuilder = new ModelBuilder();
Model model = modelBuilder.createBox(1, 1, 1,
new Material(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap)),
VertexAttributes.Usage.Position);
return model;
}
项目:Mundus
文件:UsefulMeshs.java
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();
}
项目:Mundus
文件:TranslateTool.java
public TranslateTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker,
ModelBatch batch, CommandHistory history) {
super(projectManager, goPicker, handlePicker, batch, history);
ModelBuilder modelBuilder = new ModelBuilder();
Model xHandleModel = modelBuilder.createArrow(0, 0, 0, 1, 0, 0, ARROW_CAP_SIZE, ARROW_THIKNESS, ARROW_DIVISIONS,
GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(COLOR_X)),
VertexAttributes.Usage.Position);
Model yHandleModel = modelBuilder.createArrow(0, 0, 0, 0, 1, 0, ARROW_CAP_SIZE, ARROW_THIKNESS, ARROW_DIVISIONS,
GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(COLOR_Y)),
VertexAttributes.Usage.Position);
Model zHandleModel = modelBuilder.createArrow(0, 0, 0, 0, 0, 1, ARROW_CAP_SIZE, ARROW_THIKNESS, ARROW_DIVISIONS,
GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(COLOR_Z)),
VertexAttributes.Usage.Position);
Model xzPlaneHandleModel = modelBuilder.createSphere(1, 1, 1, 20, 20,
new Material(ColorAttribute.createDiffuse(COLOR_XZ)), VertexAttributes.Usage.Position);
xHandle = new TranslateHandle(X_HANDLE_ID, xHandleModel);
yHandle = new TranslateHandle(Y_HANDLE_ID, yHandleModel);
zHandle = new TranslateHandle(Z_HANDLE_ID, zHandleModel);
xzPlaneHandle = new TranslateHandle(XZ_HANDLE_ID, xzPlaneHandleModel);
handles = new TranslateHandle[] { xHandle, yHandle, zHandle, xzPlaneHandle };
gameObjectModifiedEvent = new GameObjectModifiedEvent(null);
}
项目:GdxDemo3D
文件:NavMeshGraph.java
/**
* Get an array of the vertex indices from the mesh. Any vertices which share the same position will be counted
* as a single vertex and share the same index. That is, position duplicates will be filtered out.
*
* @param mesh
* @return
*/
private static short[] getUniquePositionVertexIndices(Mesh mesh) {
FloatBuffer verticesBuffer = mesh.getVerticesBuffer();
int positionOffset = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Position).offset / 4;
// Number of array elements which make up a vertex
int vertexSize = mesh.getVertexSize() / 4;
// The indices tell us which vertices are part of a triangle.
short[] indices = new short[mesh.getNumIndices()];
mesh.getIndices(indices);
// Marks true if an index has already been compared to avoid unnecessary comparisons
Bits handledIndices = new Bits(mesh.getNumIndices());
for (int i = 0; i < indices.length; i++) {
short indexI = indices[i];
if (handledIndices.get(indexI)) {
// Index handled in an earlier iteration
continue;
}
int vBufIndexI = indexI * vertexSize + positionOffset;
float xi = verticesBuffer.get(vBufIndexI++);
float yi = verticesBuffer.get(vBufIndexI++);
float zi = verticesBuffer.get(vBufIndexI++);
for (int j = i + 1; j < indices.length; j++) {
short indexJ = indices[j];
int vBufIndexJ = indexJ * vertexSize + positionOffset;
float xj = verticesBuffer.get(vBufIndexJ++);
float yj = verticesBuffer.get(vBufIndexJ++);
float zj = verticesBuffer.get(vBufIndexJ++);
if (xi == xj && yi == yj && zi == zj) {
indices[j] = indexI;
}
}
handledIndices.set(indexI);
}
return indices;
}
项目:nvlist
文件:TriangleGrid.java
/**
* @return The memory layout used by the mesh.
*/
public VertexAttributes getVertexAttributes() {
List<VertexAttribute> list = Lists.newArrayList();
list.add(new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE));
list.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
for (int t = 0; t < getTextures(); t++) {
list.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + t));
}
return new VertexAttributes(list.toArray(new VertexAttribute[list.size()]));
}
项目:3D-TETRIS
文件:PiecesEasy.java
public PiecesEasy(){
mb = new ModelBuilder();
model = mb.createBox(1f,1f,1f,
new Material(ColorAttribute.createDiffuse(Color.WHITE)),
VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
shadowModel = mb.createBox(1f,1f,1f,
new Material(ColorAttribute.createDiffuse(Color.GRAY)),
VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
a = new ModelInstance(model);
b = new ModelInstance(model);
c = new ModelInstance(model);
d = new ModelInstance(model);
e = new ModelInstance(shadowModel);
f = new ModelInstance(shadowModel);
g = new ModelInstance(shadowModel);
h = new ModelInstance(shadowModel);
parts = new Array<ModelInstance>();
parts.add(a);
parts.add(b);
parts.add(c);
parts.add(d);
a.transform.setToTranslation(11f, 0f, 12f);
a.transform.translate(0f,8f,0f);
base = new Vector3();
}
项目:3D-TETRIS
文件:Platform.java
public Platform() {
mb = new ModelBuilder();
black = mb.createBox(1f, 1f, 1f,
new Material(ColorAttribute.createDiffuse(Color.BLACK)),
VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
magenta = mb.createBox(1f, 1f, 1f,
new Material(ColorAttribute.createDiffuse(Color.MAGENTA)),
VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
instances = new Array<ModelInstance>();
}
项目:3D-TETRIS
文件:Pieces.java
public Pieces(){
mb = new ModelBuilder();
model = mb.createBox(1f,1f,1f,
new Material(ColorAttribute.createDiffuse(Color.WHITE)),
VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
shadowModel = mb.createBox(1f,1f,1f,
new Material(ColorAttribute.createDiffuse(Color.GRAY)),
VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
a = new ModelInstance(model);
b = new ModelInstance(model);
c = new ModelInstance(model);
d = new ModelInstance(model);
e = new ModelInstance(shadowModel);
f = new ModelInstance(shadowModel);
g = new ModelInstance(shadowModel);
h = new ModelInstance(shadowModel);
parts = new Array<ModelInstance>();
parts.add(a);
parts.add(b);
parts.add(c);
parts.add(d);
a.transform.setToTranslation(13f, 0f, 14f);
a.transform.translate(0f,8f,0f);
base = new Vector3();
}