OSDN Git Service

Rename Material#add to #set, allow mask for vertex attributes.
authorXoppa <contact@xoppa.nl>
Mon, 15 Apr 2013 21:40:24 +0000 (23:40 +0200)
committerXoppa <contact@xoppa.nl>
Mon, 15 Apr 2013 21:40:24 +0000 (23:40 +0200)
17 files changed:
demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/simulation/Simulation.java
gdx/src/com/badlogic/gdx/graphics/g3d/Model.java
gdx/src/com/badlogic/gdx/graphics/g3d/materials/Material.java
gdx/src/com/badlogic/gdx/graphics/g3d/utils/MeshBuilder.java
gdx/src/com/badlogic/gdx/graphics/g3d/utils/ModelBuilder.java
tests/gdx-tests/src/com/badlogic/gdx/tests/CullTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/FramebufferToTextureTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/MaterialTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/PickingTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/ProjectTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/BaseBulletTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/BasicShapesTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/ConstraintsTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/ConvexHullTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/MeshShapeTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/RayPickRagdollTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/g3d/BaseG3dTest.java

index 4727c6c..480267c 100644 (file)
@@ -79,13 +79,13 @@ public class Simulation implements Disposable {
                shipTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);\r
                final Texture invaderTexture = new Texture(Gdx.files.internal("data/invader.png"), Format.RGB565, true);\r
                invaderTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);\r
-               shipModel.materials.get(0).add(TextureAttribute.createDiffuse(shipTexture));\r
-               invaderModel.materials.get(0).add(TextureAttribute.createDiffuse(invaderTexture));\r
+               shipModel.materials.get(0).set(TextureAttribute.createDiffuse(shipTexture));\r
+               invaderModel.materials.get(0).set(TextureAttribute.createDiffuse(invaderTexture));\r
                \r
                ((ColorAttribute)blockModel.materials.get(0).get(ColorAttribute.Diffuse)).color.set(0, 0, 1, 0.5f);\r
-               blockModel.materials.get(0).add(new BlendingAttribute(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA));\r
+               blockModel.materials.get(0).set(new BlendingAttribute(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA));\r
                \r
-               shotModel.materials.get(0).add(ColorAttribute.createDiffuse(1, 1, 0, 1f));\r
+               shotModel.materials.get(0).set(ColorAttribute.createDiffuse(1, 1, 0, 1f));\r
                \r
                final Texture explosionTexture = new Texture(Gdx.files.internal("data/explode.png"), Format.RGBA4444, true);\r
                explosionTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);\r
index 65dae20..aa490d6 100644 (file)
@@ -190,15 +190,15 @@ public class Model implements Disposable {
                Material result = new Material();
                result.id = mtl.id;
                if (mtl.ambient != null)
-                       result.add(new ColorAttribute(ColorAttribute.Ambient, mtl.ambient));
+                       result.set(new ColorAttribute(ColorAttribute.Ambient, mtl.ambient));
                if (mtl.diffuse != null)
-                       result.add(new ColorAttribute(ColorAttribute.Diffuse, mtl.diffuse));
+                       result.set(new ColorAttribute(ColorAttribute.Diffuse, mtl.diffuse));
                if (mtl.specular != null)
-                       result.add(new ColorAttribute(ColorAttribute.Specular, mtl.specular));
+                       result.set(new ColorAttribute(ColorAttribute.Specular, mtl.specular));
                if (mtl.emissive != null)
-                       result.add(new ColorAttribute(ColorAttribute.Emissive, mtl.emissive));
+                       result.set(new ColorAttribute(ColorAttribute.Emissive, mtl.emissive));
                if (mtl.shininess > 0f)
-                       result.add(new FloatAttribute(FloatAttribute.Shininess, mtl.shininess));
+                       result.set(new FloatAttribute(FloatAttribute.Shininess, mtl.shininess));
                
                ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
                
@@ -218,7 +218,7 @@ public class Model implements Disposable {
                                descriptor.magFilter = GL20.GL_LINEAR;
                                descriptor.uWrap = GL20.GL_CLAMP_TO_EDGE;
                                descriptor.vWrap = GL20.GL_CLAMP_TO_EDGE;
-                               result.add(new TextureAttribute(TextureAttribute.Diffuse, descriptor));
+                               result.set(new TextureAttribute(TextureAttribute.Diffuse, descriptor));
                        }
                }
                
