com.badlogic.gdx.graphics.g3d.ModelBatch Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g3d.ModelBatch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Renderer.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
public Renderer () {
	try {
		lights = new Environment();
		lights.add(new DirectionalLight().set(Color.WHITE, new Vector3(-1, -0.5f, 0).nor()));

		spriteBatch = new SpriteBatch();
		modelBatch = new ModelBatch();

		backgroundTexture = new Texture(Gdx.files.internal("data/planet.jpg"), Format.RGB565, true);
		backgroundTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);

		font = new BitmapFont(Gdx.files.internal("data/font10.fnt"), Gdx.files.internal("data/font10.png"), false);

		camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
Example #2
Source File: ScaleTool.java    From Mundus with Apache License 2.0 6 votes vote down vote up
public ScaleTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker,
        ShapeRenderer shapeRenderer, ModelBatch batch, CommandHistory history) {
    super(projectManager, goPicker, handlePicker, batch, history);

    this.shapeRenderer = shapeRenderer;

    ModelBuilder modelBuilder = new ModelBuilder();
    Model xPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_X)),
            Vector3.Zero, new Vector3(15, 0, 0));
    Model yPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_Y)),
            Vector3.Zero, new Vector3(0, 15, 0));
    Model zPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_Z)),
            Vector3.Zero, new Vector3(0, 0, 15));
    Model xyzPlaneHandleModel = modelBuilder.createBox(3, 3, 3,
            new Material(ColorAttribute.createDiffuse(COLOR_XYZ)),
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);

    xHandle = new ScaleHandle(X_HANDLE_ID, xPlaneHandleModel);
    yHandle = new ScaleHandle(Y_HANDLE_ID, yPlaneHandleModel);
    zHandle = new ScaleHandle(Z_HANDLE_ID, zPlaneHandleModel);
    xyzHandle = new ScaleHandle(XYZ_HANDLE_ID, xyzPlaneHandleModel);

    handles = new ScaleHandle[] { xHandle, yHandle, zHandle, xyzHandle };
}
 
Example #3
Source File: Stage3d.java    From Scene3d with Apache License 2.0 6 votes vote down vote up
public Stage3d (float width, float height, boolean keepAspectRatio) {
	this.width = width;
	this.height = height;

	root = new Group3d();
	root.setStage3d(this);

	modelBatch = new ModelBatch();

	camera =  new Camera3d();
	environment = new Environment();
	environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.9f, 0.9f, 0.9f, 1f));
	environment.add(new DirectionalLight().set(0.8f, 0f, 0f, -1f, -0.8f, -0.2f));

	setViewport(width, height, keepAspectRatio);
}
 
Example #4
Source File: ToolManager.java    From Mundus with Apache License 2.0 6 votes vote down vote up
public ToolManager(InputManager inputManager, ProjectManager projectManager, GameObjectPicker goPicker,
        ToolHandlePicker toolHandlePicker, ModelBatch modelBatch, ShapeRenderer shapeRenderer,
        CommandHistory history) {
    this.inputManager = inputManager;
    this.activeTool = null;

    terrainBrushes = new Array<>();
    terrainBrushes.add(new SmoothCircleBrush(projectManager, modelBatch, history));
    terrainBrushes.add(new CircleBrush(projectManager, modelBatch, history));
    terrainBrushes.add(new StarBrush(projectManager, modelBatch, history));
    terrainBrushes.add(new ConfettiBrush(projectManager, modelBatch, history));

    modelPlacementTool = new ModelPlacementTool(projectManager, modelBatch, history);
    selectionTool = new SelectionTool(projectManager, goPicker, modelBatch, history);
    translateTool = new TranslateTool(projectManager, goPicker, toolHandlePicker, modelBatch, history);
    rotateTool = new RotateTool(projectManager, goPicker, toolHandlePicker, shapeRenderer, modelBatch, history);
    scaleTool = new ScaleTool(projectManager, goPicker, toolHandlePicker, shapeRenderer, modelBatch, history);
}
 
