com.badlogic.gdx.graphics.g3d.model.Node Java Examples
The following examples show how to use
com.badlogic.gdx.graphics.g3d.model.Node.
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: Ragdoll.java From GdxDemo3D with Apache License 2.0 | 6 votes |
/** * Updates the rigid body parts to follow nodes of the model instance */ private void updateBodiesToArmature() { // Ragdoll parts should follow the model animation. // Loop over each part and set it to the global transform of the armature node it should follow. capsuleTransform.set(modelTransform); for (Iterator<ObjectMap.Entry<btRigidBody, RigidBodyNodeConnection>> iterator = bodyPartMap.iterator(); iterator.hasNext(); ) { ObjectMap.Entry<btRigidBody, RigidBodyNodeConnection> entry = iterator.next(); RigidBodyNodeConnection data = entry.value; btRigidBody body = entry.key; Node followNode = data.followNode; Vector3 offset = data.bodyNodeOffsets.get(followNode); body.proceedToTransform(tmpMatrix.set(capsuleTransform) .mul(followNode.globalTransform).translate(offset)); } }
Example #2
Source File: HeadlessModel.java From gdx-proto with Apache License 2.0 | 6 votes |
private void loadAnimations (Iterable<ModelAnimation> modelAnimations) { for (final ModelAnimation anim : modelAnimations) { Animation animation = new Animation(); animation.id = anim.id; for (ModelNodeAnimation nanim : anim.nodeAnimations) { final Node node = getNode(nanim.nodeId); if (node == null) continue; NodeAnimation nodeAnim = new NodeAnimation(); nodeAnim.node = node; for (ModelNodeKeyframe kf : nanim.keyframes) { if (kf.keytime > animation.duration) animation.duration = kf.keytime; NodeKeyframe keyframe = new NodeKeyframe(); keyframe.keytime = kf.keytime; keyframe.rotation.set(kf.rotation == null ? node.rotation : kf.rotation); keyframe.scale.set(kf.scale == null ? node.scale : kf.scale); keyframe.translation.set(kf.translation == null ? node.translation : kf.translation); nodeAnim.keyframes.add(keyframe); } if (nodeAnim.keyframes.size > 0) animation.nodeAnimations.add(nodeAnim); } if (animation.nodeAnimations.size > 0) animations.add(animation); } }
Example #3
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 #4
Source File: AnimationControllerHack.java From gdx-gltf with Apache License 2.0 | 6 votes |
private final static void applyNodeAnimationBlending (final NodeAnimation nodeAnim, final ObjectMap<Node, Transform> out, final Pool<Transform> pool, final float alpha, final float time) { final Node node = nodeAnim.node; node.isAnimated = true; final Transform transform = getNodeAnimationTransform(nodeAnim, time); Transform t = out.get(node, null); if (t != null) { if (alpha > 0.999999f) t.set(transform); else t.lerp(transform, alpha); } else { if (alpha > 0.999999f) out.put(node, pool.obtain().set(transform)); else out.put(node, pool.obtain().set(node.translation, node.rotation, node.scale, ((NodePlus)node).weights).lerp(transform, alpha)); } }
Example #5
Source File: ModelManager.java From gdx-proto with Apache License 2.0 | 6 votes |
/** players are represented by cubes, with another cube marking the direction it is facing */ public void createPlayerModel() { ModelBuilder mb = new ModelBuilder(); ModelBuilder mb2 = new ModelBuilder(); long attr = Usage.Position | Usage.Normal; float r = 0.5f; float g = 1f; float b = 0.75f; Material material = new Material(ColorAttribute.createDiffuse(new Color(r, g, b, 1f))); Material faceMaterial = new Material(ColorAttribute.createDiffuse(Color.BLUE)); float w = 1f; float d = w; float h = 2f; mb.begin(); //playerModel = mb.createBox(w, h, d, material, attr); Node node = mb.node("box", mb2.createBox(w, h, d, material, attr)); // the face is just a box to show which direction the player is facing Node faceNode = mb.node("face", mb2.createBox(w/2, h/2, d/2, faceMaterial, attr)); faceNode.translation.set(0f, 0f, d/2); playerModel = mb.end(); }
Example #6
Source File: Ragdoll.java From GdxDemo3D with Apache License 2.0 | 6 votes |
/** * @param bodyPart The rigid body which is to be synchronized with a node * @param node The node which is to be synchronized with a body */ private void addPart(btRigidBody bodyPart, Node node) { if (!bodyPartMap.containsKey(bodyPart)) { bodyPartMap.put(bodyPart, new RigidBodyNodeConnection()); } RigidBodyNodeConnection conn = bodyPartMap.get(bodyPart); conn.followNode = node; // Set the follow offset to the middle of the armature bone Vector3 offsetTranslation = new Vector3(); node.getChild(0).localTransform.getTranslation(offsetTranslation).scl(0.5f); conn.bodyNodeOffsets.put(node, offsetTranslation); if (!ragdollMappedNodes.contains(node, true)) { ragdollMappedNodes.add(node); } }
Example #7
Source File: GameScene.java From GdxDemo3D with Apache License 2.0 | 6 votes |
/** * Creates and adds the navmesh to this scene. */ private void setNavmesh(GameObjectBlueprint bp) { // We need to set the node transforms before calculating the navmesh shape GameModel gameModel = new GameModel(bp.model, bp.name, bp.position, bp.rotation, bp.scale); Array<NodePart> nodes = gameModel.modelInstance.model.getNode("navmesh").parts; // Sort the model meshParts array according to material name nodes.sort(new NavMeshNodeSorter()); // The model transform must be applied to the meshparts for shape generation to work correctly. gameModel.modelInstance.calculateTransforms(); Matrix4 transform = new Matrix4(); for (Node node : gameModel.modelInstance.nodes) { transform.set(node.globalTransform).inv(); for (NodePart nodePart : node.parts) { nodePart.meshPart.mesh.transform(transform); } } navMesh = new NavMesh(gameModel.modelInstance.model); btCollisionShape shape = navMesh.getShape(); navmeshBody = new InvisibleBody("navmesh", shape, 0, gameModel.modelInstance.transform, GameEngine.NAVMESH_FLAG, GameEngine.NAVMESH_FLAG, false, false); worldBounds.set(gameModel.boundingBox); gameModel.dispose(); }
Example #8
Source File: ArmatureDebugDrawer.java From GdxDemo3D with Apache License 2.0 | 6 votes |
private void drawArmatureNodes(Node currentNode, Vector3 modelPos, Quaternion modelRot, Vector3 parentNodePos, Vector3 currentNodePos) { currentNode.globalTransform.getTranslation(currentNodePos); modelRot.transform(currentNodePos); currentNodePos.add(modelPos); drawVertex(currentNodePos, 0.02f, Color.GREEN); shapeRenderer.setColor(Color.YELLOW); if (currentNode.hasParent()) { shapeRenderer.line(parentNodePos, currentNodePos); } if (currentNode.hasChildren()) { float x = currentNodePos.x; float y = currentNodePos.y; float z = currentNodePos.z; for (Node child : currentNode.getChildren()) { drawArmatureNodes(child, modelPos, modelRot, currentNodePos, parentNodePos); currentNodePos.set(x, y, z); } } }
Example #9
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 #10
Source File: GameCharacter.java From GdxDemo3D with Apache License 2.0 | 5 votes |
/** * Midpoint of an armature bone, in world coordinate system. * * @param nodeId Name of the bone * @param out Output vector * @return Output vector for chaining */ public Vector3 getBoneMidpointWorldPosition(String nodeId, Vector3 out) { Node node = modelInstance.getNode(nodeId); Node endPointNode = (node.hasChildren()) ? node.getChild(0) : node; // Use global transform to account for model scaling node.globalTransform.getTranslation(TMP_V1); TMP_V3.set(TMP_V1); endPointNode.globalTransform.getTranslation(TMP_V2); TMP_V3.sub(TMP_V1.sub(TMP_V2).scl(0.5f)); modelInstance.transform.getRotation(TMP_Q, true).transform(TMP_V3); TMP_V3.add(getPosition()); return out.set(TMP_V3); }
Example #11
Source File: GameCharacter.java From GdxDemo3D with Apache License 2.0 | 5 votes |
/** * Direction vector of an armature bone, in world coordinate system. * * @param nodeId Name of the bone * @param out Output vector * @return Output vector for chaining */ public Vector3 getBoneDirection(String nodeId, Vector3 out) { Node node = modelInstance.getNode(nodeId); Node endPointNode = (node.hasChildren()) ? node.getChild(0) : node; node.globalTransform.getTranslation(TMP_V1); endPointNode.globalTransform.getTranslation(TMP_V2); TMP_V1.sub(TMP_V2).scl(-1); modelInstance.transform.getRotation(TMP_Q); TMP_Q.transform(TMP_V1); return out.set(TMP_V1).nor(); }
Example #12
Source File: GameModel.java From GdxDemo3D with Apache License 2.0 | 5 votes |
public static void applyTransform(Vector3 location, Vector3 rotation, Vector3 scale, ModelInstance modelInstance) { for (Node node : modelInstance.nodes) { node.scale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z)); } modelInstance.transform.rotate(Vector3.X, rotation.x); modelInstance.transform.rotate(Vector3.Z, rotation.z); modelInstance.transform.rotate(Vector3.Y, rotation.y); modelInstance.transform.setTranslation(location); modelInstance.calculateTransforms(); }
Example #13
Source File: SkinLoader.java From gdx-gltf with Apache License 2.0 | 5 votes |
private void load(GLTFSkin glSkin, GLTFNode glNode, Node node, NodeResolver nodeResolver, DataResolver dataResolver){ Array<Matrix4> ibms = new Array<Matrix4>(); Array<Integer> joints = new Array<Integer>(); int bonesCount = glSkin.joints.size; FloatBuffer floatBuffer = dataResolver.getBufferFloat(glSkin.inverseBindMatrices); for(int i=0 ; i<bonesCount ; i++){ float [] matrixData = new float[16]; floatBuffer.get(matrixData); ibms.add(new Matrix4(matrixData)); } joints.addAll(glSkin.joints); if(ibms.size > 0){ for(NodePart nodePart : node.parts){ nodePart.bones = new Matrix4[ibms.size]; nodePart.invBoneBindTransforms = new ArrayMap<Node, Matrix4>(); for(int n=0 ; n<joints.size ; n++){ nodePart.bones[n] = new Matrix4().idt(); int nodeIndex = joints.get(n); Node key = nodeResolver.get(nodeIndex); if(key == null) throw new GLTFIllegalException("node not found for bone: " + nodeIndex); nodePart.invBoneBindTransforms.put(key, ibms.get(n)); } } } }
Example #14
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 #15
Source File: GLTFMaterialExporter.java From gdx-gltf with Apache License 2.0 | 5 votes |
public void export(Iterable<Node> nodes) { for(Node node : nodes){ for(NodePart nodePart : node.parts){ export(nodePart.material); } export(node.getChildren()); } }
Example #16
Source File: GLTFCameraExporter.java From gdx-gltf with Apache License 2.0 | 5 votes |
public void export(ObjectMap<Node, Camera> cameras) { for(Entry<Node, Camera> entry : cameras){ int nodeID = base.nodeMapping.indexOf(entry.key, true); if(nodeID < 0) throw new GdxRuntimeException("node not found"); GLTFNode glNode = base.root.nodes.get(nodeID); if(base.root.cameras == null){ base.root.cameras = new Array<GLTFCamera>(); } glNode.camera = base.root.cameras.size; base.root.cameras.add(export(entry.value)); } }
Example #17
Source File: GLTFDemo.java From gdx-gltf with Apache License 2.0 | 5 votes |
private void drawSkeleton(Iterable<Node> iterable) { for(Node node : iterable){ if(node.parts == null || node.parts.size == 0){ float s = cameraControl.translateUnits / 100f; // .03f; shapeRenderer.setColor(Color.WHITE); node.globalTransform.getTranslation(v1); shapeRenderer.box(v1.x, v1.y, v1.z, s,s,s); } drawSkeleton(node.getChildren()); } }
Example #18
Source File: Ragdoll.java From GdxDemo3D with Apache License 2.0 | 5 votes |
/** * Updates the nodes of the model instance to follow the rigid body parts */ private void updateArmatureToBodies() { // Let dynamicsworld control ragdoll. Loop over all ragdoll part collision shapes // and their node connection data. for (Iterator<ObjectMap.Entry<btRigidBody, RigidBodyNodeConnection>> iterator1 = bodyPartMap.iterator(); iterator1.hasNext(); ) { ObjectMap.Entry<btRigidBody, RigidBodyNodeConnection> bodyEntry = iterator1.next(); btRigidBody partBody = bodyEntry.key; RigidBodyNodeConnection connection = bodyEntry.value; capsuleTransform.getTranslation(capsuleTranslation); // Loop over each node connected to this collision shape for (Iterator<ObjectMap.Entry<Node, Vector3>> iterator2 = connection.bodyNodeOffsets.iterator(); iterator2.hasNext(); ) { ObjectMap.Entry<Node, Vector3> nodeEntry = iterator2.next(); // A node which is to follow this collision shape Node node = nodeEntry.key; // The offset of this node from the untranslated collision shape origin Vector3 offset = nodeEntry.value; // Set the node to the transform of the collision shape it follows partBody.getWorldTransform(node.localTransform); // Calculate difference in translation between the node/ragdoll part and the // base capsule shape. node.localTransform.getTranslation(nodeTranslation); // Calculate the final node transform node.localTransform.setTranslation(nodeTranslation.sub(capsuleTranslation)).translate(tmpVec.set(offset).scl(-1)); } } // Calculate the final transform of the model. modelInstance.calculateTransforms(); }
Example #19
Source File: Ragdoll.java From GdxDemo3D with Apache License 2.0 | 5 votes |
/** * @param bodyPart The rigid body which is to be synchronized with a node * @param node The node which is to be synchronized with a body * @param nodeBodyOffset The offset from the node to rigid body origin */ private void addPart(btRigidBody bodyPart, Node node, Vector3 nodeBodyOffset) { if (!bodyPartMap.containsKey(bodyPart)) { bodyPartMap.put(bodyPart, new RigidBodyNodeConnection()); } RigidBodyNodeConnection conn = bodyPartMap.get(bodyPart); conn.bodyNodeOffsets.put(node, nodeBodyOffset); if (!ragdollMappedNodes.contains(node, true)) { ragdollMappedNodes.add(node); } }
Example #20
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 #21
Source File: ModelFactory.java From GdxDemo3D with Apache License 2.0 | 5 votes |
/** * Translate each vertex along its normal by specified amount. * * @param model * @param amount */ public static void fatten(Model model, float amount) { Vector3 pos = new Vector3(); Vector3 nor = new Vector3(); for (Node node : model.nodes) { for (NodePart n : node.parts) { Mesh mesh = n.meshPart.mesh; FloatBuffer buf = mesh.getVerticesBuffer(); int lastFloat = mesh.getNumVertices() * mesh.getVertexSize() / 4; int vertexFloats = (mesh.getVertexSize() / 4); VertexAttribute posAttr = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Position); VertexAttribute norAttr = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Normal); if (posAttr == null || norAttr == null) { throw new IllegalArgumentException("Position/normal vertex attribute not found"); } int pOff = posAttr.offset / 4; int nOff = norAttr.offset / 4; for (int i = 0; i < lastFloat; i += vertexFloats) { pos.x = buf.get(pOff + i); pos.y = buf.get(pOff + i + 1); pos.z = buf.get(pOff + i + 2); nor.x = buf.get(nOff + i); nor.y = buf.get(nOff + i + 1); nor.z = buf.get(nOff + i + 2); nor.nor().scl(amount); buf.put(pOff + i, pos.x + nor.x); buf.put(pOff + i + 1, pos.y + nor.y); buf.put(pOff + i + 2, pos.z + nor.z); } } } }
Example #22
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 #23
Source File: Sprite3DRenderer.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
private void createEnvirontment() { environment = new Environment(); // environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.8f, // 0.8f, 0.8f, 1f)); // environment.add(new DirectionalLight().set(1f, 1f, 1f, 1f, -1f, // -1f)); if (celLight == null) { Node n = null; if (currentSource != null) n = ((ModelCacheEntry) currentSource).modelInstance.getNode(celLightName); if (n != null) { celLight = new PointLight().set(1f, 1f, 1f, n.translation, 1f); } else { celLight = new PointLight().set(1f, 1f, 1f, 0.5f, 1f, 1f, 1f); } } environment.add(celLight); if (renderShadow) { shadowEnvironment = new Environment(); shadowEnvironment.add(shadowLight); shadowEnvironment.shadowMap = shadowLight; } }
Example #24
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 #25
Source File: HeadlessModel.java From gdx-proto with Apache License 2.0 | 5 votes |
private void loadNodes (Iterable<ModelNode> modelNodes) { nodePartBones.clear(); for (ModelNode node : modelNodes) { nodes.add(loadNode(null, node)); } for (ObjectMap.Entry<NodePart, ArrayMap<String, Matrix4>> e : nodePartBones.entries()) { if (e.key.invBoneBindTransforms == null) e.key.invBoneBindTransforms = new ArrayMap<Node, Matrix4>(Node.class, Matrix4.class); e.key.invBoneBindTransforms.clear(); for (ObjectMap.Entry<String, Matrix4> b : e.value.entries()) e.key.invBoneBindTransforms.put(getNode(b.key), new Matrix4(b.value).inv()); } }
Example #26
Source File: HeadlessModel.java From gdx-proto with Apache License 2.0 | 5 votes |
private Node loadNode (Node parent, ModelNode modelNode) { Node node = new Node(); node.id = modelNode.id; node.parent = parent; if (modelNode.translation != null) node.translation.set(modelNode.translation); if (modelNode.rotation != null) node.rotation.set(modelNode.rotation); if (modelNode.scale != null) node.scale.set(modelNode.scale); // FIXME create temporary maps for faster lookup? if (modelNode.parts != null) { for (ModelNodePart modelNodePart : modelNode.parts) { MeshPart meshPart = null; if (modelNodePart.meshPartId != null) { for (MeshPart part : meshParts) { if (modelNodePart.meshPartId.equals(part.id)) { meshPart = part; break; } } } if (meshPart == null) throw new GdxRuntimeException("Invalid node: " + node.id); NodePart nodePart = new NodePart(); nodePart.meshPart = meshPart; // nodePart.material = meshMaterial; node.parts.add(nodePart); if (modelNodePart.bones != null) nodePartBones.put(nodePart, modelNodePart.bones); } } if (modelNode.children != null) { for (ModelNode child : modelNode.children) { node.children.add(loadNode(node, child)); } } return node; }
Example #27
Source File: Scene.java From gdx-gltf with Apache License 2.0 | 5 votes |
public int getDirectionalLightCount() { int count = 0; for(Entry<Node, BaseLight> entry : lights){ if(entry.value instanceof DirectionalLight){ count++; } } return count; }
Example #28
Source File: NodeUtil.java From gdx-gltf with Apache License 2.0 | 5 votes |
public static Array<Node> getAllNodes(Array<Node> result, Node node) { result.add(node); for(int i=0 ; i<node.getChildCount() ; i++){ getAllNodes(result, node.getChild(i)); } return result; }
Example #29
Source File: GLTFDemoUI.java From gdx-gltf with Apache License 2.0 | 5 votes |
public void setLights(ObjectMap<Node, BaseLight> lights) { Array<String> names = new Array<String>(); names.add(""); for(Entry<Node, BaseLight> entry : lights){ names.add(entry.key.id); } lightSelector.setItems(names); }
Example #30
Source File: GLTFDemoUI.java From gdx-gltf with Apache License 2.0 | 5 votes |
public void setNodes(Array<Node> nodes) { nodeMap.clear(); Array<String> names = new Array<String>(); for(Node e : nodes){ names.add(e.id); nodeMap.put(e.id, e); } names.sort(); names.insert(0, ""); nodeSelector.setItems(); nodeSelector.setItems(names); }