예제 #1
0
  /**
   * Get the relative size of a prop.
   *
   * @param spatial which prop (not null)
   * @return the prop's size relative to standard (>0)
   */
  public float getRelativeSize(Spatial spatial) {
    assert spatial != null;

    float result = spatial.getWorldScale().x;
    result *= scene.getScaleFactor();
    return result;
  }
예제 #2
0
  /**
   * Generate a collision shape for a prop.
   *
   * @param propType the type of the prop (not null)
   * @param relativeSize the prop's size relative to standard (>0)
   * @param parts (not null)
   * @return a new instance
   */
  private CollisionShape createShape(String propType, float relativeSize, List<Spatial> parts) {
    assert propType != null;
    assert relativeSize > 0f : relativeSize;
    assert parts != null;
    assert !parts.isEmpty();

    if ("barrel".equals(propType)) {
      /*
       * Generate a cylindrical shape aligned with the Y-axis.
       */
      float halfHeight = 0.5f * relativeSize; // meters
      float radius = 0.472f * relativeSize; // meters
      Vector3f halfExtents = new Vector3f(radius, halfHeight, radius);
      float scaleFactor = scene.getScaleFactor();
      halfExtents.divideLocal(scaleFactor);
      CollisionShape shape = new CylinderCollisionShape(halfExtents, PhysicsSpace.AXIS_Y);
      return shape;
    }
    /*
     * Generate a compound shape composed of GImpact shapes,
     * one for each geometry.
     */
    CompoundCollisionShape shape = new CompoundCollisionShape();
    for (Spatial part : parts) {
      Geometry geometry = (Geometry) part;
      Mesh mesh = geometry.getMesh();
      CollisionShape partShape = new GImpactCollisionShape(mesh);
      Vector3f scale = part.getWorldScale();
      partShape.setScale(scale);
      shape.addChildShape(partShape, Vector3f.ZERO);
    }
    return shape;
  }
예제 #3
0
  /**
   * Duplicate a prop. Duplicating differs from cloning because the duplicate gets a unique name and
   * any descendants of the duplicate get renamed to match. Besides, cloning doesn't work well on
   * physics controls.
   *
   * @param originalProp which prop to duplicate (not null)
   * @return the new prop
   */
  public Node duplicate(Spatial originalProp) {
    String name = originalProp.getName();
    logger.log(Level.INFO, "duplicating prop {0}", MyString.quote(name));

    String propType = SpatialProperties.getPrefixType(originalProp);
    float relativeSize = originalProp.getWorldScale().x;
    Vector3f centerLocation = MySpatial.getWorldLocation(originalProp);
    Quaternion orientation = MySpatial.getWorldOrientation(originalProp);

    Node result = add(propType, relativeSize, centerLocation, orientation);
    return result;
  }