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