public void init() {
    cam = new PerspCam().initProjection(70, Display.getAspectRatio(), 0.01f, 100f);
    cam.setPosition(new Vector3(0, 0, 0.5f));

    sheet =
        new SpriteSheet(
            Texture.fromFilePath(FilePath.getResourceFile("resources/coin_sprinkle.png")), 32, 32);

    Sprite sprite = new Sprite();
    sprite.getAnimation().addFrame(sheet.getCell(0, 0), 0.25f, TimeUtils.Unit.SECONDS);
    sprite.getAnimation().addFrame(sheet.getCell(0, 1), 0.25f, TimeUtils.Unit.SECONDS);
    sprite.getAnimation().setEndCallback(sprite.getAnimation()::start);
    sprite.getAnimation().start();

    model = new BillBoardModel(sprite, 0.2f, 0.2f);
    model2 =
        new BillBoardModel(
            Texture.fromFilePath(FilePath.getResourceFile("resources/texture.png")), 0.8f, 0.8f);

    scene = new Scene3D();

    // Add the entity to the scene
    scene.addChild(entity = new Entity3D(model, new Cuboid(Vector3.ZERO, 1, 1, 1)));
    entity.setPosition(new Vector3(0, 0, 0.2f));
    scene.addChild(new Entity3D(model2, new Cuboid(Vector3.ZERO, 1, 1, 1)));
  }
Пример #2
0
  public void render(Batcher batcher, Transform transform) {
    Mesh m = getMeshes().get(0);
    Material originalMaterial = SilenceEngine.graphics.getCurrentMaterial();
    Texture originalTexture = Texture.CURRENT;

    SilenceEngine.graphics.useMaterial(m.getMaterial());
    m.getMaterial().getDiffuseMap().bind();

    if (transform != null) batcher.applyTransform(transform);
    batcher.begin(m.isWireFrame() ? Primitive.LINES : Primitive.TRIANGLES);
    {
      for (Mesh mesh : getMeshes()) {
        if (!m.getMaterial().equals(mesh.getMaterial())) {
          batcher.end();

          SilenceEngine.graphics.useMaterial(mesh.getMaterial());
          mesh.getMaterial().getDiffuseMap().bind();

          m = mesh;
          if (transform != null) batcher.applyTransform(transform);
          batcher.begin(m.isWireFrame() ? Primitive.LINES : Primitive.TRIANGLES);
        }

        Color color = mesh.getMaterial().getDiffuse();

        for (Face face : mesh.getFaces()) {
          batcher.vertex(mesh.getVertices().get((int) face.vertexIndex.x));
          batcher.normal(mesh.getNormals().get((int) face.normalIndex.x));
          batcher.texCoord(mesh.getTexcoords().get((int) face.texcoordIndex.x));
          if (mesh.getMaterial().getDiffuseMap().getID() == Texture.EMPTY.getID())
            batcher.color(color.x, color.y, color.z, mesh.getMaterial().getDissolve());

          batcher.vertex(mesh.getVertices().get((int) face.vertexIndex.y));
          batcher.normal(mesh.getNormals().get((int) face.normalIndex.y));
          batcher.texCoord(mesh.getTexcoords().get((int) face.texcoordIndex.y));
          if (mesh.getMaterial().getDiffuseMap().getID() == Texture.EMPTY.getID())
            batcher.color(color.x, color.y, color.z, mesh.getMaterial().getDissolve());

          batcher.vertex(mesh.getVertices().get((int) face.vertexIndex.z));
          batcher.normal(mesh.getNormals().get((int) face.normalIndex.z));
          batcher.texCoord(mesh.getTexcoords().get((int) face.texcoordIndex.z));
          if (mesh.getMaterial().getDiffuseMap().getID() == Texture.EMPTY.getID())
            batcher.color(color.x, color.y, color.z, mesh.getMaterial().getDissolve());
        }
      }
    }
    batcher.end();

    SilenceEngine.graphics.useMaterial(originalMaterial);
    originalTexture.bind();
  }