Example #1
0
  @Deprecated
  public static Model createFromMesh(
      final Mesh mesh,
      int indexOffset,
      int vertexCount,
      int primitiveType,
      final Material material) {
    Model result = new Model();
    MeshPart meshPart = new MeshPart();
    meshPart.id = "part1";
    meshPart.indexOffset = indexOffset;
    meshPart.numVertices = vertexCount;
    meshPart.primitiveType = primitiveType;
    meshPart.mesh = mesh;

    NodePart partMaterial = new NodePart();
    partMaterial.material = material;
    partMaterial.meshPart = meshPart;
    Node node = new Node();
    node.id = "node1";
    node.parts.add(partMaterial);

    result.meshes.add(mesh);
    result.materials.add(material);
    result.nodes.add(node);
    result.meshParts.add(meshPart);
    result.manageDisposable(mesh);
    return result;
  }
Example #2
0
  @Override
  public void create() {
    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(2f, 2f, 2f);
    cam.lookAt(0, 0, 0);
    cam.near = 1f;
    cam.far = 300f;
    cam.update();

    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);

    ModelLoader modelLoader = new G3dModelLoader(new JsonReader());
    ModelData modelData =
        modelLoader.loadModelData(Gdx.files.internal(data + "/invaderscene.g3dj"));
    model = new Model(modelData, new TextureProvider.FileTextureProvider());

    NodePart blockPart = model.getNode("ship").parts.get(0);

    renderable = new Renderable();
    renderable.mesh = blockPart.meshPart.mesh;
    renderable.meshPartOffset = blockPart.meshPart.indexOffset;
    renderable.meshPartSize = blockPart.meshPart.numVertices;
    renderable.primitiveType = blockPart.meshPart.primitiveType;
    renderable.material = blockPart.material;
    renderable.environment = environment;
    renderable.worldTransform.idt();
  }
Example #3
0
  public Wheel(GameManager base, Vector3 location, String type) {
    this.base = base;

    // If there is no wheel constructor, set it up
    if (this.base.world.getConstructor("wheel" + type) == null) {
      modelLoader = new G3dModelLoader(new JsonReader());
      if (type == "bigtruck")
        wheelData =
            modelLoader.loadModelData(
                Gdx.files.internal("data/vehicles/wheels/bigtruckwheel.g3dj"));
      else
        wheelData =
            modelLoader.loadModelData(Gdx.files.internal("data/vehicles/wheels/policewheel.g3dj"));
      wheelModel = new Model(wheelData, new TextureProvider.FileTextureProvider());
      wheelHalfExtents =
          wheelModel.calculateBoundingBox(new BoundingBox()).getDimensions(new Vector3()).scl(0.5f);

      this.base.world.addConstructor("wheel" + type, new BulletConstructor(wheelModel, 0f, null));
      this.base.disposables.add(wheelModel);

      wheel = this.base.world.add("wheel" + type, location.x, location.y, location.z);
    } else {
      wheel = this.base.world.add("wheel" + type, location.x, location.y, location.z);
      wheelHalfExtents =
          wheel
              .modelInstance
              .model
              .calculateBoundingBox(new BoundingBox())
              .getDimensions(new Vector3())
              .scl(0.5f);
    }
  }
Example #4
0
 /**
  * Adds the nodes of the specified model to a new node 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.children.addAll(model.nodes);
   node(node);
   for (final Disposable disposable : model.getManagedDisposables()) manage(disposable);
   return node;
 }
Example #5
0
 public void endNoChildren() {
   onEnd();
   parent(null);
   valid = false;
   if (uniqueModel != null) uniqueModel.dispose();
   scene.remove(this);
   for (GameObject g : touchingObjects) g.activate();
 }
Example #6
0
 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.children) rebuildReferences(model, child);
 }
Example #7
0
  @Override
  public void dispose() {
    groundObject.dispose();
    groundShape.dispose();

    ballObject.dispose();
    ballShape.dispose();

    dispatcher.dispose();
    collisionConfig.dispose();

    modelBatch.dispose();
    model.dispose();
  }
Example #8
0
 @Override
 public void dispose() {
   modelBatch.dispose();
   model.dispose();
 }
Example #9
0
 /** Уничтожить модель частицы. */
 public void dispose() {
   model.dispose();
 }
Example #10
0
 /**
  * Add the {@link Disposable} object to the model, causing it to be disposed when the model is
  * disposed.
  */
 public void manage(final Disposable disposable) {
   if (model == null) throw new GdxRuntimeException("Call begin() first");
   model.manageDisposable(disposable);
 }
Example #11
0
 @Override
 public void dispose() {
   modelBatch.dispose();
   instances.clear();
   model.dispose();
 }
Example #12
0
 /** Creates a btBoxShape with the same dimensions as the shape. */
 public BulletConstructor(final Model model, final float mass) {
   final BoundingBox boundingBox = new BoundingBox();
   model.calculateBoundingBox(boundingBox);
   create(model, mass, boundingBox.getWidth(), boundingBox.getHeight(), boundingBox.getDepth());
 }