Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mygdx.game;
- import com.badlogic.gdx.ApplicationAdapter;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.Input;
- import com.badlogic.gdx.assets.AssetManager;
- import com.badlogic.gdx.assets.loaders.ModelLoader;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.PerspectiveCamera;
- import com.badlogic.gdx.graphics.Pixmap;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.VertexAttributes;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.graphics.g3d.Environment;
- import com.badlogic.gdx.graphics.g3d.Material;
- import com.badlogic.gdx.graphics.g3d.Model;
- import com.badlogic.gdx.graphics.g3d.ModelBatch;
- import com.badlogic.gdx.graphics.g3d.ModelInstance;
- import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
- import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute;
- import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
- import com.badlogic.gdx.graphics.g3d.loader.ObjLoader;
- import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
- import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
- import com.badlogic.gdx.math.Vector3;
- import com.badlogic.gdx.math.collision.Sphere;
- import com.badlogic.gdx.utils.Array;
- import java.io.File;
- import sun.rmi.runtime.Log;
- public class MyGdxGame extends ApplicationAdapter {
- public PerspectiveCamera cam;
- public CameraInputController camController;
- public ModelBatch modelBatch;
- public AssetManager assets;
- public Array<ModelInstance> instances = new Array<ModelInstance>();
- public Environment environment;
- public boolean loading;
- public ModelInstance maleBodyInstance;
- public Model maleBodyModel;
- public Model pantModel;
- public Material material;
- public TextureAttribute textureAttribute1;
- public Texture blueTexture;
- public Texture greenTexture;
- public Texture redTexture;
- long startTime = System.nanoTime();
- int frames = 0;
- public boolean lol = true;
- @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(7f, 7f, 7f);
- cam.lookAt(0,0,0);
- cam.near = 0.1f;
- cam.far = 300f;
- cam.update();
- camController = new CameraInputController(cam);
- Gdx.input.setInputProcessor(camController);
- greenTexture = new Texture(Gdx.files.internal("twok.jpg"));
- redTexture = new Texture(Gdx.files.internal("twok_empty.png"));
- assets = new AssetManager();
- assets.load("lol2.obj", Model.class);
- loading = true;
- }
- private void doneLoading() {
- if(maleBodyModel == null)
- {
- maleBodyModel = assets.get("lol2.obj", Model.class);
- maleBodyInstance = new ModelInstance(maleBodyModel);
- maleBodyInstance.transform.setToTranslation(1, 0, 1);
- maleBodyInstance.transform.setToRotation(0, 1, 0, 45);
- }
- if(lol)
- {
- textureAttribute1 = new TextureAttribute(TextureAttribute.Diffuse, greenTexture);
- lol = false;
- }else
- {
- textureAttribute1 = new TextureAttribute(TextureAttribute.Diffuse, redTexture);
- lol = true;
- }
- material = maleBodyInstance.materials.get(0);
- material.set(textureAttribute1);
- instances.clear();
- instances.add(maleBodyInstance);
- //loading = false;
- }
- @Override
- public void render () {
- if (assets.update())
- doneLoading();
- camController.update();
- Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
- modelBatch.begin(cam);
- modelBatch.render(instances, environment);
- modelBatch.end();
- }
- @Override
- public void dispose () {
- modelBatch.dispose();
- instances.clear();
- assets.dispose();
- }
- @Override
- public void resize(int width, int height) {
- }
- @Override
- public void pause() {
- }
- @Override
- public void resume() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement