Пример #1
0
  public void create() {

    lightManager = new LightManager(LIGHTS_NUM, LightQuality.FRAGMENT);
    for (int i = 0; i < LIGHTS_NUM; i++) {
      PointLight l = new PointLight();
      l.position.set(MathUtils.random(8) - 4, MathUtils.random(6), MathUtils.random(8) - 4);
      l.color.r = MathUtils.random();
      l.color.b = MathUtils.random();
      l.color.g = MathUtils.random();
      l.intensity = 1 + MathUtils.random() * LIGHT_INTESITY;
      lightManager.addLigth(l);
    }
    lightManager.dirLight = new DirectionalLight();
    lightManager.dirLight.color.set(0.15f, 0.15f, 0.15f, 1);
    lightManager.dirLight.direction.set(-.4f, -1, 0.03f).nor();

    lightManager.ambientLight.set(.1f, 0.09f, 0.09f, 0f);

    cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.near = 0.1f;
    cam.far = 264f;
    cam.position.set(0, 0.5f, -2f);
    cam.update();

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

    texture = new Texture(Gdx.files.internal("data/multipleuvs_1.png"), Format.RGB565, true);
    texture.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Linear);
    texture2 = new Texture(Gdx.files.internal("data/texture2UV1N.png"), Format.RGB565, true);
    texture2.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Linear);

    model = ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/models/sphere.obj"));
    model2 = ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/models/basicscene.obj"));

    instance = new StillModelNode();
    instance.getTransform().translate(2, 0, -5);
    instance2 = new StillModelNode();

    BoundingBox box = new BoundingBox();
    model.getBoundingBox(box);
    instance.radius = box.getDimensions().len() / 2;

    model2.getBoundingBox(box);
    instance2.radius = box.getDimensions().len() / 2;

    protoRenderer = new PrototypeRendererGL20(lightManager);
    protoRenderer.cam = cam;

    MaterialAttribute c1 =
        new ColorAttribute(new Color(0.75f, 0.75f, 0.75f, 0.6f), ColorAttribute.diffuse);
    MaterialAttribute c2 =
        new ColorAttribute(new Color(0.35f, 0.35f, 0.35f, 0.35f), ColorAttribute.specular);
    MaterialAttribute t1 = new TextureAttribute(texture, 0, TextureAttribute.diffuseTexture);
    MaterialAttribute t2 = new TextureAttribute(texture2, 1, TextureAttribute.specularTexture);

    // MaterialAttribute b = new BlendingAttribute(BlendingAttribute.translucent);

    Material material2 = new Material("basic", c2, t1, t2);
    model2.setMaterial(material2);

    Material material = new Material("shiningBall", c1, c2);
    model.setMaterial(material);

    model3 = ModelLoaderRegistry.loadKeyframedModel(Gdx.files.internal("data/models/knight.md2"));
    animInstance = new AnimatedModelNode();
    animInstance.animation = model3.getAnimations()[0].name;
    animInstance.looping = true;
    model3.getBoundingBox(box);

    animInstance.matrix.trn(-1.75f, 0f, -5.5f);
    animInstance.matrix.scale(0.05f, 0.05f, 0.05f);
    box.mul(animInstance.matrix);
    animInstance.radius = (box.getDimensions().len() / 2);
    texture3 = new Texture(Gdx.files.internal("data/models/knight.jpg"), Format.RGB565, true);
    texture3.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Linear);

    MaterialAttribute t3 = new TextureAttribute(texture3, 0, TextureAttribute.diffuseTexture);
    Material material3 = new Material("", c2, t3, t2);
    model3.setMaterial(material3);
  }