Example #1
0
  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;
        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.children.add(loadNode(node, child));
      }
    }

    return node;
  }
Example #2
0
  private Node loadNode(Node parent, ModelNode modelNode) {
    Node node = new Node();
    node.id = modelNode.id;
    // node.boneId = modelNode.boneId; // FIXME check meaning of this, breadth first index of node
    // hierarchy?
    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;
        Material meshMaterial = null;
        if (modelNodePart.meshPartId != null) {
          for (MeshPart part : meshParts) {
            // FIXME need to make sure this is unique by adding mesh id to mesh part id!
            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;
            }
          }
        }

        // FIXME what if meshPart is set but meshMaterial isn't and vice versa?
        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.children.add(loadNode(node, child));
      }
    }

    return node;
  }