Example #5
Source File: GameRenderer.java    From GdxDemo3D with Apache License 2.0 6 votes vote down vote up
public GameRenderer(Viewport viewport, Camera camera, GameEngine engine) {
	this.viewport = viewport;
	this.camera = camera;
	this.engine = engine;

	shapeRenderer = new MyShapeRenderer();
	shapeRenderer.setAutoShapeType(true);

	spriteBatch = new SpriteBatch();
	font = new BitmapFont();
	font.setColor(Color.WHITE);
	font.setUseIntegerPositions(false);
	font.getData().setScale(0.01f);
	shadowBatch = new ModelBatch(new DepthShaderProvider());

	ShaderProgram.pedantic = false;
	final String vertUber = Gdx.files.internal("shaders/uber.vert").readString();
	final String fragUber = Gdx.files.internal("shaders/uber.frag").readString();
	modelBatch = new ModelBatch(new DefaultShaderProvider(vertUber, fragUber) {
		@Override
		protected Shader createShader(final Renderable renderable) {
			return new UberShader(renderable, config);
		}
	});
}
 
Example #6
Source File: LibgdxUtils.java    From libgdx-utils with MIT License 6 votes vote down vote up
@Override
public void create() {
	try {
		logger.setLevel(Logger.DEBUG);
		Gdx.app.setLogLevel(Application.LOG_DEBUG);

		Texture.setAssetManager(assets);

		spriteBatch = new SpriteBatch();
		modelBatch = new ModelBatch();

		game.create();
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		Gdx.app.exit();
	}
}
 
Example #7
Source File: SimpleRoom.java    From gdx-vr with Apache License 2.0 6 votes vote down vote up
@Override
public void create() {
	assets = new AssetManager();
	String model = "Bambo_House.g3db";
	assets.load(model, Model.class);
	assets.finishLoading();
	modelInstance = new ModelInstance(assets.get(model, Model.class), new Matrix4().setToScaling(0.6f, 0.6f, 0.6f));

	DefaultShader.Config config = new Config();
	config.defaultCullFace = GL20.GL_NONE;
	ShaderProvider shaderProvider = new DefaultShaderProvider(config);
	modelBatch = new ModelBatch(shaderProvider);

	ModelBuilder builder = new ModelBuilder();
	float groundSize = 1000f;
	ground = new ModelInstance(builder.createRect(-groundSize, 0, groundSize, groundSize, 0, groundSize, groundSize, 0, -groundSize, -groundSize, 0, -groundSize, 0,
			1, 0, new Material(), Usage.Position | Usage.Normal), new Matrix4().setToTranslation(0, -0.01f, 0));
	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));

	VirtualReality.renderer.listeners.add(this);
	// VirtualReality.head.setCyclops(true);
}
 
Example #8
Source File: Renderer.java    From VuforiaLibGDX with MIT License 6 votes vote down vote up
public Renderer() {

        lights = new Environment();
        lights.set(new ColorAttribute(ColorAttribute.AmbientLight, Color.WHITE));

        camera = new PerspectiveCamera(60, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        camera.near = 1.0F;
        camera.far = 1000.0F;
        //set camera into "Vuforia - style" direction
        camera.position.set(new Vector3(0,0,0));
        camera.lookAt(new Vector3(0,0,1));

        IntBuffer buffer = BufferUtils.newIntBuffer(16);
        Gdx.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_IMAGE_UNITS, buffer);
        int units = buffer.get(0);
        Log.d("TAG", "Max texture units: "+units);
        modelBatch = new ModelBatch(new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 0)));
    }
 
Example #9
Source File: MenuScene.java    From Skyland with MIT License 5 votes vote down vote up
private void init3d() {
    camera = WorldGenerator.generatePerspectiveCamera(1, 150, new Vector3(-8, 6, 15), new Vector3(0, -2, 0));
    batch = new ModelBatch();

    particleUtils = new ParticleUtils();
    particleUtils.initBillBoardParticles(camera);

    world = WorldGenerator.generateBaseWorld(false, false);
    cloudGenerator = new CloudGenerator(world, 40);
    environment = WorldGenerator.generateBaseEnvironment(new Vector3(8, 14, 6));
    island = WorldGenerator.createKinematicIsland(world, new Vector3(8, 1, 0), false);
    WorldHover.reinit();
}
 
