import com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor;
import com.badlogic.gdx.graphics.g3d.utils.TextureProvider;
import com.badlogic.gdx.graphics.g3d.utils.TextureProvider.FileTextureProvider;
+import com.badlogic.gdx.math.collision.BoundingBox;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.BufferUtils;
import com.badlogic.gdx.utils.ObjectMap;
node.calculateTransforms(true);
}
}
+
+ private final BoundingBox meshBounds = new BoundingBox();
+ public BoundingBox getBoundingBox(final BoundingBox out) {
+ out.inf();
+ for (Mesh mesh : meshes) {
+ mesh.calculateBoundingBox(meshBounds);
+ out.ext(meshBounds);
+ }
+ return out;
+ }
}
\ No newline at end of file
package com.badlogic.gdx.graphics.g3d;
+import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.g3d.test.Light;
import com.badlogic.gdx.graphics.g3d.utils.DefaultRenderableSorter;
Renderable renderable = renderables.get(i);
renderable.lights = lights;
renderable.shader = shader;
- renderable.shader = shader;
+ renderable.transform.set(transform);
// renderable.transform; FIXME multiply transform!
reuseableRenderables.add(renderable);
}
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
+import com.badlogic.gdx.graphics.g3d.materials.ColorAttribute;
+import com.badlogic.gdx.graphics.g3d.materials.NewMaterial;
+import com.badlogic.gdx.graphics.g3d.materials.TextureAttribute;
+import com.badlogic.gdx.graphics.g3d.Model;
+import com.badlogic.gdx.graphics.g3d.model.data.ModelData;
+import com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial;
+import com.badlogic.gdx.graphics.g3d.model.data.ModelMesh;
+import com.badlogic.gdx.graphics.g3d.model.data.ModelMeshPart;
+import com.badlogic.gdx.graphics.g3d.model.data.ModelMeshPartMaterial;
+import com.badlogic.gdx.graphics.g3d.model.data.ModelNode;
+import com.badlogic.gdx.graphics.g3d.model.data.ModelTexture;
import com.badlogic.gdx.graphics.g3d.old.ModelLoaderHints;
-import com.badlogic.gdx.graphics.g3d.old.loaders.StillModelLoader;
-import com.badlogic.gdx.graphics.g3d.old.materials.ColorAttribute;
-import com.badlogic.gdx.graphics.g3d.old.materials.Material;
-import com.badlogic.gdx.graphics.g3d.old.materials.TextureAttribute;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillModel;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillSubMesh;
+import com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
+import com.badlogic.gdx.math.Quaternion;
+import com.badlogic.gdx.math.Vector3;
+import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.FloatArray;
/** Loads Wavefront OBJ files.
*
* @author mzechner, espitz */
-public class ObjLoader implements StillModelLoader {
+public class ObjLoader /* implements StillModelLoader */ {
final FloatArray verts;
final FloatArray norms;
final FloatArray uvs;
/** Loads a Wavefront OBJ file from a given file handle.
*
* @param file the FileHandle */
- public StillModel loadObj (FileHandle file) {
+ public Model loadObj (FileHandle file) {
return loadObj(file, false);
}
*
* @param file the FileHandle
* @param flipV whether to flip the v texture coordinate (Blender, Wings3D, et al) */
- public StillModel loadObj (FileHandle file, boolean flipV) {
+ public Model loadObj (FileHandle file, boolean flipV) {
return loadObj(file, file.parent(), flipV);
}
* @param file the FileHandle
* @param textureDir
* @param flipV whether to flip the v texture coordinate (Blender, Wings3D, et al) */
- public StillModel loadObj (FileHandle file, FileHandle textureDir, boolean flipV) {
+ public Model loadObj (FileHandle file, FileHandle textureDir, boolean flipV) {
String line;
String[] tokens;
char firstChar;
groups.add(activeGroup);
BufferedReader reader = new BufferedReader(new InputStreamReader(file.read()), 4096);
+ int id = 0;
try {
while ((line = reader.readLine()) != null) {
tokens = line.split("\\s+");
+ if (tokens.length < 1)
+ break;
if (tokens[0].length() == 0) {
continue;
// Get number of objects/groups remaining after removing empty ones
final int numGroups = groups.size();
- final StillModel model = new StillModel(new StillSubMesh[numGroups]);
+ final ModelData data = new ModelData();
for (int g = 0; g < numGroups; g++) {
Group group = groups.get(g);
finalIndices[i] = (short)i;
}
}
- final Mesh mesh;
ArrayList<VertexAttribute> attributes = new ArrayList<VertexAttribute>();
attributes.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
if (hasNorms) attributes.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
if (hasUVs) attributes.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
-
- mesh = new Mesh(true, numFaces * 3, numIndices, attributes.toArray(new VertexAttribute[attributes.size()]));
- mesh.setVertices(finalVerts);
- if (numIndices > 0) mesh.setIndices(finalIndices);
-
- StillSubMesh subMesh = new StillSubMesh(group.name, mesh, GL10.GL_TRIANGLES);
- subMesh.material = mtl.getMaterial(group.materialName);
- model.subMeshes[g] = subMesh;
-
+
+ String nodeId = "node" + (++id);
+ String meshId = "mesh" + id;
+ String partId = "part" + id;
+ ModelNode node = new ModelNode();
+ node.id = nodeId;
+ node.meshId = meshId;
+ node.scale = new Vector3(1,1,1);
+ node.translation = new Vector3();
+ node.rotation = new Quaternion();
+ ModelMeshPartMaterial pm = new ModelMeshPartMaterial();
+ pm.meshPartId = partId;
+ pm.materialId = group.materialName;
+ node.meshPartMaterials = new ModelMeshPartMaterial[] { pm };
+ ModelMeshPart part = new ModelMeshPart();
+ part.id = partId;
+ part.indices = finalIndices;
+ part.primitiveType = GL10.GL_TRIANGLES;
+ ModelMesh mesh = new ModelMesh();
+ mesh.id = meshId;
+ mesh.attributes = attributes.toArray(new VertexAttribute[attributes.size()]);
+ mesh.vertices = finalVerts;
+ mesh.parts = new ModelMeshPart[] { part };
+ data.nodes.add(node);
+ data.meshes.add(mesh);
+ ModelMaterial mm = mtl.getMaterial(group.materialName);
+ data.materials.add(mm);
}
+ //for (ModelMaterial m : mtl.materials)
+ //data.materials.add(m);
+
// An instance of ObjLoader can be used to load more than one OBJ.
// Clearing the ArrayList cache instead of instantiating new
// ArrayLists should result in slightly faster load times for
if (uvs.size > 0) uvs.clear();
if (groups.size() > 0) groups.clear();
- return model;
+ return new Model(data);
}
private Group setActiveGroup (String name) {
int numFaces;
boolean hasNorms;
boolean hasUVs;
- Material mat;
+ NewMaterial mat;
Group (String name) {
this.name = name;
this.faces = new ArrayList<Integer>(200);
this.numFaces = 0;
- this.mat = new Material("");
+ this.mat = new NewMaterial("");
this.materialName = "default";
}
}
- @Override
- public StillModel load (FileHandle handle, ModelLoaderHints hints) {
+ public Model load (FileHandle handle, ModelLoaderHints hints) {
return loadObj(handle, hints.flipV);
}
}
class MtlLoader {
- private ArrayList<Material> materials = new ArrayList<Material>();
+ public ArrayList<ModelMaterial> materials = new ArrayList<ModelMaterial>();
private static AssetManager assetManager;
private static Texture emptyTexture = null;
String curMatName = "default";
Color difcolor = Color.WHITE;
Color speccolor = Color.WHITE;
- Texture texture = emptyTexture;
+ String texFilename = null;
FileHandle file = Gdx.files.internal(name);
if (file == null || file.exists() == false) return;
} else if (tokens[0].charAt(0) == '#')
continue;
else if (tokens[0].toLowerCase().equals("newmtl")) {
- Material mat = new Material(curMatName, new TextureAttribute(texture, 0, TextureAttribute.diffuseTexture),
- new ColorAttribute(difcolor, ColorAttribute.diffuse), new ColorAttribute(speccolor, ColorAttribute.specular));
+ ModelMaterial mat = new ModelMaterial();
+ mat.id = curMatName;
+ mat.diffuse = new Color(difcolor);
+ mat.specular = new Color(speccolor);
+ mat.diffuseTextures = new Array<ModelTexture>();
+ ModelTexture tex = new ModelTexture();
+ tex.fileName = new String(texFilename);
+ mat.diffuseTextures.add(tex);
materials.add(mat);
if (tokens.length > 1) {
} else if (tokens[0].toLowerCase().equals("map_kd")) {
String textureName = tokens[1];
if (textureName.length() > 0) {
- String texname = textureDir.child(textureName).toString();
- assetManager.load(texname, Texture.class);
- assetManager.finishLoading();
- texture = assetManager.get(texname, Texture.class);
- texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
+ texFilename = textureDir.child(textureName).toString();
} else
- texture = emptyTexture;
+ texFilename = null;
}
}
// last material
- Material mat = new Material(curMatName, new TextureAttribute(texture, 0, TextureAttribute.diffuseTexture),
- new ColorAttribute(difcolor, ColorAttribute.diffuse), new ColorAttribute(speccolor, ColorAttribute.specular));
+ ModelMaterial mat = new ModelMaterial();
+ mat.id = curMatName;
+ mat.diffuse = new Color(difcolor);
+ mat.specular = new Color(speccolor);
+ mat.diffuseTextures = new Array<ModelTexture>();
+ ModelTexture tex = new ModelTexture();
+ tex.fileName = new String(texFilename);
+ mat.diffuseTextures.add(tex);
materials.add(mat);
return;
}
-
- public Material getMaterial (String name) {
- name = name.replace('.', '_');
- for (Material mat : materials) {
- if (mat.getName().equals(name)) return mat;
- }
- return new Material("default");
+
+ public ModelMaterial getMaterial(final String name) {
+ for (final ModelMaterial m : materials)
+ if (m.id.equals(name))
+ return m;
+ ModelMaterial mat = new ModelMaterial();
+ mat.id = name;
+ mat.diffuse = new Color(Color.WHITE);
+ materials.add(mat);
+ return mat;
}
}
#define LOWP
#endif
-varying vec3 v_normal;
-
#if defined(diffuseTextureFlag) || defined(specularTextureFlag)
varying MED vec2 v_texCoords0;
#endif
uniform Light lights[NUM_LIGHTS];
varying vec3 v_lightLambert;
+varying vec3 v_normal;
#endif
#endif
#endif
attribute vec3 a_position;
+
+#ifdef NUM_LIGHTS
attribute vec3 a_normal;
uniform mat3 u_normalMatrix;
varying vec3 v_normal;
+#endif
#ifdef textureFlag
attribute vec2 a_texCoord0;
vec4 pos = u_modelTrans * vec4(a_position, 1.0);
gl_Position = u_projTrans * pos;
+
+ #ifdef NUM_LIGHTS
v_normal = u_normalMatrix * a_normal;
- #ifdef NUM_LIGHTS
vec3 aggDir = vec3(0.0);
float aggWeight = 0.0;
vec3 aggCol = vec3(0.0);
@Override
public boolean needsGL20 () {
- return false;
+ return true;
}
@Override
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Input.Keys;
+import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
+import com.badlogic.gdx.graphics.g3d.Model;
+import com.badlogic.gdx.graphics.g3d.ModelBatch;
+import com.badlogic.gdx.graphics.g3d.model.data.ModelData;
+import com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial;
+import com.badlogic.gdx.graphics.g3d.model.data.ModelMesh;
+import com.badlogic.gdx.graphics.g3d.model.data.ModelMeshPart;
+import com.badlogic.gdx.graphics.g3d.model.data.ModelMeshPartMaterial;
+import com.badlogic.gdx.graphics.g3d.model.data.ModelNode;
+import com.badlogic.gdx.graphics.g3d.old.loaders.wavefront.ObjLoader;
import com.badlogic.gdx.graphics.g3d.old.materials.Material;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillModel;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillSubMesh;
+import com.badlogic.gdx.graphics.g3d.test.Light;
+import com.badlogic.gdx.graphics.g3d.test.TestShader;
+import com.badlogic.gdx.math.Quaternion;
+import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.collision.Ray;
import com.badlogic.gdx.physics.bullet.Bullet;
import com.badlogic.gdx.physics.bullet.btIDebugDraw;
initialized = true;
}
- final float lightAmbient[] = new float[] {0.5f, 0.5f, 0.5f, 1f};
- final float lightPosition[] = new float[] {10f, 10f, 10f, 1f};
- final float lightDiffuse[] = new float[] {0.5f, 0.5f, 0.5f, 1f};
+ public Light[] lights = new Light[] {
+ //new Light(Color.WHITE, Vector3.tmp.set(-10f, 10f, -10f), 150f),
+ //new Light(Color.BLUE, Vector3.tmp.set(10f, 5f, 0f), 10f),
+ //new Light(Color.GREEN, Vector3.tmp.set(0f, 10f, 5f), 5f)
+ };
- PerspectiveCamera camera;
- BulletWorld world;
-
+ public PerspectiveCamera camera;
+ public BulletWorld world;
+ public ObjLoader objLoader = new ObjLoader();
+ public ModelBatch modelBatch;
+
public BulletWorld createWorld() {
return new BulletWorld();
}
+ public static Model createSimpleModel(final VertexAttribute[] attributes, final float[] vertices, final short[] indices) {
+ final ModelMesh mesh = new ModelMesh();
+ mesh.attributes = attributes;
+ mesh.id = "mesh1";
+ mesh.vertices = vertices;
+ ModelMeshPart mp = new ModelMeshPart();
+ mp.id = "part1";
+ mp.indices = indices;
+ mp.primitiveType = GL10.GL_TRIANGLES;
+ mesh.parts = new ModelMeshPart[] { mp };
+ ModelNode node = new ModelNode();
+ node.id = "node1";
+ node.meshId = "mesh1";
+ node.translation = new Vector3();
+ node.rotation = new Quaternion();
+ node.scale = new Vector3(1,1,1);
+ ModelMeshPartMaterial pm = new ModelMeshPartMaterial();
+ pm.meshPartId = "part1";
+ pm.materialId = "mat1";
+ node.meshPartMaterials = new ModelMeshPartMaterial[] { pm };
+ ModelMaterial mat = new ModelMaterial();
+ mat.id = "mat1";
+ mat.diffuse = new Color(Color.WHITE);
+ final ModelData data = new ModelData();
+ data.meshes.add(mesh);
+ data.nodes.add(node);
+ data.materials.add(mat);
+ return new Model(data);
+ }
+
@Override
public void create () {
init();
+ modelBatch = new ModelBatch();
+ TestShader.ignoreUnimplemented = true;
+
world = createWorld();
world.performanceCounter = performanceCounter;
camera.update();
// Create some simple meshes
- final Mesh groundMesh = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, "a_position"));
- groundMesh.setVertices(new float[] {20f, 0f, 20f, 20f, 0f, -20f, -20f, 0f, 20f, -20f, 0f, -20f});
- groundMesh.setIndices(new short[] {0, 1, 2, 1, 2, 3});
- final StillModel groundModel = new StillModel(new StillSubMesh("ground", groundMesh, GL10.GL_TRIANGLES, new Material()));
+ final Model groundModel = createSimpleModel(new VertexAttribute[] { new VertexAttribute(Usage.Position, 3, "a_position") },
+ new float[] {20f, 0f, 20f, 20f, 0f, -20f, -20f, 0f, 20f, -20f, 0f, -20f},
+ new short[] {0, 1, 2, 1, 2, 3});
- final Mesh boxMesh = new Mesh(true, 8, 36, new VertexAttribute(Usage.Position, 3, "a_position"));
- boxMesh.setVertices(new float[] {0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f,
- 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f});
- boxMesh.setIndices(new short[] {0, 1, 2, 1, 2, 3, // top
- 4, 5, 6, 5, 6, 7, // bottom
- 0, 2, 4, 4, 6, 2, // front
- 1, 3, 5, 5, 7, 3, // back
- 2, 3, 6, 6, 7, 3, // left
- 0, 1, 4, 4, 5, 1 // right
- });
- final StillModel boxModel = new StillModel(new StillSubMesh("box", boxMesh, GL10.GL_TRIANGLES, new Material()));
+ final Model boxModel = createSimpleModel(new VertexAttribute[] { new VertexAttribute(Usage.Position, 3, "a_position") },
+ new float[] {0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f,
+ 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f},
+ new short[] {0, 1, 2, 1, 2, 3, // top
+ 4, 5, 6, 5, 6, 7, // bottom
+ 0, 2, 4, 4, 6, 2, // front
+ 1, 3, 5, 5, 7, 3, // back
+ 2, 3, 6, 6, 7, 3, // left
+ 0, 1, 4, 4, 5, 1 // right
+ });
// Add the constructors
world.addConstructor("ground", new BulletConstructor(groundModel, 0f)); // mass = 0: static body
}
protected void beginRender(boolean lighting) {
- GL10 gl = Gdx.gl10;
+ Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
+ camera.update();
+ /* GL10 gl = Gdx.gl10;
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuse, 0);
} else
gl.glDisable(GL10.GL_LIGHTING);
- camera.apply(Gdx.gl10);
+ camera.apply(Gdx.gl10); */
}
protected void renderWorld() {
- world.render();
+ modelBatch.begin(camera);
+ world.render(modelBatch, lights);
+ modelBatch.end();
}
public void update() {
// Shoot a box
Ray ray = camera.getPickRay(x, y);
BulletEntity entity = world.add(what, ray.origin.x, ray.origin.y, ray.origin.z);
- entity.color.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
+ entity.getColor().set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
((btRigidBody)entity.body).applyCentralImpulse(ray.direction.mul(impulse));
return entity;
}
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Mesh;
-import com.badlogic.gdx.graphics.g3d.old.model.Model;
+import com.badlogic.gdx.graphics.g3d.Model;
+import com.badlogic.gdx.graphics.g3d.materials.ColorAttribute;
+import com.badlogic.gdx.graphics.g3d.materials.NewMaterial;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.utils.Disposable;
public abstract class BaseEntity implements Disposable {
public Matrix4 transform = new Matrix4();
public Model model;
- public Color color = new Color(1f, 1f, 1f, 1f);
+ private Color color = new Color(1f, 1f, 1f, 1f);
+ public Color getColor () {
+ return color;
+ }
+ public void setColor (Color color) {
+ setColor(color.r, color.g, color.b, color.a);
+ }
+ public void setColor (float r, float g, float b, float a) {
+ if (model != null) {
+ NewMaterial m = model.materials.get(0);
+ if (m != null) {
+ ColorAttribute ca = (ColorAttribute)m.get(ColorAttribute.Diffuse);
+ if (ca != null)
+ ca.color.set(r, g, b, a);
+ }
+ }
+ }
}
\ No newline at end of file
package com.badlogic.gdx.tests.bullet;
import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Mesh;
-import com.badlogic.gdx.graphics.g3d.old.model.Model;
+import com.badlogic.gdx.graphics.g3d.Model;
+import com.badlogic.gdx.graphics.g3d.ModelBatch;
+import com.badlogic.gdx.graphics.g3d.test.Light;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Disposable;
return entity;
}
- public void render() {
- render(entities);
+ public void render(final ModelBatch batch, final Light[] lights) {
+ render(batch, lights, entities);
}
- public void render(final Iterable<T> entities) {
+ public void render(final ModelBatch batch, final Light[] lights, final Iterable<T> entities) {
for (final T e : entities)
- render(e);
+ batch.addModel(e.model, e.transform, lights);
}
- public void render(final T entity) {
- final GL10 gl = Gdx.gl10;
- gl.glPushMatrix();
- gl.glMultMatrixf(entity.transform.val, 0);
- gl.glColor4f(entity.color.r, entity.color.g, entity.color.b, entity.color.a);
- entity.model.render();
- gl.glPopMatrix();
+ public void render(final ModelBatch batch, final Light[] lights, final T entity) {
+ batch.addModel(entity.model, entity.transform, lights);
+ //final GL10 gl = Gdx.gl10;
+ //gl.glPushMatrix();
+ //gl.glMultMatrixf(entity.transform.val, 0);
+ //gl.glColor4f(entity.color.r, entity.color.g, entity.color.b, entity.color.a);
+ //entity.model.render();
+ //gl.glPopMatrix();
}
public void update() { }
constructor.dispose();
constructors.clear();
- for (int i = 0; i < models.size; i++)
- models.get(i).dispose();
+ //for (int i = 0; i < models.size; i++)
+ //models.get(i).dispose();
models.clear();
}
}
\ No newline at end of file
package com.badlogic.gdx.tests.bullet;
import com.badlogic.gdx.graphics.Mesh;
-import com.badlogic.gdx.graphics.g3d.old.model.Model;
+import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.collision.BoundingBox;
package com.badlogic.gdx.tests.bullet;
import com.badlogic.gdx.graphics.Mesh;
-import com.badlogic.gdx.graphics.g3d.old.model.Model;
+import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.physics.bullet.btCollisionObject;
import com.badlogic.gdx.physics.bullet.btCollisionShape;
package com.badlogic.gdx.tests.bullet;
import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.g3d.ModelBatch;
+import com.badlogic.gdx.graphics.g3d.test.Light;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.WindowedMean;
}
@Override
- public void render() {
+ public void render (ModelBatch batch, Light[] lights, Iterable<BulletEntity> entities) {
if (debugDrawer != null && debugDrawer.getDebugMode() > 0) {
debugDrawer.begin();
collisionWorld.debugDrawWorld();
debugDrawer.end();
}
if (renderMeshes)
- super.render();
+ super.render(batch, lights, entities);
}
@Override
// Check what the projectile hits
if (projectile != null) {
- color = projectile.color;
- projectile.color = Color.RED;
+ color = projectile.getColor();
+ projectile.setColor(Color.RED);
world.collisionWorld.contactTest(projectile.body, contactCB);
}
// Check for other collisions
if (hits.size > 0) {
for (int i = 0; i < hits.size; i++) {
- colors.add(hits.get(i).color);
- hits.get(i).color = Color.RED;
+ colors.add(hits.get(i).getColor());
+ hits.get(i).setColor(Color.RED);
}
}
if (contacts.size > 0) {
for (int i = 0; i < contacts.size; i++) {
- colors.add(contacts.get(i).color);
- contacts.get(i).color = Color.BLUE;
+ colors.add(contacts.get(i).getColor());
+ contacts.get(i).setColor(Color.BLUE);
}
}
render(false);
if (projectile != null)
- projectile.color = color;
+ projectile.setColor(color);
for (int i = 0; i < hits.size; i++)
- hits.get(i).color = colors.get(i);
+ hits.get(i).setColor(colors.get(i));
for (int i = 0; i < contacts.size; i++)
- contacts.get(i).color = colors.get(hits.size+i);
+ contacts.get(i).setColor(colors.get(hits.size+i));
}
@Override
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
-import com.badlogic.gdx.graphics.g3d.old.model.Model;
+import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.bullet.ContactResultCallback;
world.addConstructor("collisionBox", new BulletConstructor(boxModel));
world.add("collisionGround", 0f, 0f, 0f)
- .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
world.add("collisionBox", 0f, 1f, 5f)
- .color.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
world.add("collisionBox", 0f, 1f, -5f)
- .color.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
world.add("collisionBox", 5f, 1f, 0f)
- .color.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
world.add("collisionBox", -5f, 1f, 0f)
- .color.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
movingBox = world.add("collisionBox", -5f, 1f, 0f);
normalColor.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
}
hit = false;
other = null;
world.collisionWorld.contactTest(movingBox.body, contactCB);
- movingBox.color.set(hit ? Color.RED : normalColor);
+ movingBox.getColor().set(hit ? Color.RED : normalColor);
BulletEntity e = null;
if (other != null && other.userData != null && other.userData instanceof BulletEntity) {
e = (BulletEntity)(other.userData);
- tmpColor.set(e.color);
- e.color.set(Color.RED);
+ tmpColor.set(e.getColor());
+ e.getColor().set(Color.RED);
}
super.renderWorld();
if (e != null)
- e.color.set(tmpColor);
+ e.getColor().set(tmpColor);
}
@Override
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
-import com.badlogic.gdx.graphics.g3d.old.materials.Material;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillModel;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillSubMesh;
+import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.bullet.btDiscreteDynamicsWorld;
import com.badlogic.gdx.physics.bullet.btDynamicsWorld;
public void create () {
super.create();
- final Mesh barMesh = new Mesh(true, 8, 36, new VertexAttribute(Usage.Position, 3, "a_position"));
- barMesh.setVertices(new float[] {5f, 0.5f, 0.5f, 5f, 0.5f, -0.5f, -5f, 0.5f, 0.5f, -5f, 0.5f, -0.5f,
- 5f, -0.5f, 0.5f, 5f, -0.5f, -0.5f, -5f, -0.5f, 0.5f, -5f, -0.5f, -0.5f});
- barMesh.setIndices(new short[] {0, 1, 2, 1, 2, 3, // top
- 4, 5, 6, 5, 6, 7, // bottom
- 0, 2, 4, 4, 6, 2, // front
- 1, 3, 5, 5, 7, 3, // back
- 2, 3, 6, 6, 7, 3, // left
- 0, 1, 4, 4, 5, 1 // right
+ final Model barModel = createSimpleModel(new VertexAttribute[] { new VertexAttribute(Usage.Position, 3, "a_position")},
+ new float[] {5f, 0.5f, 0.5f, 5f, 0.5f, -0.5f, -5f, 0.5f, 0.5f, -5f, 0.5f, -0.5f,
+ 5f, -0.5f, 0.5f, 5f, -0.5f, -0.5f, -5f, -0.5f, 0.5f, -5f, -0.5f, -0.5f},
+ new short[] {0, 1, 2, 1, 2, 3, // top
+ 4, 5, 6, 5, 6, 7, // bottom
+ 0, 2, 4, 4, 6, 2, // front
+ 1, 3, 5, 5, 7, 3, // back
+ 2, 3, 6, 6, 7, 3, // left
+ 0, 1, 4, 4, 5, 1 // right
});
- final StillModel barModel = new StillModel(new StillSubMesh("bar", barMesh, GL10.GL_TRIANGLES, new Material()));
world.addConstructor("bar", new BulletConstructor(barModel, 0f)); // mass = 0: static body
// Create the entities
world.add("ground", 0f, 0f, 0f)
- .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
BulletEntity bar = world.add("bar", 0f, 7f, 0f);
- bar.color.set(0.75f + 0.25f * (float)Math.random(), 0.75f + 0.25f * (float)Math.random(), 0.75f + 0.25f * (float)Math.random(), 1f);
+ bar.getColor().set(0.75f + 0.25f * (float)Math.random(), 0.75f + 0.25f * (float)Math.random(), 0.75f + 0.25f * (float)Math.random(), 1f);
BulletEntity box1 = world.add("box", -4.5f, 6f, 0f);
- box1.color.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
+ box1.getColor().set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
btPoint2PointConstraint constraint = new btPoint2PointConstraint((btRigidBody)bar.body, (btRigidBody)box1.body, Vector3.tmp.set(-5, -0.5f, -0.5f), Vector3.tmp2.set(-0.5f, 0.5f, -0.5f));
((btDynamicsWorld)world.collisionWorld).addConstraint(constraint, false);
constraints.add(constraint);
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
box2 = world.add("box", -3.5f + (float)i, 6f, 0f);
- box2.color.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
+ box2.getColor().set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
constraint = new btPoint2PointConstraint((btRigidBody)box1.body, (btRigidBody)box2.body, Vector3.tmp.set(0.5f, -0.5f, 0.5f), Vector3.tmp2.set(-0.5f, -0.5f, 0.5f));
} else {
box1 = world.add("box", -3.5f + (float)i, 6f, 0f);
- box1.color.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
+ box1.getColor().set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
constraint = new btPoint2PointConstraint((btRigidBody)box2.body, (btRigidBody)box1.body, Vector3.tmp.set(0.5f, 0.5f, -0.5f), Vector3.tmp2.set(-0.5f, 0.5f, -0.5f));
}
((btDynamicsWorld)world.collisionWorld).addConstraint(constraint, false);
final BulletEntity e = (BulletEntity)(entities.get(userValue0));
// Disable future callbacks for this entity
e.body.setContactCallbackFilter(0);
- e.color.set(Color.RED);
+ e.getColor().set(Color.RED);
Gdx.app.log("ContactCallbackTest", "Contact processed "+(++c));
}
if (match1) {
final BulletEntity e = (BulletEntity)(entities.get(userValue1));
// Disable future callbacks for this entity
e.body.setContactCallbackFilter(0);
- e.color.set(Color.RED);
+ e.getColor().set(Color.RED);
Gdx.app.log("ContactCallbackTest", "Contact processed "+(++c));
}
}
// Create the entities
(ground = world.add("ground", 0f, 0f, 0f))
- .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
for (int x = 0; x < BOXCOUNT_X; x++) {
for (int y = 0; y < BOXCOUNT_Y; y++) {
for (int z = 0; z < BOXCOUNT_Z; z++) {
final BulletEntity e = (BulletEntity)world.add("box", BOXOFFSET_X + x * 2f, BOXOFFSET_Y + y * 2f, BOXOFFSET_Z + z * 2f);
- e.color.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
+ e.getColor().set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
e.body.setContactCallbackFlag(2);
e.body.setContactCallbackFilter(2);
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Mesh;
-import com.badlogic.gdx.graphics.g3d.old.loaders.ModelLoaderRegistry;
-import com.badlogic.gdx.graphics.g3d.old.loaders.wavefront.ObjLoader;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillModel;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillSubMesh;
+import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.physics.bullet.btConvexHullShape;
import com.badlogic.gdx.physics.bullet.btShapeHull;
public void create () {
super.create();
- final StillModel sceneModel = ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/car.obj"));
- final Mesh sceneMesh = sceneModel.subMeshes[0].getMesh();
- world.addConstructor("car", new BulletConstructor(sceneModel, 5f, createConvexHullShape(sceneMesh)));
+ final Model sceneModel = objLoader.loadObj(Gdx.files.internal("data/car.obj"));
+ world.addConstructor("car", new BulletConstructor(sceneModel, 5f, createConvexHullShape(sceneModel)));
// Create the entities
world.add("ground", 0f, 0f, 0f)
- .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
for (float y = 10f; y < 50f; y += 5f)
world.add("car", -2f+(float)Math.random()*4f, y, -2f+(float)Math.random()*4f)
- .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
}
@Override
return true;
}
- public static btConvexHullShape createConvexHullShape(final Mesh mesh) {
+ public static btConvexHullShape createConvexHullShape(final Model model) {
+ final Mesh mesh = model.meshes.get(0);
final btConvexHullShape shape = new btConvexHullShape(mesh.getVerticesBuffer(), mesh.getNumVertices(), mesh.getVertexSize());
// now optimize the shape
final btShapeHull hull = new btShapeHull(shape);
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
-import com.badlogic.gdx.graphics.g3d.old.materials.Material;
-import com.badlogic.gdx.graphics.g3d.old.model.Model;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillModel;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillSubMesh;
+import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Quaternion;
import com.badlogic.gdx.math.Vector3;
}
public static Model createFrustumModel(final Vector3... p) {
- final Mesh mesh = new Mesh(true, 8, 32, new VertexAttribute(Usage.Position, 3, "a_position"));
- mesh.setVertices(new float[] {
- p[0].x, p[0].y, p[0].z, p[1].x, p[1].y, p[1].z, p[2].x, p[2].y, p[2].z, p[3].x, p[3].y, p[3].z, // near
- p[4].x, p[4].y, p[4].z, p[5].x, p[5].y, p[5].z, p[6].x, p[6].y, p[6].z, p[7].x, p[7].y, p[7].z});// far
- mesh.setIndices(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});
- return new StillModel(new StillSubMesh("frustum", mesh, GL10.GL_LINES, new Material()));
+ return createSimpleModel(new VertexAttribute[] { new VertexAttribute(Usage.Position, 3, "a_position")},
+ new float[] {
+ p[0].x, p[0].y, p[0].z, p[1].x, p[1].y, p[1].z, p[2].x, p[2].y, p[2].z, p[3].x, p[3].y, p[3].z, // near
+ p[4].x, p[4].y, p[4].z, p[5].x, p[5].y, p[5].z, p[6].x, p[6].y, p[6].z, p[7].x, p[7].y, p[7].z},// far
+ 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});
}
private float angleX, angleY, angleZ;
BOX_X_MIN + dX * (float)Math.random(),
BOX_Y_MIN + dY * (float)Math.random(),
BOX_Z_MIN + dZ * (float)Math.random()
- ).color.set(Color.GRAY);
+ ).getColor().set(Color.GRAY);
frustumCam = new PerspectiveCamera(camera.fieldOfView, camera.viewportWidth, camera.viewportHeight);
frustumCam.far = Vector3.len(BOX_X_MAX, BOX_Y_MAX, BOX_Z_MAX);
final Model frustumModel = createFrustumModel(frustumCam.frustum.planePoints);
frustumObject = createFrustumObject(frustumCam.frustum.planePoints);
world.add(frustumEntity = new BulletEntity(frustumModel, frustumObject, 0, 0, 0));
- frustumEntity.color.set(Color.BLUE);
+ frustumEntity.getColor().set(Color.BLUE);
world.renderMeshes = false;
}
world.performanceCounter.stop();
for (int i = 0; i < visibleEntities.size; i++)
- visibleEntities.get(i).color.set(Color.RED);
-
+ visibleEntities.get(i).getColor().set(Color.RED);
+
+ modelBatch.begin(camera);
if ((state & CULL_FRUSTUM) == CULL_FRUSTUM) {
- world.render(visibleEntities);
- world.render(frustumEntity);
+ world.render(modelBatch, lights, visibleEntities);
+ world.render(modelBatch, lights, frustumEntity);
} else
- world.render(world.entities);
+ world.render(modelBatch, lights);
+ modelBatch.end();
for (int i = 0; i < visibleEntities.size; i++)
- visibleEntities.get(i).color.set(Color.GRAY);
+ visibleEntities.get(i).getColor().set(Color.GRAY);
}
@Override
// Create the entities
world.add("ground", 0f, 0f, 0f)
- .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
for (int x = 0; x < BOXCOUNT_X; x++) {
for (int y = 0; y < BOXCOUNT_Y; y++) {
for (int z = 0; z < BOXCOUNT_Z; z++) {
world.add("box", BOXOFFSET_X + x, BOXOFFSET_Y + y, BOXOFFSET_Z + z)
- .color.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
}
}
}
// Create the entities
world.add("ground", 0f, 0f, 0f)
- .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
kinematicBox1 = world.add("staticbox", position1.x, position1.y, position1.z);
- kinematicBox1.color.set(Color.RED);
+ kinematicBox1.getColor().set(Color.RED);
kinematicBox1.body.setCollisionFlags(kinematicBox1.body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_KINEMATIC_OBJECT);
kinematicBox2 = world.add("staticbox", position2.x, position2.y, position2.z);
- kinematicBox2.color.set(Color.RED);
+ kinematicBox2.getColor().set(Color.RED);
kinematicBox2.body.setCollisionFlags(kinematicBox2.body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_KINEMATIC_OBJECT);;
kinematicBox3 = world.add("staticbox", position3.x, position3.y, position3.z);
- kinematicBox3.color.set(Color.RED);
+ kinematicBox3.getColor().set(Color.RED);
kinematicBox3.body.setCollisionFlags(kinematicBox3.body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_KINEMATIC_OBJECT);;
// This makes bullet call btMotionState#getWorldTransform on every update:
kinematicBox3.body.setActivationState(gdxBullet.DISABLE_DEACTIVATION);
package com.badlogic.gdx.tests.bullet;
import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.g3d.old.loaders.ModelLoaderRegistry;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillModel;
+import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.collision.BoundingBox;
public void create () {
super.create();
- final StillModel sphereModel = ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/sphere.obj"));
- sphereModel.subMeshes[0].getMesh().scale(0.25f, 0.25f, 0.25f);
+ final Model sphereModel = objLoader.loadObj(Gdx.files.internal("data/sphere.obj"));
+ // sphereModel.subMeshes[0].getMesh().scale(0.25f, 0.25f, 0.25f);
final BoundingBox sphereBounds = new BoundingBox();
sphereModel.getBoundingBox(sphereBounds);
sphereConstructor.bodyInfo.setM_restitution(1f);
world.addConstructor("sphere", sphereConstructor);
- // final StillModel sceneModel = ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/scene.obj"));
- // final BulletConstructor sceneConstructor = new BulletConstructor(sceneModel, 0f, new btBvhTriangleMeshShape(true, sceneModel));
- // sceneConstructor.bodyInfo.setM_restitution(0.25f);
- // world.addConstructor("scene", sceneConstructor);
+ final Model sceneModel = objLoader.loadObj(Gdx.files.internal("data/scene.obj"));
+ final BulletConstructor sceneConstructor = new BulletConstructor(sceneModel, 0f, new btBvhTriangleMeshShape(true, sceneModel));
+ sceneConstructor.bodyInfo.setM_restitution(0.25f);
+ world.addConstructor("scene", sceneConstructor);
- // world.add("scene", (new Matrix4()).setToTranslation(0f, 2f, 0f).rotate(Vector3.Y, -90))
- // .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ world.add("scene", (new Matrix4()).setToTranslation(0f, 2f, 0f).rotate(Vector3.Y, -90))
+ .getColor().set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
world.add("ground", 0f, 0f, 0f)
- .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
for (float x = -3; x < 7; x++) {
for (float z = -5; z < 5; z++) {
world.add("sphere", x, 10f + (float)Math.random() * 0.1f, z)
- .color.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
}
}
}
// Create the entities
world.add("ground", -7f, 0f, -7f)
- .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
for (int x = 0; x < BOXCOUNT_X; x++) {
for (int y = 0; y < BOXCOUNT_Y; y++) {
for (int z = 0; z < BOXCOUNT_Z; z++) {
world.add("box", BOXOFFSET_X + x, BOXOFFSET_Y + y, BOXOFFSET_Z + z)
- .color.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
}
}
}
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
-import com.badlogic.gdx.graphics.g3d.old.materials.Material;
-import com.badlogic.gdx.graphics.g3d.old.model.Model;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillModel;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillSubMesh;
+import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
world.addConstructor("lowerarm", new BulletConstructor(createCapsuleModel(0.04f, 0.25f), 1f, new btCapsuleShape(0.04f, 0.25f)));
world.add("ground", 0f, 0f, 0f)
- .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
addRagdoll(0, 3f, 0);
addRagdoll(1f, 6f, 0);
protected Model createCapsuleModel(float radius, float height) {
final float hh = radius + 0.5f * height;
- final Mesh mesh = new Mesh(true, 8, 36, new VertexAttribute(Usage.Position, 3, "a_position"));
- mesh.setVertices(new float[] {radius, hh, radius, radius, hh, -radius, -radius, hh, radius, -radius, hh, -radius,
- radius, -hh, radius, radius, -hh, -radius, -radius, -hh, radius, -radius, -hh, -radius});
- mesh.setIndices(new short[] {0, 1, 2, 1, 2, 3, // top
- 4, 5, 6, 5, 6, 7, // bottom
- 0, 2, 4, 4, 6, 2, // front
- 1, 3, 5, 5, 7, 3, // back
- 2, 3, 6, 6, 7, 3, // left
- 0, 1, 4, 4, 5, 1 // right
+ return createSimpleModel(new VertexAttribute[] { new VertexAttribute(Usage.Position, 3, "a_position") },
+ new float[] {radius, hh, radius, radius, hh, -radius, -radius, hh, radius, -radius, hh, -radius,
+ radius, -hh, radius, radius, -hh, -radius, -radius, -hh, radius, -radius, -hh, -radius},
+ new short[] {0, 1, 2, 1, 2, 3, // top
+ 4, 5, 6, 5, 6, 7, // bottom
+ 0, 2, 4, 4, 6, 2, // front
+ 1, 3, 5, 5, 7, 3, // back
+ 2, 3, 6, 6, 7, 3, // left
+ 0, 1, 4, 4, 5, 1 // right
});
- return new StillModel(new StillSubMesh("capsule", mesh, GL10.GL_TRIANGLES, new Material()));
+ // return new StillModel(new StillSubMesh("capsule", mesh, GL10.GL_TRIANGLES, new Material()));
}
}
// Create the entities
(ground = world.add("ground", 0f, 0f, 0f))
- .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ .setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
for (int x = 0; x < BOXCOUNT_X; x++) {
for (int y = 0; y < BOXCOUNT_Y; y++) {
for (int z = 0; z < BOXCOUNT_Z; z++) {
world.add("box", BOXOFFSET_X + x, BOXOFFSET_Y + y, BOXOFFSET_Z + z)
- .color.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
+ .setColor(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
}
}
}
super.create();
world.add("ground", 0f, 0f, 0f)
- .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
float x0 = -2f, y0 = 6f, z0 = -2f;
float x1 = 8f, y1 = 6f, z1 = 8f;
world.maxSubSteps = 20;
world.add("ground", 0f, 0f, 0f)
- .color.set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
+ .getColor().set(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
// Note: not every model is suitable for a one on one translation with a soft body, a better model might be added later.
final StillModel model = ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/wheel.obj"));
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.Texture;
-import com.badlogic.gdx.graphics.g3d.RenderBatch;
+import com.badlogic.gdx.graphics.g3d.Model;
+import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.loader.JsonModelLoader;
-import com.badlogic.gdx.graphics.g3d.old.loaders.ModelLoaderRegistry;
-import com.badlogic.gdx.graphics.g3d.old.materials.Material;
-import com.badlogic.gdx.graphics.g3d.old.materials.TextureAttribute;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillModel;
-import com.badlogic.gdx.graphics.g3d.old.model.still.StillSubMesh;
-import com.badlogic.gdx.graphics.g3d.test.InterimModel;
+import com.badlogic.gdx.graphics.g3d.old.loaders.wavefront.ObjLoader;
import com.badlogic.gdx.graphics.g3d.test.Light;
-import com.badlogic.gdx.graphics.g3d.test.NewModel;
+import com.badlogic.gdx.graphics.g3d.test.TestShader;
import com.badlogic.gdx.graphics.g3d.utils.DefaultTextureBinder;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
float SIZE_X = 20f, SIZE_Y = 20f, SIZE_Z = 20f;
public static class ModelInstance {
- public NewModel model;
+ public Model model;
public Matrix4 transform;
- public ModelInstance(NewModel model, Matrix4 transform) {
+ public ModelInstance(Model model, Matrix4 transform) {
this.model = model;
this.transform = transform;
}
}
PerspectiveCamera cam;
Array<ModelInstance> instances = new Array<ModelInstance>();
- NewModel sphereModel;
- NewModel sceneModel;
- StillModel cubeModel;
- NewModel carModel;
- NewModel testModel;
- Array<NewModel> cubes = new Array<NewModel>();
+ Model sphereModel;
+ Model sceneModel;
+ Model cubeModel;
+ Model carModel;
+ Model testModel;
+ Array<Model> cubes = new Array<Model>();
Array<Texture> textures = new Array<Texture>();
- RenderBatch renderBatch;
+ ModelBatch renderBatch;
DefaultTextureBinder exclusiveTextures;
Light[] lights;
@Override
public void create () {
+ TestShader.ignoreUnimplemented = true;
+
final JsonModelLoader loader = new JsonModelLoader();
// need more higher resolution textures for this test...
for (int i = 0; i < TEXTURE_COUNT; i++)
textures.add(new Texture(Gdx.files.internal(TEXTURES[i%TEXTURES.length])));
- sphereModel = new InterimModel(ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/sphere.obj")));
- sceneModel = new InterimModel(ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/scene.obj")));
- cubeModel = ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/cube.obj"));
- carModel = new InterimModel(ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/car.obj")));
- testModel = new InterimModel(loader.load(Gdx.files.internal("data/g3d/test.g3dj"), null));
+ ObjLoader objLoader = new ObjLoader();
+ sphereModel = objLoader.loadObj(Gdx.files.internal("data/sphere.obj"));
+ sceneModel = objLoader.loadObj(Gdx.files.internal("data/scene.obj"));
+ cubeModel = objLoader.loadObj(Gdx.files.internal("data/cube.obj"));
+ carModel = objLoader.loadObj(Gdx.files.internal("data/car.obj"));
+ testModel = new Model(loader.parseModel(Gdx.files.internal("data/g3d/head.g3dj"), null));
- StillSubMesh mesh = (StillSubMesh)(cubeModel.subMeshes[0]);
+ //StillSubMesh mesh = (StillSubMesh)(cubeModel.subMeshes[0]);
for (int i = 0; i < textures.size; i++)
- cubes.add(new InterimModel(new StillModel(new StillSubMesh(mesh.name, mesh.mesh, mesh.primitiveType, new Material("mat", new TextureAttribute(textures.get(i), 0, TextureAttribute.diffuseTexture))))));
+ cubes.add(cubeModel);
+ // cubes.add(new InterimModel(new StillModel(new StillSubMesh(mesh.name, mesh.mesh, mesh.primitiveType, new Material("mat", new TextureAttribute(textures.get(i), 0, TextureAttribute.diffuseTexture))))));
createScene2();
cam.lookAt(0, 0, 0);
cam.update();
- renderBatch = new RenderBatch();
+ renderBatch = new ModelBatch();
lights = new Light[] {
new Light(Color.WHITE, Vector3.tmp.set(-10f, 10f, -10f), 15f),
public void render () {
if ((dbgTimer += Gdx.graphics.getDeltaTime()) >= 1f) {
dbgTimer -= 1f;
- Gdx.app.log("Test", "FPS: "+Gdx.graphics.getFramesPerSecond()+", binds: "+exclusiveTextures.getBindCount()+", reused: "+exclusiveTextures.getReuseCount());
- exclusiveTextures.resetCounts();
+ // Gdx.app.log("Test", "FPS: "+Gdx.graphics.getFramesPerSecond()+", binds: "+exclusiveTextures.getBindCount()+", reused: "+exclusiveTextures.getReuseCount());
+ // exclusiveTextures.resetCounts();
}
GL20 gl = Gdx.gl20;
gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl.glDisable(GL20.GL_CULL_FACE);
renderBatch.begin(cam);
- for (int i = 0; i < instances.size; i++)
- renderBatch.addModel(instances.get(i).model, instances.get(i).transform, lights);
+ for (int i = 0; i < instances.size; i++) {
+ if (instances.get(i).model == null)
+ Gdx.app.log("Test", "Model "+i+" is null");
+ else
+ renderBatch.addModel(instances.get(i).model, instances.get(i).transform, lights);
+ }
renderBatch.end();
}
import com.badlogic.gdx.tests.bench.TiledMapBench;\r
import com.badlogic.gdx.tests.examples.MoveSpriteExample;\r
import com.badlogic.gdx.tests.g3d.BatchRenderTest;\r
+import com.badlogic.gdx.tests.g3d.NewModelTest;\r
import com.badlogic.gdx.tests.g3d.JsonModelLoaderTest;\r
import com.badlogic.gdx.tests.gles2.HelloTriangle;\r
import com.badlogic.gdx.tests.gles2.SimpleVertexShader;\r
// SoundTouchTest.class, Mpg123Test.class, WavTest.class, FreeTypeTest.class,\r
// InternationalFontsTest.class, VorbisTest.class\r
TextButtonTest.class, TextButtonTestGL2.class, TextureBindTest.class, SortedSpriteTest.class,\r
- ExternalMusicTest.class, SoftKeyboardTest.class, DirtyRenderingTest.class, YDownTest.class, BatchRenderTest.class,\r
+ ExternalMusicTest.class, SoftKeyboardTest.class, DirtyRenderingTest.class, YDownTest.class,\r
ScreenCaptureTest.class, BitmapFontTest.class, LabelScaleTest.class, GamepadTest.class, NetAPITest.class, TideMapAssetManagerTest.class, TideMapDirectLoaderTest.class, TiledMapAssetManagerTest.class, TiledMapBench.class,\r
RunnablePostTest.class, Vector2dTest.class, SuperKoalio.class, NinePatchTest.class,\r
- JsonModelLoaderTest.class, BatchRenderTest.class));\r
+ JsonModelLoaderTest.class, BatchRenderTest.class, NewModelTest.class));\r
\r
public static List<String> getNames () {\r
List<String> names = new ArrayList<String>(tests.size());\r