com.badlogic.gdx.graphics.g3d.Model Java Examples
The following examples show how to use
com.badlogic.gdx.graphics.g3d.Model.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UsefulMeshs.java From Mundus with Apache License 2.0 | 6 votes |
public static Model createAxes() { final float GRID_MIN = -10f; final float GRID_MAX = 10f; final float GRID_STEP = 1f; ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, new Material()); builder.setColor(Color.LIGHT_GRAY); for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) { builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX); builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t); } builder = modelBuilder.part("axes", GL20.GL_LINES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, new Material()); builder.setColor(Color.RED); builder.line(0, 0, 0, 100, 0, 0); builder.setColor(Color.GREEN); builder.line(0, 0, 0, 0, 100, 0); builder.setColor(Color.BLUE); builder.line(0, 0, 0, 0, 0, 100); return modelBuilder.end(); }
Example #2
Source File: GameModel.java From GdxDemo3D with Apache License 2.0 | 6 votes |
/** * Holds a an instance of the model. * * @param name Name of model * @param model Model to instantiate * @param location World position at which to place the model instance * @param rotation The rotation of the model instance in degrees * @param scale Scale of the model instance */ public GameModel(Model model, String name, Vector3 location, Vector3 rotation, Vector3 scale) { super(name); modelInstance = new ModelInstance(model); applyTransform(location, rotation, scale, modelInstance); try { modelInstance.calculateBoundingBox(boundingBox); } catch (Exception e) { Gdx.app.debug(TAG, "Error when calculating bounding box.", e); } boundingBox.getCenter(center); boundingBox.getDimensions(dimensions); boundingBoxRadius = dimensions.len() / 2f; modelTransform = modelInstance.transform; halfExtents.set(dimensions).scl(0.5f); }
Example #3
Source File: BulletConstructor.java From gdx-ai with Apache License 2.0 | 6 votes |
private void create (final Model model, final float mass, final btCollisionShape shape) { this.model = model; this.shape = shape; if (shape != null && mass >= 0) { // Calculate the local inertia, bodies with no mass are static Vector3 localInertia; if (mass == 0) localInertia = Vector3.Zero; else { shape.calculateLocalInertia(mass, tmpV); localInertia = tmpV; } // For now just pass null as the motionstate, we'll add that to the body in the entity itself bodyInfo = new btRigidBodyConstructionInfo(mass, null, shape, localInertia); } }
Example #4
Source File: Ragdoll.java From GdxDemo3D with Apache License 2.0 | 6 votes |
/** * Constructs a ragdoll out of rigid bodies using physics constraints. * * @param model Model to instantiate * @param name Name of model * @param location World position at which to place the model instance * @param rotation The rotation of the model instance in degrees * @param scale Scale of the model instance * @param shape Collision shape with which to construct a rigid body * @param mass Mass of the body * @param belongsToFlag Flag for which collision layers this body belongs to * @param collidesWithFlag Flag for which collision layers this body collides with * @param callback If this body should trigger collision contact callbacks. * @param noDeactivate If this body should never 'sleep' * @param ragdollEmpties Blender empties with body part definitions * @param armatureNodeId The id of the root node in the model animation armature * @param steerSettings Steerable settings */ public Ragdoll(Model model, String name, Vector3 location, Vector3 rotation, Vector3 scale, btCollisionShape shape, float mass, short belongsToFlag, short collidesWithFlag, boolean callback, boolean noDeactivate, Array<BlenderEmpty> ragdollEmpties, String armatureNodeId, SteerSettings steerSettings) { super(model, name, location, rotation, scale, shape, mass, belongsToFlag, collidesWithFlag, callback, noDeactivate, steerSettings); createRagdoll(ragdollEmpties, armatureNodeId); }
Example #5
Source File: ExportSharedIndexBufferTest.java From gdx-gltf with Apache License 2.0 | 6 votes |
@Override public void create() { Material material = new Material(); ModelBuilder mb = new ModelBuilder(); MeshPartBuilder mpb; mb.begin(); mpb = mb.part("part1", GL20.GL_TRIANGLES, Usage.Position, material); BoxShapeBuilder.build(mpb, 1, 1, 1); mpb = mb.part("part2", GL20.GL_TRIANGLES, Usage.Position, material); mpb.setVertexTransform(new Matrix4().setToTranslation(2, 0, 0)); BoxShapeBuilder.build(mpb, 1, 1, 1); Model model = mb.end(); new GLTFExporter().export(model, Gdx.files.absolute("/tmp/ExportSharedIndexBufferTest.gltf")); Gdx.app.exit(); }
Example #6
Source File: Sprite3DRenderer.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
private void retrieveSource(String source) { ModelCacheEntry entry = (ModelCacheEntry) sourceCache.get(source); if (entry == null || entry.refCounter < 1) { loadSource(source); EngineAssetManager.getInstance().finishLoading(); entry = (ModelCacheEntry) sourceCache.get(source); } if (entry.modelInstance == null) { Model model3d = EngineAssetManager.getInstance().getModel3D(source); entry.modelInstance = new ModelInstance(model3d); entry.controller = new AnimationController(entry.modelInstance); entry.camera3d = getCamera(entry.modelInstance); } }
Example #7
Source File: LevelBuilder.java From gdx-proto with Apache License 2.0 | 6 votes |
/** client builds statics, probably based on info from server */ public static void buildStatics(LevelStatic[] statics) { if (staticGeometry == null) { staticGeometry = new Array<>(); } Log.debug("client building statics received from server: " + statics.length); ModelBuilder mb = new ModelBuilder(); mb.begin(); for (LevelStatic stat : statics) { Model model = Assets.manager.get(stat.modelName, Model.class); setupStaticModel(model.meshParts, stat.mtx, true); Node node = mb.node("piece", model); stat.mtx.getTranslation(tmp); node.translation.set(tmp); node.rotation.set(stat.mtx.getRotation(q)); } Model finalModel = mb.end(); ModelInstance instance = new ModelInstance(finalModel); staticGeometry.add(instance); }
Example #8
Source File: ModelFactory.java From GdxDemo3D with Apache License 2.0 | 6 votes |
public static Model buildPlaneModel(final float width, final float height, final Material material, final float u1, final float v1, final float u2, final float v2) { ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder bPartBuilder = modelBuilder.part("rect", GL20.GL_TRIANGLES, VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates, material); bPartBuilder.setUVRange(u1, v1, u2, v2); bPartBuilder.rect(-(width * 0.5f), -(height * 0.5f), 0, (width * 0.5f), -(height * 0.5f), 0, (width * 0.5f), (height * 0.5f), 0, -(width * 0.5f), (height * 0.5f), 0, 0, 0, -1); return (modelBuilder.end()); }
Example #9
Source File: ScaleTool.java From Mundus with Apache License 2.0 | 6 votes |
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 }; }
Example #10
Source File: Benchmark.java From gdx-gltf with Apache License 2.0 | 5 votes |
protected void assertConsistent(Model model) { final long expectedAttributes = VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates; assertEquals(0, model.animations.size); // assertEquals(1, model.materials.size); TODO GLTF should collect that? assertEquals(4, model.meshes.size); // assertEquals(1, model.meshParts.size); TODO GLTF should collect that? assertEquals(4, model.nodes.size); for(Node node : model.nodes){ assertEquals(0, node.getChildCount()); assertEquals(1, node.parts.size); MeshPart mp = node.parts.first().meshPart; assertEquals(0, mp.offset); assertEquals(GL20.GL_TRIANGLES, mp.primitiveType); assertEquals(36864, mp.size); assertEquals(expectedAttributes, mp.mesh.getVertexAttributes().getMask()); boolean isIndexed = mp.mesh.getNumIndices() > 0; if(isIndexed){ // XXX OBJ doesn't have indexed meshes assertEquals(24576, mp.mesh.getNumVertices()); assertEquals(36864, mp.mesh.getNumIndices()); }else{ assertEquals(36864, mp.mesh.getNumVertices()); } } }
Example #11
Source File: Terrain.java From gdx-proto with Apache License 2.0 | 5 votes |
/** * * @param model the model which is used for rendering * @param collisionMesh a mesh used for collision * @return */ public static TerrainChunk CreateMeshChunk (Model model, Model collisionMesh) { // Creates collision out the collision mesh btCollisionObject obj = new btCollisionObject(); btCollisionShape shape = new btBvhTriangleMeshShape(collisionMesh.meshParts); obj.setCollisionShape(shape); Physics.applyStaticGeometryCollisionFlags(obj); Physics.inst.addStaticGeometryToWorld(obj); return new TerrainChunk(new ModelInstance(model), obj); }
Example #12
Source File: GameObjectBlueprint.java From GdxDemo3D with Apache License 2.0 | 5 votes |
public GameObjectBlueprint(BlenderModel blenderModel, Model model, BlenderEmpty blenderEmpty) { this.model = model; setFromObject(blenderModel); if (blenderEmpty.custom_properties.containsKey(blenderPfxField)) { pfx = blenderEmpty.custom_properties.get(blenderPfxField); return; } if (blenderEmpty.custom_properties.containsKey(blenderCollisionShapeField) && blenderEmpty.custom_properties.containsKey(blenderMassField)) { setRigidBody(blenderEmpty, model, blenderModel.scale); return; } throw new GdxRuntimeException("Cannot load collision shape data for " + blenderModel.name + " from '" + blenderEmpty.name + "'"); }
Example #13
Source File: WorldGenerator.java From Skyland with MIT License | 5 votes |
public static BulletWorld generateBaseWorld(boolean grid, boolean debug) { BulletWorld world = new BulletWorld(new Vector3(0, -9.81f, 0)); Builder.init(world); //Sets the stuff so you can use Builder class if (debug) world.setDebugMode(btIDebugDraw.DebugDrawModes.DBG_DrawWireframe | btIDebugDraw.DebugDrawModes.DBG_DrawFeaturesText | btIDebugDraw.DebugDrawModes.DBG_DrawText | btIDebugDraw.DebugDrawModes.DBG_DrawContactPoints); if (grid) world.add(new BulletEntity(ModelGenerator.generateAxis(-10, 10, 1), null)); btCollisionShape collisionShape = Bullet.obtainStaticNodeShape(Assets.get(Models.MODEL_ISLAND_PROTOTYPE, Model.class).nodes.first(), true); world.addConstructor("island", new BulletConstructor(Assets.get(Models.MODEL_ISLAND_PROTOTYPE, Model.class), 0, collisionShape)); return world; }
Example #14
Source File: Builder.java From Skyland with MIT License | 5 votes |
private static void buildCave(Matrix4 transform) { Model caveModel = Assets.get(CURR_MODEL, Model.class); if (WORLD.getConstructor("cave") == null) { for (Node n : caveModel.nodes) n.scale.set(.6f, .6f, .6f); btCollisionShape collisionShape = Bullet.obtainStaticNodeShape(caveModel.nodes); collisionShape.setLocalScaling(new Vector3(.6f, .6f, .6f)); WORLD.addConstructor("cave", new BulletConstructor(caveModel, 0, collisionShape)); } BulletEntity cave = WORLD.add("cave", transform); cave.body.setCollisionFlags(cave.body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_KINEMATIC_OBJECT); cave.body.setActivationState(Collision.DISABLE_DEACTIVATION); cave.body.userData = new BulletUserData("cave", cave); }
Example #15
Source File: GLTFExporter.java From gdx-gltf with Apache License 2.0 | 5 votes |
/** convenient method to export a single model */ public void export(Model model, FileHandle file) { GLTFScene scene = beginSingleScene(file); new GLTFMaterialExporter(this).export(model.nodes); scene.nodes = exportNodes(scene, model.nodes); new GLTFSkinExporter(this).export(); new GLTFAnimationExporter(this).export(model.animations); end(file); }
Example #16
Source File: GameObjectBlueprint.java From GdxDemo3D with Apache License 2.0 | 5 votes |
public GameObjectBlueprint(BlenderModel blenderModel, Model model) { this.model = model; setFromObject(blenderModel); this.mass = 0; ModelInstance modelInstance = new ModelInstance(model); GameModel.applyTransform(position, rotation, blenderModel.scale, modelInstance); this.shape = Bullet.obtainStaticNodeShape(modelInstance.nodes); this.shapeType = "static_node_shape_" + blenderModel.name; setCollisionFlags(this.mass); }
Example #17
Source File: DemoMotionGdxAdapter.java From thunderboard-android with Apache License 2.0 | 5 votes |
public void initModel() { // initMatrix is our starting position, it has to compensate for any transforms // in the model file we load assets.load(getModelFilename(), Model.class); initOrientation(); loading = true; }
Example #18
Source File: ModelFactory.java From GdxDemo3D with Apache License 2.0 | 5 votes |
public static Model buildBillboardModel(Texture texture, float width, float height) { TextureRegion textureRegion = new TextureRegion(texture, texture.getWidth(), texture.getHeight()); Material material = new Material(); material.set(new TextureAttribute(TextureAttribute.Diffuse, textureRegion)); material.set(new ColorAttribute(ColorAttribute.AmbientLight, Color.WHITE)); material.set(new BlendingAttribute()); return ModelFactory.buildPlaneModel(width, height, material, 0, 0, 1, 1); }
Example #19
Source File: Box.java From gdx-proto with Apache License 2.0 | 5 votes |
/** create some boxes to fill the level with some test geometry */ public static void createBoxes(int count) { ModelBuilder main = new ModelBuilder(); ModelBuilder mb = new ModelBuilder(); Material material = new Material(); if (Main.isClient()) { material.set(TextureAttribute.createDiffuse(Assets.manager.get("textures/marble.jpg", Texture.class))); } main.begin(); //float x = GameWorld.WORLD_WIDTH; //float y = GameWorld.WORLD_DEPTH; for (int i = 0; i < count; i++) { //float w = MathUtils.random(minW, maxW); float w = 8f; float d = 8f; float h = (i+1)*5f; tmp.set(10f + (w+2) * i, 0f, 10f + (d+2) * i); if (Main.isClient()) { mb.begin(); MeshPartBuilder mpb = mb.part("part-" + i, GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, material); mpb.box(w, h, d); Model boxModel = mb.end(); Node node = main.node("box-" + i, boxModel); node.translation.set(tmp); q.idt(); node.rotation.set(q); } //node.translation.set(MathUtils.random(x), 0f, MathUtils.random(y)); //q.set(Vector3.X, -90); mtx.set(q); mtx.setTranslation(tmp); btCollisionObject obj = Physics.inst.createBoxObject(tmp.set(w/2, h/2, d/2)); obj.setWorldTransform(mtx); Physics.applyStaticGeometryCollisionFlags(obj); Physics.inst.addStaticGeometryToWorld(obj); } Model finalModel = main.end(); instance = new ModelInstance(finalModel); }
Example #20
Source File: BlenderAssetManager.java From GdxDemo3D with Apache License 2.0 | 5 votes |
public <T> void manageDisposableFromPath(String assetId, String localPath, Class<T> type) { if (type == Texture.class) { sceneData.textures.add(new BlenderTexture(assetId, localPath)); assetManager.load(localPath, Texture.class, textureParameter); } else if (type == Model.class) { sceneData.models.add(new BlenderModel(assetId, localPath)); assetManager.load(localPath, Model.class, modelParameters); } else { throw new GdxRuntimeException("Asset type not supported '" + type + "'"); } }
Example #21
Source File: UsefulMeshs.java From Mundus with Apache License 2.0 | 5 votes |
public static Model createArrowStub(Material mat, Vector3 from, Vector3 to) { ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder meshBuilder; // line meshBuilder = modelBuilder.part("line", GL20.GL_LINES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, mat); meshBuilder.line(from.x, from.y, from.z, to.x, to.y, to.z); // stub Node node = modelBuilder.node(); node.translation.set(to.x, to.y, to.z); meshBuilder = modelBuilder.part("stub", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal, mat); BoxShapeBuilder.build(meshBuilder, 2, 2, 2); return modelBuilder.end(); }
Example #22
Source File: Actor3d.java From Scene3d with Apache License 2.0 | 5 votes |
public Actor3d(Model model, float x, float y, float z){ super(model); setPosition(x,y,z); //boundBox = model.meshes.get(0).calculateBoundingBox(); calculateBoundingBox(boundBox); center.set(boundBox.getCenter()); dimensions.set(boundBox.getDimensions()); radius = dimensions.len() / 2f; animation = new AnimationController(this); }
Example #23
Source File: TranslateTool.java From Mundus with Apache License 2.0 | 5 votes |
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); }
Example #24
Source File: NavMesh.java From GdxDemo3D with Apache License 2.0 | 5 votes |
public NavMesh(Model model) { btTriangleIndexVertexArray vertexArray = new btTriangleIndexVertexArray(model.meshParts); collisionShape = new btBvhTriangleMeshShape(vertexArray, true); raycastCallback = new NavMeshRaycastCallback(navMeshRayFrom, navMeshRayTo); raycastCallback.setFlags(btTriangleRaycastCallback.EFlags.kF_FilterBackfaces); graph = new NavMeshGraph(model); pathFinder = new IndexedAStarPathFinder<Triangle>(graph); heuristic = new NavMeshHeuristic(); }
Example #25
Source File: ScaleTool.java From Mundus with Apache License 2.0 | 5 votes |
public ScaleHandle(int id, Model model) { super(id); this.model = model; this.modelInstance = new ModelInstance(model); modelInstance.materials.first().set(getIdAttribute()); }
Example #26
Source File: DogCharacter.java From GdxDemo3D with Apache License 2.0 | 5 votes |
public DogCharacter(Model model, String name, Vector3 location, Vector3 rotation, Vector3 scale, btCollisionShape shape, float mass, short belongsToFlag, short collidesWithFlag, boolean callback, boolean noDeactivate) { super(model, name, location, rotation, scale, shape, mass, belongsToFlag, collidesWithFlag, callback, noDeactivate, new DogSteerSettings()); // Create behavior tree through the library BehaviorTreeLibraryManager btlm = BehaviorTreeLibraryManager.getInstance(); this.tree = btlm.createBehaviorTree("btrees/dog.btree", this); // Create animation controller animations = new AnimationController(modelInstance); // Create path follower followPathSteerer = new FollowPathSteerer(this); // Create wander steerer wanderSteerer = new WanderSteerer(this); // Init flags humanWantToPlay = false; stickThrown = false; alreadyCriedForHumanDeath = false; humanIsDead = false; }
Example #27
Source File: GameObjectBlueprint.java From GdxDemo3D with Apache License 2.0 | 5 votes |
public GameObjectBlueprint(BlenderModel blenderModel, Model model, btCollisionShape shape, float mass, String shapeType) { this.shape = shape; this.mass = mass; this.shapeType = shapeType; this.model = model; setFromObject(blenderModel); setCollisionFlags(this.mass); }
Example #28
Source File: GameScene.java From GdxDemo3D with Apache License 2.0 | 5 votes |
private void setVColorBlendAttributes() { Array<String> modelsIdsInScene = assets.getPlaceholderIdsByType(BlenderModel.class); Array<BlenderModel> instancesWithId = new Array<BlenderModel>(); for (String id : modelsIdsInScene) { instancesWithId.clear(); assets.getPlaceholders(id, BlenderModel.class, instancesWithId); for (BlenderModel blenderModel : instancesWithId) { // Maybe check if // renderable.meshPart.mesh.getVertexAttribute(VertexAttributes.Usage.ColorUnpacked) != null if (blenderModel.custom_properties.containsKey("v_color_material_blend")) { Model model = assets.getAsset(id, Model.class); String redMaterialName = blenderModel.custom_properties.get("v_color_material_red"); String greenMaterialName = blenderModel.custom_properties.get("v_color_material_green"); String blueMaterialName = blenderModel.custom_properties.get("v_color_material_blue"); TextureAttribute redTexAttr = (TextureAttribute) model.getMaterial(redMaterialName).get(TextureAttribute.Diffuse); TextureAttribute greenTexAttr = (TextureAttribute) model.getMaterial(greenMaterialName).get(TextureAttribute.Diffuse); TextureAttribute blueTexAttr = (TextureAttribute) model.getMaterial(blueMaterialName).get(TextureAttribute.Diffuse); VertexColorTextureBlend redAttribute = new VertexColorTextureBlend(VertexColorTextureBlend.Red, redTexAttr.textureDescription.texture); VertexColorTextureBlend greenAttribute = new VertexColorTextureBlend(VertexColorTextureBlend.Green, greenTexAttr.textureDescription.texture); VertexColorTextureBlend blueAttribute = new VertexColorTextureBlend(VertexColorTextureBlend.Blue, blueTexAttr.textureDescription.texture); for (Node node : model.nodes) { for (NodePart nodePart : node.parts) { nodePart.material.set(redAttribute, greenAttribute, blueAttribute); } } break; } } } }
Example #29
Source File: SteerableBody.java From GdxDemo3D with Apache License 2.0 | 5 votes |
/** * @param model Model to instantiate * @param name Name of model * @param location World position at which to place the model instance * @param rotation The rotation of the model instance in degrees * @param scale Scale of the model instance * @param shape Collision shape with which to construct a rigid body * @param mass Mass of the body * @param belongsToFlag Flag for which collision layers this body belongs to * @param collidesWithFlag Flag for which collision layers this body collides with * @param callback If this body should trigger collision contact callbacks. * @param noDeactivate If this body should never 'sleep' * @param steerSettings Steerable settings */ public SteerableBody(Model model, String name, Vector3 location, Vector3 rotation, Vector3 scale, btCollisionShape shape, float mass, short belongsToFlag, short collidesWithFlag, boolean callback, boolean noDeactivate, SteerSettings steerSettings) { super(model, name, location, rotation, scale, shape, mass, belongsToFlag, collidesWithFlag, callback, noDeactivate); // Set the bounding radius used by steering behaviors like collision avoidance, // raycast collision avoidance and some others. Note that calculation only takes // into account dimensions on the horizontal plane since we are steering in 2.5D this.boundingRadius = (boundingBox.getWidth() + boundingBox.getDepth()) / 4; this.steerSettings = steerSettings; setZeroLinearSpeedThreshold(steerSettings.getZeroLinearSpeedThreshold()); // Don't allow physics engine to turn character around any axis. // This prevents it from gaining any angular velocity as a result of collisions, for instance. // Usually, you use angular factor Vector3.Y, which allows the engine to turn it only around // the up axis, but here we can use Vector3.Zero since we directly set linear and angular // velocity in applySteering() instead of using force and torque. // This gives us (almost?) total control over character's motion. // Of course, subclasses can specify different angular factor, if needed. body.setAngularFactor(Vector3.Zero); }
Example #30
Source File: GameCharacter.java From GdxDemo3D with Apache License 2.0 | 5 votes |
public GameCharacter(Model model, String name, Vector3 location, Vector3 rotation, Vector3 scale, btCollisionShape shape, float mass, short belongsToFlag, short collidesWithFlag, boolean callback, boolean noDeactivate, SteerSettings steerSettings) { super(model, name, location, rotation, scale, shape, mass, belongsToFlag, collidesWithFlag, callback, noDeactivate, steerSettings); selectionMarkerOffset = new Vector3(0, -halfExtents.y * 0.95f, 0); }