Ejemplo n.º 1
0
  public void construct(ModelConstructTool modelBuilder, String... partName) {
    modelBuilder.node(partName[0]);
    MeshPartBuilder meshBuilder =
        modelBuilder.part(
            "gilse",
            GL20.GL_TRIANGLES,
            Usage.Position | Usage.Normal,
            new Material(ColorAttribute.createDiffuse(Color.ORANGE)));
    Matrix4 tmGls = new Matrix4();
    tmGls.setToRotation(0f, 0f, 10f, -90f);
    meshBuilder.setVertexTransform(tmGls);
    meshBuilder.cylinder(7f, 48f, 7f, 10);

    meshBuilder =
        modelBuilder.part(
            "cone",
            GL20.GL_TRIANGLES,
            Usage.Position | Usage.Normal,
            new Material(ColorAttribute.createDiffuse(Color.ORANGE)));
    Matrix4 tmCone = new Matrix4();
    tmCone.setToRotation(0f, 0f, 10f, -90f);
    tmCone.trn(30f, 0f, 0f);
    ;
    meshBuilder.setVertexTransform(tmCone);
    meshBuilder.cone(7, 12, 7, 10);
  }
Ejemplo n.º 2
0
  public static Model getTankModel() {
    Material material = new Material(ColorAttribute.createDiffuse(Color.GREEN));
    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();

    Node node1 = modelBuilder.node();
    node1.id = "body";
    node1.translation.set(0, 1f, 0);
    MeshPartBuilder meshBuilder =
        modelBuilder.part(
            "bodyPart",
            GL20.GL_TRIANGLES,
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal,
            material);
    meshBuilder.box(10, 2, 6);

    Node node2 = modelBuilder.node();
    node2.id = "tower";
    node2.translation.set(1f, 3f, 0f);
    meshBuilder =
        modelBuilder.part(
            "towerPart",
            GL20.GL_TRIANGLES,
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal,
            material);
    meshBuilder.box(4, 2, 3);

    Node node3 = modelBuilder.node();
    node3.id = "gun";
    node3.translation.set(5f, 3f, 0f);
    node3.rotation.set(new Vector3(0, 0, 1), 90f);
    meshBuilder =
        modelBuilder.part(
            "gunPart",
            GL20.GL_TRIANGLES,
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal,
            material);
    meshBuilder.cylinder(0.5f, 5f, 0.5f, 6);

    Model model = modelBuilder.end();

    return model;
  }
Ejemplo n.º 3
0
  @Override
  public void create() {
    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
    environment.add(
        (shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f))
            .set(0.8f, 0.8f, 0.8f, -1f, -.8f, -.2f));
    environment.shadowMap = shadowLight;

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

    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();
    MeshPartBuilder mpb =
        modelBuilder.part(
            "parts",
            GL20.GL_TRIANGLES,
            Usage.Position | Usage.Normal | Usage.ColorUnpacked,
            new Material(ColorAttribute.createDiffuse(Color.WHITE)));
    mpb.setColor(1f, 1f, 1f, 1f);
    mpb.box(0, -1.5f, 0, 10, 1, 10);
    mpb.setColor(1f, 0f, 1f, 1f);
    mpb.sphere(2f, 2f, 2f, 10, 10);
    model = modelBuilder.end();
    instance = new ModelInstance(model);

    shadowBatch = new ModelBatch(new DepthShaderProvider());

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