Example #10
Source File: GameScene.java    From Skyland with MIT License 5 votes vote down vote up
private void initWorld() {
    camera = WorldGenerator.generatePerspectiveCamera(1, 150, new Vector3(-8, 10, 15), new Vector3(0, 2, 0));
    batch = new ModelBatch();

    particleUtils = new ParticleUtils();
    particleUtils.initBillBoardParticles(camera);

    //adding generators
    world = WorldGenerator.generateBaseWorld(false, false);
    cloudGenerator = new CloudGenerator(world, 30);
    environment = WorldGenerator.generateBaseEnvironment(new Vector3(-6, 14, 6));
    WorldGenerator.createKinematicIsland(world, new Vector3(0, 0, 0), true);

    WorldHover.reinit();
}
 
Example #11
Source File: SunRenderer.java    From Cubes with MIT License 5 votes vote down vote up
public static void draw(ModelBatch modelBatch) {
  if (SUN == null) SUN = new SunRenderer(false);
  SUN.render(modelBatch);

  if (MOON == null) MOON = new SunRenderer(true);
  MOON.render(modelBatch);
}
 
Example #12
Source File: SceneManager.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public SceneManager(ShaderProvider shaderProvider, DepthShaderProvider depthShaderProvider, RenderableSorter renderableSorter)
{
	this.renderableSorter = renderableSorter;
	
	batch = new ModelBatch(shaderProvider, renderableSorter);
	
	depthBatch = new ModelBatch(depthShaderProvider);
	
	float lum = 1f;
	environment.set(new ColorAttribute(ColorAttribute.AmbientLight, lum, lum, lum, 1));
}
 
Example #13
Source File: CubesModelBatch.java    From Cubes with MIT License 5 votes vote down vote up
public CubesModelBatch() {
  super(new CubesShaderProvider(), new CubesRenderableSorter());

  try {
    Field field = ModelBatch.class.getDeclaredField("renderablesPool");
    field.setAccessible(true);
    field.set(this, new CubesRenderablePool());
    field.setAccessible(false);
    if (!(renderablesPool instanceof CubesRenderablePool)) throw new CubesException("Not instance of CubesRenderablePool");
  } catch (Exception e) {
    Debug.crash(new CubesException("Failed to setup CubesRenderablePool", e));
  }
}
 
Example #14
Source File: TerrainBrush.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public TerrainBrush(ProjectManager projectManager, ModelBatch batch, CommandHistory history,
        FileHandle pixmapBrush) {
    super(projectManager, batch, history);

    brushPixmap = new Pixmap(pixmapBrush);
    pixmapCenter = brushPixmap.getWidth() / 2;
}
 
Example #15
Source File: Sprite3DRenderer.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public static void createBatchs() {
	Config modelConfigShader = new Config(Gdx.files.classpath(VERTEX_SHADER).readString(),
			Gdx.files.classpath(FRAGMENT_SHADER).readString());

	modelConfigShader.numBones = MAX_BONES;
	modelConfigShader.numDirectionalLights = 0;
	modelConfigShader.numPointLights = 0;
	modelConfigShader.numSpotLights = 0;

	modelBatch = new ModelBatch(new DefaultShaderProvider(modelConfigShader));

	shadowBatch = new ModelBatch(new DepthShaderProvider());
	floorBatch = new ModelBatch(new DefaultShaderProvider(Gdx.files.classpath(VERTEX_SHADER),
			Gdx.files.classpath(FLOOR_FRAGMENT_SHADER)));
}
 
