Search in sources :

Example 1 with NodePart

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

the class ModelInstance method invalidate.

/** Makes sure that each {@link NodePart} of the {@link Node} and its sub-nodes, doesn't reference a node outside this node
	 * tree and that all materials are listed in the {@link #materials} array. */
private void invalidate(Node node) {
    for (int i = 0, n = node.parts.size; i < n; ++i) {
        NodePart part = node.parts.get(i);
        ArrayMap<Node, Matrix4> bindPose = part.invBoneBindTransforms;
        if (bindPose != null) {
            for (int j = 0; j < bindPose.size; ++j) {
                bindPose.keys[j] = getNode(bindPose.keys[j].id);
            }
        }
        if (!materials.contains(part.material, true)) {
            final int midx = materials.indexOf(part.material, false);
            if (midx < 0)
                materials.add(part.material = part.material.copy());
            else
                part.material = materials.get(midx);
        }
    }
    for (int i = 0, n = node.getChildCount(); i < n; ++i) {
        invalidate(node.getChild(i));
    }
}
Also used : Node(com.badlogic.gdx.graphics.g3d.model.Node) NodePart(com.badlogic.gdx.graphics.g3d.model.NodePart) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 2 with NodePart

use of com.badlogic.gdx.graphics.g3d.model.NodePart in project bdx by GoranM.

the class Mesh method copy.

public Mesh copy(String newName) {
    Model uniqueModel = scene.createModel(new JsonReader().parse(serialized()));
    Mesh newMesh = new Mesh(uniqueModel, scene, newName);
    newMesh.materials.clear();
    for (NodePart part : uniqueModel.nodes.get(0).parts) {
        // Don't forget to cast to Material for it to be a true copy (see shader copying)
        Material newMat = new Material((Material) part.material);
        newMesh.materials.add(newMat);
        part.material = newMat;
    }
    return newMesh;
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model) JsonReader(com.badlogic.gdx.utils.JsonReader) NodePart(com.badlogic.gdx.graphics.g3d.model.NodePart)

Example 3 with NodePart

use of com.badlogic.gdx.graphics.g3d.model.NodePart in project ProjektGG by eskalon.

the class GameMapScreen method onInit.

@Override
protected void onInit() {
    titleImage = assetManager.get(TITLE_IMAGE_PATH);
    sceneRenderer = new SceneRenderer(game.getGameCamera().getCamera(), game.getCurrentSession().getCity());
    Model scene = assetManager.get(TEST_SCENE_PATH);
    for (int i = 0; i < scene.nodes.size; i++) {
        String id = scene.nodes.get(i).id;
        RenderData instance = new RenderData(scene, id, true);
        if (id.equals("space")) {
            game.getCurrentSession().getCity().setSkybox(instance);
            continue;
        }
        game.getCurrentSession().getCity().getBuildings().add(new Building(i, instance));
    /*
			 * if (id.equals("ship")) ship = instance; else if
			 * (id.startsWith("block")) blocks.add(instance); else if
			 * (id.startsWith("invader")) invaders.add(instance);
			 */
    }
    ModelBuilder modelBuilder = new ModelBuilder();
    Model model = modelBuilder.createSphere(2f, 2f, 2f, 20, 20, new Material(), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
    NodePart blockPart = model.nodes.get(0).parts.get(0);
    renderable = new Renderable();
    blockPart.setRenderable(renderable);
    renderable.environment = sceneRenderer.environment;
    renderable.worldTransform.idt();
    renderContext = new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 1));
    shader = new TestShader(game.getAssetManager());
    shader.init();
    // this.renderContext = new RenderContext(
    // new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 1));
    // this.shader.init();
    this.cameraController = new CameraInputController(game.getGameCamera().getCamera());
}
Also used : Building(de.gg.entity.Building) RenderContext(com.badlogic.gdx.graphics.g3d.utils.RenderContext) Material(com.badlogic.gdx.graphics.g3d.Material) TestShader(de.gg.render.TestShader) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) Renderable(com.badlogic.gdx.graphics.g3d.Renderable) RenderData(de.gg.render.RenderData) Model(com.badlogic.gdx.graphics.g3d.Model) NodePart(com.badlogic.gdx.graphics.g3d.model.NodePart) SceneRenderer(de.gg.render.SceneRenderer) DefaultTextureBinder(com.badlogic.gdx.graphics.g3d.utils.DefaultTextureBinder)

Example 4 with NodePart

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

the class Model method loadNode.

protected Node loadNode(ModelNode modelNode) {
    Node node = new Node();
    node.id = modelNode.id;
    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;
            Material meshMaterial = null;
            if (modelNodePart.meshPartId != null) {
                for (MeshPart part : meshParts) {
                    if (modelNodePart.meshPartId.equals(part.id)) {
                        meshPart = part;
                        break;
                    }
                }
            }
            if (modelNodePart.materialId != null) {
                for (Material material : materials) {
                    if (modelNodePart.materialId.equals(material.id)) {
                        meshMaterial = material;
                        break;
                    }
                }
            }
            if (meshPart == null || meshMaterial == null)
                throw new GdxRuntimeException("Invalid node: " + node.id);
            if (meshPart != null && meshMaterial != null) {
                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.addChild(loadNode(child));
        }
    }
    return node;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ModelNode(com.badlogic.gdx.graphics.g3d.model.data.ModelNode) Node(com.badlogic.gdx.graphics.g3d.model.Node) ModelNodePart(com.badlogic.gdx.graphics.g3d.model.data.ModelNodePart) ModelMaterial(com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial) ModelMeshPart(com.badlogic.gdx.graphics.g3d.model.data.ModelMeshPart) MeshPart(com.badlogic.gdx.graphics.g3d.model.MeshPart) NodePart(com.badlogic.gdx.graphics.g3d.model.NodePart) ModelNodePart(com.badlogic.gdx.graphics.g3d.model.data.ModelNodePart) ModelNode(com.badlogic.gdx.graphics.g3d.model.data.ModelNode)

Example 5 with NodePart

use of com.badlogic.gdx.graphics.g3d.model.NodePart 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)

Aggregations

NodePart (com.badlogic.gdx.graphics.g3d.model.NodePart)6 Node (com.badlogic.gdx.graphics.g3d.model.Node)4 Model (com.badlogic.gdx.graphics.g3d.Model)3 MeshPart (com.badlogic.gdx.graphics.g3d.model.MeshPart)2 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)2 Material (com.badlogic.gdx.graphics.g3d.Material)1 Renderable (com.badlogic.gdx.graphics.g3d.Renderable)1 ModelMaterial (com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial)1 ModelMeshPart (com.badlogic.gdx.graphics.g3d.model.data.ModelMeshPart)1 ModelNode (com.badlogic.gdx.graphics.g3d.model.data.ModelNode)1 ModelNodePart (com.badlogic.gdx.graphics.g3d.model.data.ModelNodePart)1 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)1 DefaultTextureBinder (com.badlogic.gdx.graphics.g3d.utils.DefaultTextureBinder)1 MeshPartBuilder (com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder)1 RenderContext (com.badlogic.gdx.graphics.g3d.utils.RenderContext)1 Matrix4 (com.badlogic.gdx.math.Matrix4)1 Vector3 (com.badlogic.gdx.math.Vector3)1 BoundingBox (com.badlogic.gdx.math.collision.BoundingBox)1 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1 JsonReader (com.badlogic.gdx.utils.JsonReader)1