index 5995f7f..20d205f 100644 (file)
@@ -84,22 +84,22 @@ public class Material implements Iterable<Material.Attribute>, Comparator<Materi
        /** Create a material with the specified attributes */
        public Material(final Attribute... attributes) {
                this();
-               add(attributes);
+               set(attributes);
        }
        /** Create a material with the specified attributes */
        public Material(final String id, final Attribute... attributes) {
                this(id);
-               add(attributes);
+               set(attributes);
        }
        /** Create a material with the specified attributes */
        public Material(final Array<Attribute> attributes) {
                this();
-               add(attributes);
+               set(attributes);
        }
        /** Create a material with the specified attributes */
        public Material(final String id, final Array<Attribute> attributes) {
                this(id);
-               add(attributes);
+               set(attributes);
        }
        /** Create a material which is an exact copy of the specified material */
        public Material(final Material copyFrom) {
@@ -109,7 +109,7 @@ public class Material implements Iterable<Material.Attribute>, Comparator<Materi
        public Material(final String id, final Material copyFrom) {
                this(id);
                for (Attribute attr : copyFrom)
-                       add(attr.copy());
+                       set(attr.copy());
        }
        
        private final void enable(final long mask) {
@@ -140,7 +140,7 @@ public class Material implements Iterable<Material.Attribute>, Comparator<Materi
 
        /** Add a attribute to this material.
         * If the material already contains an attribute of the same type it is overwritten. */
-       public final void add(final Attribute attribute) {
+       public final void set(final Attribute attribute) {
                final int idx = indexOf(attribute.type);
                if (idx < 0) {
                        enable(attribute.type);
@@ -153,16 +153,16 @@ public class Material implements Iterable<Material.Attribute>, Comparator<Materi
        
        /** Add an array of attributes to this material. 
         * If the material already contains an attribute of the same type it is overwritten. */
-       public final void add(final Attribute... attributes) {
+       public final void set(final Attribute... attributes) {
                for (final Attribute attr : attributes)
-                       add(attr);
+                       set(attr);
        }
 
        /** Add an array of attributes to this material.
         * If the material already contains an attribute of the same type it is overwritten. */
-       public final void add(final Array<Attribute> attributes) {
+       public final void set(final Array<Attribute> attributes) {
                for (final Attribute attr : attributes)
-                       add(attr);
+                       set(attr);
        }
        
        /** Removes the attribute from the material, i.e.: material.remove(BlendingAttribute.ID);
index 517fcbc..a7a3789 100644 (file)
@@ -10,6 +10,7 @@ import com.badlogic.gdx.graphics.VertexAttributes.Usage;
 import com.badlogic.gdx.graphics.g3d.Model;
 import com.badlogic.gdx.graphics.g3d.model.MeshPart;
 import com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo;
+import com.badlogic.gdx.graphics.glutils.ShaderProgram;
 import com.badlogic.gdx.math.MathUtils;
 import com.badlogic.gdx.math.Matrix4;
 import com.badlogic.gdx.math.Vector2;
@@ -87,10 +88,43 @@ public class MeshBuilder implements MeshPartBuilder {
        private float uMin = 0, uMax = 1, vMin = 0, vMax = 1;
        private float[] vertex;
        
-       /** Begin building a mesh */
+       /** @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.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);
+       }
+       
+       /** Begin building a mesh. Call {@link #part(String, int)} to start a {@link MeshPart}.
+        * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, 
+        * only Position, Color, Normal and TextureCoordinates is supported. */
+       public void begin(final long attributes) {
+               begin(createAttributes(attributes), 0);
+       }
+       
+       /** Begin building a mesh. Call {@link #part(String, int)} to start a {@link MeshPart}. */
        public void begin(final VertexAttributes attributes) {
                begin(attributes, 0);
        }
+       
+       /** Begin building a mesh.
+        * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, 
+        * only Position, Color, Normal and TextureCoordinates is supported. */
+       public void begin(final long attributes, int primitiveType) {
+               begin(createAttributes(attributes), primitiveType);
+       }
+       
        /** Begin building a mesh */
        public void begin(final VertexAttributes attributes, int primitiveType) {
                if (this.attributes != null)
index 0d61845..d3e995d 100644 (file)
@@ -148,54 +148,118 @@ public class ModelBuilder {
        /** Creates a new MeshPart within the current Node.
         * The resources the Material might contain are not managed, use {@link #manage(Disposable)} to add those to the model.
         * @return The {@link MeshPartBuilder} you can use to build the MeshPart. */ 
-       public MeshPartBuilder part(final String id, int primitiveType, final VertexAttributes attributes, final Material material) {
+       private MeshPartBuilder part(final String id, int primitiveType, final VertexAttributes attributes, final Material material) {
                final MeshBuilder builder = getBuilder(attributes);
                part(builder.part(id, primitiveType), material);
                return builder;
        }
        
+       /** Creates a new MeshPart within the current Node.
+        * The resources the Material might contain are not managed, use {@link #manage(Disposable)} to add those to the model.
+        * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, 
+        * only Position, Color, Normal and TextureCoordinates is supported.
+        * @return The {@link MeshPartBuilder} you can use to build the MeshPart. */ 
+       public MeshPartBuilder part(final String id, int primitiveType, final long attributes, final Material material) {
+               return part(id, primitiveType, MeshBuilder.createAttributes(attributes), material);
+       }
+       
        /** Convenience method to create a model with a single node containing a box shape.
         * The resources the Material might contain are not managed, 
-        * use {@link Model#manageDisposable(Disposable)} to add those to the model. */ 
-       public Model createBox(float width, float height, float depth, final Material material, final VertexAttributes attributes) {
+        * use {@link Model#manageDisposable(Disposable)} to add those to the model.
+        * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, 
+        * only Position, Color, Normal and TextureCoordinates is supported. */ 
+       public Model createBox(float width, float height, float depth, final Material material, final long attributes) {
+               return createBox(width, height, depth, GL10.GL_TRIANGLES, material, attributes);
+       }
+       
+       /** Convenience method to create a model with a single node containing a box shape.
+        * The resources the Material might contain are not managed, 
+        * use {@link Model#manageDisposable(Disposable)} to add those to the model.
+        * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, 
+        * only Position, Color, Normal and TextureCoordinates is supported. */ 
+       public Model createBox(float width, float height, float depth, int primitiveType, final Material material, final long attributes) {
                begin();
-               part("box", GL10.GL_TRIANGLES, attributes, material).box(width, height, depth);
+               part("box", primitiveType, attributes, material).box(width, height, depth);
                return end();
        }
        
        /** Convenience method to create a model with a single node containing a rectangle shape. 
         * The resources the Material might contain are not managed, 
-        * use {@link Model#manageDisposable(Disposable)} to add those to the model. */
-       public Model createRect(float x00, float y00, float z00, float x10, float y10, float z10, float x11, float y11, float z11, float x01, float y01, float z01, float normalX, float normalY, float normalZ, final Material material, final VertexAttributes attributes) {
+        * use {@link Model#manageDisposable(Disposable)} to add those to the model.
+        * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, 
+        * only Position, Color, Normal and TextureCoordinates is supported. */
+       public Model createRect(float x00, float y00, float z00, float x10, float y10, float z10, float x11, float y11, float z11, float x01, float y01, float z01, float normalX, float normalY, float normalZ, final Material material, final long attributes) {
+               return createRect(x00, y00, z00, x10, y10, z10, x11, y11, z11, x01, y01, z01, normalX, normalY, normalZ, GL10.GL_TRIANGLES, material, attributes);
+       }
+       
+       /** Convenience method to create a model with a single node containing a rectangle shape. 
+        * The resources the Material might contain are not managed, 
+        * use {@link Model#manageDisposable(Disposable)} to add those to the model.
+        * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, 
+        * only Position, Color, Normal and TextureCoordinates is supported. */
+       public Model createRect(float x00, float y00, float z00, float x10, float y10, float z10, float x11, float y11, float z11, float x01, float y01, float z01, float normalX, float normalY, float normalZ, int primitiveType, final Material material, final long attributes) {
                begin();
-               part("rect", GL10.GL_TRIANGLES, attributes, material).rect(x00, y00, z00, x10, y10, z10, x11, y11, z11, x01, y01, z01, normalX, normalY, normalZ);
+               part("rect", primitiveType, attributes, material).rect(x00, y00, z00, x10, y10, z10, x11, y11, z11, x01, y01, z01, normalX, normalY, normalZ);
                return end();
        }
 
        /** Convenience method to create a model with a single node containing a cylinder shape.
         * The resources the Material might contain are not managed, 
-        * use {@link Model#manageDisposable(Disposable)} to add those to the model. */
-       public Model createCylinder(float width, float height, float depth, int divisions, final Material material, final VertexAttributes attributes) {
+        * use {@link Model#manageDisposable(Disposable)} to add those to the model.
+        * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, 
+        * only Position, Color, Normal and TextureCoordinates is supported. */
+       public Model createCylinder(float width, float height, float depth, int divisions, final Material material, final long attributes) {
+               return createCylinder(width, height, depth, divisions, GL10.GL_TRIANGLES, material, attributes);
+       }
+       
+       /** Convenience method to create a model with a single node containing a cylinder shape.
+        * The resources the Material might contain are not managed, 
+        * use {@link Model#manageDisposable(Disposable)} to add those to the model.
+        * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, 
+        * only Position, Color, Normal and TextureCoordinates is supported. */
+       public Model createCylinder(float width, float height, float depth, int divisions, int primitiveType, final Material material, final long attributes) {
                begin();
-               part("cylinder", GL10.GL_TRIANGLES, attributes, material).cylinder(width, height, depth, divisions);
+               part("cylinder", primitiveType, attributes, material).cylinder(width, height, depth, divisions);
                return end();
        }
        
        /** Convenience method to create a model with a single node containing a cone shape.
         * The resources the Material might contain are not managed, 
-        * use {@link Model#manageDisposable(Disposable)} to add those to the model. */
-       public Model createCone(float width, float height, float depth, int divisions, final Material material, final VertexAttributes attributes) {
+        * use {@link Model#manageDisposable(Disposable)} to add those to the model.
+        * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, 
+        * only Position, Color, Normal and TextureCoordinates is supported. */
+       public Model createCone(float width, float height, float depth, int divisions, final Material material, final long attributes) {
+               return createCone(width, height, depth, divisions, GL10.GL_TRIANGLES, material, attributes);
+       }
+               
+       /** Convenience method to create a model with a single node containing a cone shape.
+        * The resources the Material might contain are not managed, 
+        * use {@link Model#manageDisposable(Disposable)} to add those to the model.
+        * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, 
+        * only Position, Color, Normal and TextureCoordinates is supported. */
+       public Model createCone(float width, float height, float depth, int divisions, int primitiveType, final Material material, final long attributes) {
                begin();
-               part("cone", GL10.GL_TRIANGLES, attributes, material).cone(width, height, depth, divisions);
+               part("cone", primitiveType, attributes, material).cone(width, height, depth, divisions);
                return end();
        }
+
+       /** Convenience method to create a model with a single node containing a sphere shape.
+        * The resources the Material might contain are not managed, 
+        * use {@link Model#manageDisposable(Disposable)} to add those to the model.
+        * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, 
+        * only Position, Color, Normal and TextureCoordinates is supported. */
+       public Model createSphere(float width, float height, float depth, int divisionsU, int divisionsV, final Material material, final long attributes) {
+               return createSphere(width, height, depth, divisionsU, divisionsV, GL10.GL_TRIANGLES, material, attributes);
+       }
        
        /** Convenience method to create a model with a single node containing a sphere shape.
         * The resources the Material might contain are not managed, 
-        * use {@link Model#manageDisposable(Disposable)} to add those to the model. */
-       public Model createSphere(float width, float height, float depth, int divisionsU, int divisionsV, final Material material, final VertexAttributes attributes) {
+        * use {@link Model#manageDisposable(Disposable)} to add those to the model.
+        * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, 
+        * only Position, Color, Normal and TextureCoordinates is supported. */
+       public Model createSphere(float width, float height, float depth, int divisionsU, int divisionsV, int primitiveType, final Material material, final long attributes) {
                begin();
-               part("cylinder", GL10.GL_TRIANGLES, attributes, material).sphere(width, height, depth, divisionsU, divisionsV);
+               part("cylinder", primitiveType, attributes, material).sphere(width, height, depth, divisionsU, divisionsV);
                return end();
        }
        
index 3cb5945..2032da9 100644 (file)
@@ -60,7 +60,7 @@ public class CullTest extends GdxTest implements ApplicationListener {
        @Override\r
        public void create () {\r
                ModelBuilder builder = new ModelBuilder();\r
-               sphere = builder.createSphere(2f, 2f, 2f, 16, 16, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)), new VertexAttributes(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)));\r
+               sphere = builder.createSphere(2f, 2f, 2f, 16, 16, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)), Usage.Position | Usage.Normal);\r
                // cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r
                cam = new OrthographicCamera(45, 45 * (Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight()));\r
 \r
index 245c910..9c65911 100644 (file)
@@ -59,7 +59,7 @@ public class FramebufferToTextureTest extends GdxTest {
                texture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);\r
                ObjLoader objLoader = new ObjLoader();\r
                mesh =  objLoader.loadObj(Gdx.files.internal("data/cube.obj"));\r
-               mesh.materials.get(0).add(new TextureAttribute(TextureAttribute.Diffuse, texture));\r
+               mesh.materials.get(0).set(new TextureAttribute(TextureAttribute.Diffuse, texture));\r
                modelInstance = new ModelInstance(mesh);\r
                modelBatch = new ModelBatch();\r
 \r
index 3695d9a..9b76125 100644 (file)
@@ -96,11 +96,11 @@ public class MaterialTest extends GdxTest {
        public boolean touchUp (int screenX, int screenY, int pointer, int button) {
                
                if(!material.has(TextureAttribute.Diffuse))
-                       material.add(textureAttribute);
+                       material.set(textureAttribute);
                else if(!material.has(ColorAttribute.Diffuse))
-                       material.add(colorAttribute);
+                       material.set(colorAttribute);
                else if(!material.has(BlendingAttribute.Type))
-                       material.add(blendingAttribute);
+                       material.set(blendingAttribute);
                else
                        material.clear();
                
index 54a85fe..80d314b 100644 (file)
@@ -64,7 +64,7 @@ public class PickingTest extends GdxTest {
                VP_HEIGHT = Gdx.graphics.getHeight() - 4 * BORDER;\r
                ObjLoader objLoader = new ObjLoader();\r
                sphere = objLoader.loadObj(Gdx.files.internal("data/sphere.obj"));\r
-               sphere.materials.get(0).add(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE));\r
+               sphere.materials.get(0).set(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE));\r
                cam = new PerspectiveCamera(45, VP_WIDTH, VP_HEIGHT);\r
 // cam = new OrthographicCamera(10, 10);\r
                cam.far = 200;\r
index f40f6db..b5bbcb6 100644 (file)
@@ -56,7 +56,7 @@ public class ProjectTest extends GdxTest {
        public void create () {\r
                ObjLoader objLoader = new ObjLoader();\r
                sphere = objLoader.loadObj(Gdx.files.internal("data/sphere.obj"));\r
-               sphere.materials.get(0).add(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE));\r
+               sphere.materials.get(0).set(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE));\r
                cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r
                cam.far = 200;\r
                Random rand = new Random();\r
index abe4b6f..a5a9b79 100644 (file)
@@ -113,10 +113,10 @@ public class BaseBulletTest extends BulletTest {
                // Create some simple meshes
                final Model groundModel = modelBuilder.createRect(20f, 0f, -20f, -20f, 0f, -20f, -20f, 0f, 20f, 20f, 0f, 20f, 0, 1, 0, 
                        new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(16f)),
-                       new VertexAttributes(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)));
+                       Usage.Position | Usage.Normal);
                final Model boxModel = modelBuilder.createBox(1f, 1f, 1f,
                        new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f)), 
-                       new VertexAttributes(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)));
+                       Usage.Position | Usage.Normal);
 
                // Add the constructors
                world.addConstructor("ground", new BulletConstructor(groundModel, 0f)); // mass = 0: static body
index a14d6c9..2e09b6b 100644 (file)
@@ -1,6 +1,7 @@
 package com.badlogic.gdx.tests.bullet;
 
 import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.GL10;
 import com.badlogic.gdx.graphics.Texture;
 import com.badlogic.gdx.graphics.VertexAttribute;
 import com.badlogic.gdx.graphics.VertexAttributes;
@@ -37,10 +38,7 @@ public class BasicShapesTest extends BaseBulletTest {
 
                texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
                final Material material = new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(1,1,1,1), FloatAttribute.createShininess(8f));
-               final VertexAttributes attributes = new VertexAttributes(
-                                               new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
-                                               new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE),
-                                               new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE+"0"));
+               final long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates;
                
                final Model sphere = modelBuilder.createSphere(4f, 4f, 4f, 24, 24, material, attributes);
                world.addConstructor("sphere", new BulletConstructor(sphere, 10f, new btSphereShape(2f)));
index e9290a3..5b454cd 100644 (file)
@@ -44,7 +44,7 @@ public class ConstraintsTest extends BaseBulletTest {
        public void create () {
                super.create();
 
-               final Model barModel = modelBuilder.createBox(10f, 1f, 1f, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)), new VertexAttributes(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE))); 
+               final Model barModel = modelBuilder.createBox(10f, 1f, 1f, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)), Usage.Position | Usage.Normal); 
                world.addConstructor("bar", new BulletConstructor(barModel, 0f)); // mass = 0: static body
                
                // Create the entities
index a0a7619..dc97ae5 100644 (file)
@@ -34,7 +34,7 @@ public class ConvexHullTest extends BaseBulletTest {
 
                final Model sceneModel = objLoader.loadObj(Gdx.files.internal("data/car.obj"));
                sceneModel.materials.get(0).clear();
-               sceneModel.materials.get(0).add(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE));
+               sceneModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE));
                world.addConstructor("car", new BulletConstructor(sceneModel, 5f, createConvexHullShape(sceneModel)));
 
                // Create the entities
index d537d4f..d5cc234 100644 (file)
@@ -41,7 +41,7 @@ public class MeshShapeTest extends BaseBulletTest {
                
                final Model sphereModel = modelBuilder.createSphere(0.5f, 0.5f, 0.5f, 8, 8, 
                        new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE)), 
-                       new VertexAttributes(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE))); 
+                       Usage.Position | Usage.Normal); 
                final BulletConstructor sphereConstructor = new BulletConstructor(sphereModel, 0.25f, new btSphereShape(0.25f));
                sphereConstructor.bodyInfo.setM_restitution(1f);
                world.addConstructor("sphere", sphereConstructor);
index 61bbe35..f7da1ce 100644 (file)
@@ -255,10 +255,8 @@ public class RayPickRagdollTest extends BaseBulletTest {
        
        protected Model createCapsuleModel(float radius, float height) {
                final float hh = radius + 0.5f * height;
-               // return ModelBuilder
                return modelBuilder.createCylinder(radius * 2, hh * 2f, radius * 2f, 16, 
                        new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE)), 
-                       new VertexAttributes(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)));
-               // return ModelBuilder.createBox(radius*2f, hh*2f, radius*2f, new NewMaterial(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)));
+                       Usage.Position | Usage.Normal);
        }
 }
index 04ed87d..ff30c9b 100644 (file)
@@ -55,17 +55,13 @@ public abstract class BaseG3dTest extends GdxTest {
        private void createAxes() {
                ModelBuilder modelBuilder = new ModelBuilder();
                modelBuilder.begin();
-               MeshPartBuilder builder = modelBuilder.part("grid", GL10.GL_LINES, new VertexAttributes(
-                       new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
-                       new VertexAttribute(Usage.Color, 4, ShaderProgram.COLOR_ATTRIBUTE)), new Material());
+               MeshPartBuilder builder = modelBuilder.part("grid", GL10.GL_LINES, Usage.Position | Usage.Color, 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", GL10.GL_LINES, new VertexAttributes(
-                       new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
-                       new VertexAttribute(Usage.Color, 4, ShaderProgram.COLOR_ATTRIBUTE)), new Material());
+               builder = modelBuilder.part("axes", GL10.GL_LINES, Usage.Position | Usage.Color, new Material());
                builder.setColor(Color.RED);
                builder.line(0, 0, 0, 100, 0, 0);
                builder.setColor(Color.GREEN);