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);
}
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;
}
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);
}
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);
}
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();
}
Aggregations