Example #16
Source File: FluidSimulatorGeneric.java    From fluid-simulator-v2 with Apache License 2.0 5 votes vote down vote up
public FluidSimulatorGeneric(FluidSimulatorStarter fluidSimulatorStarter) {
		this.game = fluidSimulatorStarter;
		// LibGDX single batches cannot have a size more than 5460
		batch = new SpriteBatch(IS_DESKTOP ? 5460 : ANDROID_SIZE);
		font = new BitmapFont();
		camera = new OrthographicCamera(WORLD_WIDTH, WORLD_HEIGHT);
		camera.position.set(0, (WORLD_HEIGHT / 2) - 1, 0);
		immediateRenderer = new ImmediateModeRenderer20(SIZE*6, false, true, 0);
		irt = new Renderer20(SIZE*6, false, true, 1);
		irt2 = new ImmediateModeRenderer20(SIZE*11, false, true, 1);
		shapeRenderer = new ShapeRenderer(SIZE);
		renderer = new Box2DDebugRenderer(true, true, false, true, false, false);
		
		//3D
		camera3D = new PerspectiveCamera(67, WORLD_WIDTH, WORLD_HEIGHT);
		camera3D.position.set(0, 130f, 250f);
		camera3D.lookAt(0,150f,0);
		camera3D.near = 0.1f;
		camera3D.far = 500f;
		camera3D.update();
		ModelBuilder modelBuilder = new ModelBuilder();
//        model = modelBuilder.createSphere(5f, 5f, 5f, 4, 4, GL10.GL_TRIANGLES,
//                new Material(ColorAttribute.createDiffuse(Color.GREEN)),
//                Usage.Position | Usage.Normal);
        model = modelBuilder.createBox(5f, 5f, 5f,
            new Material(ColorAttribute.createDiffuse(Color.GREEN)),
            Usage.Position | Usage.Normal);
        instance = new ModelInstance(model);
        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, 0, -0.8f, -0.2f));
        camController = new Camera3DController(camera3D);
        camController.setFluidSimulator(this);
		
		world = new World(new Vector2(0, -9.8f), false);
		world.setContactListener(this);
	}
 
Example #17
Source File: TransformTool.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public TransformTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker,
        ModelBatch batch, CommandHistory history) {
    super(projectManager, goPicker, batch, history);
    this.handlePicker = handlePicker;

    gameObjectModifiedEvent = new GameObjectModifiedEvent(null);
}
 
Example #18
Source File: Stage3d.java    From Scene3d with Apache License 2.0 5 votes vote down vote up
public Stage3d (float width, float height, PerspectiveCamera camera, Environment environment) {
	this.width = width;
	this.height = height;
	root = new Group3d();
	root.setStage3d(this);
	modelBatch = new ModelBatch();
	this.camera = camera;
	this.environment = environment;
}
 
Example #19
Source File: RotateTool.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public RotateTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker,
        ShapeRenderer shapeRenderer, ModelBatch batch, CommandHistory history) {
    super(projectManager, goPicker, handlePicker, batch, history);
    this.shapeRenderer = shapeRenderer;
    xHandle = new RotateHandle(X_HANDLE_ID, COLOR_X);
    yHandle = new RotateHandle(Y_HANDLE_ID, COLOR_Y);
    zHandle = new RotateHandle(Z_HANDLE_ID, COLOR_Z);
    handles = new RotateHandle[] { xHandle, yHandle, zHandle };
}
 
Example #20
Source File: Stage3d.java    From Scene3d with Apache License 2.0 5 votes vote down vote up
public Stage3d (float width, float height, PerspectiveCamera camera) {
	this.width = width;
	this.height = height;
	root = new Group3d();
	root.setStage3d(this);
	modelBatch = new ModelBatch();
	this.camera = camera;
}
 
Example #21
Source File: ToolHandlePicker.java    From Mundus with Apache License 2.0 5 votes vote down vote up
private void renderPickableScene(ToolHandle[] handles, ModelBatch batch, PerspectiveCamera cam) {
    batch.begin(cam);
    for (ToolHandle handle : handles) {
        handle.renderPick(batch);
    }
    batch.end();
}
 
Example #22
Source File: TerrainChunk.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
public void render(ModelBatch batch, Environment env) {
	batch.render(modelInstance, env);
	
	for (ModelInstance m : sceneObjects) {
		batch.render(m, env);
	}
}
 
Example #23
Source File: Entity.java    From Radix with MIT License 5 votes vote down vote up
public void render(ModelBatch batch) {
    if (model != null) {
        // TODO: support subtle action. need to create instance every time?
        ModelInstance instance = new ModelInstance(model);
        instance.materials.get(0).set(TextureAttribute.createDiffuse(texture));
        instance.transform.translate(position.getX(), position.getY(), position.getZ());
        batch.render(instance);
    }
}
 
Example #24
Source File: BulletWorld.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@Override
public void render (ModelBatch batch, Environment lights, Iterable<BulletEntity> entities) {
	if (renderMeshes) super.render(batch, lights, entities);
	if (debugDrawer != null && debugDrawer.getDebugMode() > 0) {
		batch.flush();
		debugDrawer.begin(batch.getCamera());
		collisionWorld.debugDrawWorld();
		debugDrawer.end();
	}
}
 
