Search in sources :

Example 16 with Node

use of com.badlogic.gdx.graphics.g3d.model.Node in project libgdx by libgdx.

the class ModelBuilder method rebuildReferences.

/** Resets the references to {@link Material}s, {@link Mesh}es and {@link MeshPart}s within the model to the ones used within
	 * it's nodes. This will make the model responsible for disposing all referenced meshes. */
public static void rebuildReferences(final Model model) {
    model.materials.clear();
    model.meshes.clear();
    model.meshParts.clear();
    for (final Node node : model.nodes) rebuildReferences(model, node);
}
Also used : Node(com.badlogic.gdx.graphics.g3d.model.Node)

Example 17 with Node

use of com.badlogic.gdx.graphics.g3d.model.Node in project libgdx by libgdx.

the class ModelBuilder method node.

/** Adds the nodes of the specified model to a new node of the model being build. After this method the given model can no
	 * longer be used. Do not call the {@link Model#dispose()} method on that model.
	 * @return The newly created node containing the nodes of the given model. */
public Node node(final String id, final Model model) {
    final Node node = new Node();
    node.id = id;
    node.addChildren(model.nodes);
    node(node);
    for (final Disposable disposable : model.getManagedDisposables()) manage(disposable);
    return node;
}
Also used : Disposable(com.badlogic.gdx.utils.Disposable) Node(com.badlogic.gdx.graphics.g3d.model.Node)

Example 18 with Node

use of com.badlogic.gdx.graphics.g3d.model.Node in project libgdx by libgdx.

the class ModelBuilder method rebuildReferences.

private static void rebuildReferences(final Model model, final Node node) {
    for (final NodePart mpm : node.parts) {
        if (!model.materials.contains(mpm.material, true))
            model.materials.add(mpm.material);
        if (!model.meshParts.contains(mpm.meshPart, true)) {
            model.meshParts.add(mpm.meshPart);
            if (!model.meshes.contains(mpm.meshPart.mesh, true))
                model.meshes.add(mpm.meshPart.mesh);
            model.manageDisposable(mpm.meshPart.mesh);
        }
    }
    for (final Node child : node.getChildren()) rebuildReferences(model, child);
}
Also used : Node(com.badlogic.gdx.graphics.g3d.model.Node) NodePart(com.badlogic.gdx.graphics.g3d.model.NodePart)

Example 19 with Node

use of com.badlogic.gdx.graphics.g3d.model.Node in project libgdx by libgdx.

the class ShaderTest method create.

@Override
public void create() {
    modelBatch = new ModelBatch(new DefaultShaderProvider() {

        @Override
        protected Shader createShader(Renderable renderable) {
            if (renderable.material.has(TestAttribute.ID))
                return new TestShader(renderable);
            return super.createShader(renderable);
        }
    });
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(0f, 0f, 20f);
    cam.lookAt(0, 0, 0);
    cam.near = 1f;
    cam.far = 300f;
    cam.update();
    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);
    Material testMaterial1 = new Material("TestMaterial1", new TestAttribute(1f));
    Material redMaterial = new Material("RedMaterial", ColorAttribute.createDiffuse(Color.RED));
    Material testMaterial2 = new Material("TestMaterial2", new TestAttribute(1f), ColorAttribute.createDiffuse(Color.BLUE));
    ModelBuilder builder = new ModelBuilder();
    Node node;
    builder.begin();
    node = builder.node();
    node.id = "testCone1";
    node.translation.set(-10, 0f, 0f);
    builder.part("testCone", GL20.GL_TRIANGLES, Usage.Position, testMaterial1).cone(5, 5, 5, 20);
    node = builder.node();
    node.id = "redSphere";
    builder.part("redSphere", GL20.GL_TRIANGLES, Usage.Position, redMaterial).sphere(5, 5, 5, 20, 20);
    node = builder.node();
    node.id = "testCone1";
    node.translation.set(10, 0f, 0f);
    builder.part("testCone", GL20.GL_TRIANGLES, Usage.Position, testMaterial2).cone(5, 5, 5, 20);
    model = builder.end();
    ModelInstance modelInstance;
    modelInstance = new ModelInstance(model);
    testAttribute1 = (TestAttribute) modelInstance.getMaterial("TestMaterial1").get(TestAttribute.ID);
    testAttribute2 = (TestAttribute) modelInstance.getMaterial("TestMaterial2").get(TestAttribute.ID);
    instances.add(modelInstance);
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) DefaultShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) Renderable(com.badlogic.gdx.graphics.g3d.Renderable) Node(com.badlogic.gdx.graphics.g3d.model.Node) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera)

Example 20 with Node

use of com.badlogic.gdx.graphics.g3d.model.Node in project libgdx by libgdx.

the class SkeletonTest method renderSkeleton.

public void renderSkeleton(final ModelInstance instance) {
    shapeRenderer.setProjectionMatrix(cam.combined);
    shapeRenderer.begin(ShapeType.Line);
    for (Node node : instance.nodes) {
        shapeRenderer.setColor(node.isAnimated ? Color.RED : Color.YELLOW);
        node.globalTransform.getTranslation(tmpV);
        shapeRenderer.box(tmpV.x, tmpV.y, tmpV.z, 0.5f, 0.5f, 0.5f);
        for (Node child : node.getChildren()) renderSkeleton(tmpV, child);
    }
    shapeRenderer.end();
}
Also used : Node(com.badlogic.gdx.graphics.g3d.model.Node)

Aggregations

Node (com.badlogic.gdx.graphics.g3d.model.Node)21 Vector3 (com.badlogic.gdx.math.Vector3)5 NodePart (com.badlogic.gdx.graphics.g3d.model.NodePart)4 Model (com.badlogic.gdx.graphics.g3d.Model)3 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)3 NodeAnimation (com.badlogic.gdx.graphics.g3d.model.NodeAnimation)3 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)2 Material (com.badlogic.gdx.graphics.g3d.Material)2 Animation (com.badlogic.gdx.graphics.g3d.model.Animation)2 MeshPart (com.badlogic.gdx.graphics.g3d.model.MeshPart)2 NodeKeyframe (com.badlogic.gdx.graphics.g3d.model.NodeKeyframe)2 ModelNode (com.badlogic.gdx.graphics.g3d.model.data.ModelNode)2 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)2 Quaternion (com.badlogic.gdx.math.Quaternion)2 BoundingBox (com.badlogic.gdx.math.collision.BoundingBox)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 AssetManager (com.badlogic.gdx.assets.AssetManager)1 Camera (com.badlogic.gdx.graphics.Camera)1 Texture (com.badlogic.gdx.graphics.Texture)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1