Exemplo n.º 1
0
  private void addGeometry(
      GLRenderer renderer,
      Geometry geometry,
      Color color,
      double x,
      double y,
      double z,
      double rx,
      double ry,
      double rz,
      double s) {
    // 3d shape
    List<Material> materials = new ArrayList<Material>();
    materials.add(new MeshLambertMaterial().setColor(color).setOpacity(0.2).setTransparent(true));
    materials.add(new MeshBasicMaterial().setColor(0x000000).setWireframe(true).setOpacity(0.3));
    Object3D mesh = SceneUtils.createMultiMaterialObject(geometry, materials);

    mesh.getPosition().set(x, y, z - 75.0);

    mesh.getScale().set(s);

    //			if (geometry.debug)
    //				mesh.add(geometry.debug);

    this.parentObject.add(mesh);
    renderer.render(scene, camera);
  }
Exemplo n.º 2
0
  public Box3 setFromObject(Object3D object) {

    // Computes the world-axis-aligned bounding box of an object (including its children),
    // accounting for both the object's, and childrens', world transforms

    object.updateMatrixWorld(true);

    this.makeEmpty();

    object.traverse(
        new Object3D.Traverse() {

          @Override
          public void callback(Object3D node) {

            AbstractGeometry geometry = ((GeometryObject) node).getGeometry();

            Vector3 v1 = new Vector3();

            if (geometry != null) {

              if (geometry instanceof Geometry) {

                List<Vector3> vertices = ((Geometry) geometry).getVertices();

                for (int i = 0, il = vertices.size(); i < il; i++) {

                  v1.copy(vertices.get(i));

                  v1.apply(node.getMatrixWorld());

                  expandByPoint(v1);
                }

              } else if (geometry instanceof BufferGeometry
                  && ((BufferGeometry) geometry).getAttribute("position") != null) {

                Float32Array positions =
                    (Float32Array) ((BufferGeometry) geometry).getAttribute("position").getArray();

                for (int i = 0, il = positions.getLength(); i < il; i += 3) {

                  v1.set(positions.get(i), positions.get(i + 1), positions.get(i + 2));

                  v1.apply(node.getMatrixWorld());

                  expandByPoint(v1);
                }
              }
            }
          }
        });

    return this;
  }