Example #25
Source File: TranslateTool.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public TranslateTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker,
        ModelBatch batch, CommandHistory history) {

    super(projectManager, goPicker, handlePicker, batch, history);

    ModelBuilder modelBuilder = new ModelBuilder();

    Model xHandleModel = modelBuilder.createArrow(0, 0, 0, 1, 0, 0, ARROW_CAP_SIZE, ARROW_THIKNESS, ARROW_DIVISIONS,
            GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(COLOR_X)),
            VertexAttributes.Usage.Position);
    Model yHandleModel = modelBuilder.createArrow(0, 0, 0, 0, 1, 0, ARROW_CAP_SIZE, ARROW_THIKNESS, ARROW_DIVISIONS,
            GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(COLOR_Y)),
            VertexAttributes.Usage.Position);
    Model zHandleModel = modelBuilder.createArrow(0, 0, 0, 0, 0, 1, ARROW_CAP_SIZE, ARROW_THIKNESS, ARROW_DIVISIONS,
            GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(COLOR_Z)),
            VertexAttributes.Usage.Position);
    Model xzPlaneHandleModel = modelBuilder.createSphere(1, 1, 1, 20, 20,
            new Material(ColorAttribute.createDiffuse(COLOR_XZ)), VertexAttributes.Usage.Position);

    xHandle = new TranslateHandle(X_HANDLE_ID, xHandleModel);
    yHandle = new TranslateHandle(Y_HANDLE_ID, yHandleModel);
    zHandle = new TranslateHandle(Z_HANDLE_ID, zHandleModel);
    xzPlaneHandle = new TranslateHandle(XZ_HANDLE_ID, xzPlaneHandleModel);
    handles = new TranslateHandle[] { xHandle, yHandle, zHandle, xzPlaneHandle };

    gameObjectModifiedEvent = new GameObjectModifiedEvent(null);
}
 
Example #26
Source File: GameRenderer.java    From Radix with MIT License 5 votes vote down vote up
@Override
public void init() {
    initted = true;

    frustum = game.getCamera().frustum;

    debugTextRenderer = new BitmapFont();
    fpsRender = debugTextRenderer.newFontCache();
    awrtRender = debugTextRenderer.newFontCache();
    glInfoRender = debugTextRenderer.newFontCache();
    positionRender = debugTextRenderer.newFontCache();
    headingRender = debugTextRenderer.newFontCache();
    chunkposRender = debugTextRenderer.newFontCache();
    lightlevelRender = debugTextRenderer.newFontCache();
    activeThreadsRender = debugTextRenderer.newFontCache();
    selectedBlockRender = debugTextRenderer.newFontCache();
    glDebugRender = debugTextRenderer.newFontCache();

    blockOverlayBatch = new ModelBatch(Gdx.files.internal("shaders/gdx/world.vert.glsl"),
            Gdx.files.internal("shaders/gdx/world.frag.glsl"));
    entityBatch = new ModelBatch(Gdx.files.internal("shaders/gdx/world.vert.glsl"),
            Gdx.files.internal("shaders/gdx/world.frag.glsl"));
    String destroyStageFmt = "textures/block/overlay/destroy_stage_%d.png";
    for (int stage = 0; stage < 10; stage++) {
        blockBreakStages[stage] = new Texture(Gdx.files.internal(String.format(destroyStageFmt, stage)));
    }
}
 
Example #27
Source File: SmoothCircleBrush.java    From Mundus with Apache License 2.0 4 votes vote down vote up
public SmoothCircleBrush(ProjectManager projectManager, ModelBatch batch, CommandHistory history) {
    super(projectManager, batch, history, Gdx.files.internal("brushes/circle_smooth.png"));
}
 
Example #28
Source File: BaseWorld.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
public void render (final ModelBatch batch, final Environment lights, final T entity) {
	batch.render(entity.modelInstance, lights);
}
 
Example #29
Source File: BaseWorld.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
public void render (final ModelBatch batch, final Environment lights, final Iterable<T> entities) {
	for (final T e : entities) {
		batch.render(e.modelInstance, lights);
	}
}
 
Example #30
Source File: BaseWorld.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
public void render (final ModelBatch batch, final Environment lights) {
	render(batch, lights, entities);
}