com.badlogic.gdx.graphics.g3d.utils.ModelBuilder Java Examples
The following examples show how to use
com.badlogic.gdx.graphics.g3d.utils.ModelBuilder.
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: ExportSharedIndexBufferTest.java From gdx-gltf with Apache License 2.0 | 6 votes |
@Override public void create() { Material material = new Material(); ModelBuilder mb = new ModelBuilder(); MeshPartBuilder mpb; mb.begin(); mpb = mb.part("part1", GL20.GL_TRIANGLES, Usage.Position, material); BoxShapeBuilder.build(mpb, 1, 1, 1); mpb = mb.part("part2", GL20.GL_TRIANGLES, Usage.Position, material); mpb.setVertexTransform(new Matrix4().setToTranslation(2, 0, 0)); BoxShapeBuilder.build(mpb, 1, 1, 1); Model model = mb.end(); new GLTFExporter().export(model, Gdx.files.absolute("/tmp/ExportSharedIndexBufferTest.gltf")); Gdx.app.exit(); }
Example #2
Source File: Shadow.java From gdx-proto with Apache License 2.0 | 6 votes |
public static void init() { list = new Array<>(); ModelBuilder mb = new ModelBuilder(); Vector3 norm = new Vector3(0f, 1f, 0f); Texture texture = Assets.manager.get("textures/shadow.png", Texture.class); Material material = new Material(TextureAttribute.createDiffuse(texture)); material.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, 0.7f)); //material.set(new DepthTestAttribute(0)); // disable depth testing long attr = Usage.Position | Usage.TextureCoordinates; float s = 1f; model = mb.createRect( -s, 0f, -s,// bl -s, 0f, s, // tl s, 0f, s, // tr s, 0f, -s, // br norm.x, norm.y, norm.z, material, attr ); }
Example #3
Source File: LevelBuilder.java From gdx-proto with Apache License 2.0 | 6 votes |
/** client builds statics, probably based on info from server */ public static void buildStatics(LevelStatic[] statics) { if (staticGeometry == null) { staticGeometry = new Array<>(); } Log.debug("client building statics received from server: " + statics.length); ModelBuilder mb = new ModelBuilder(); mb.begin(); for (LevelStatic stat : statics) { Model model = Assets.manager.get(stat.modelName, Model.class); setupStaticModel(model.meshParts, stat.mtx, true); Node node = mb.node("piece", model); stat.mtx.getTranslation(tmp); node.translation.set(tmp); node.rotation.set(stat.mtx.getRotation(q)); } Model finalModel = mb.end(); ModelInstance instance = new ModelInstance(finalModel); staticGeometry.add(instance); }
Example #4
Source File: ModelManager.java From gdx-proto with Apache License 2.0 | 6 votes |
public void createBillboardTest() { ModelBuilder mb = new ModelBuilder(); mb.begin(); long attr = Usage.TextureCoordinates | Usage.Position | Usage.Normal; TextureRegion region = Assets.getAtlas().findRegion("sprites/test-guy"); Material mat = new Material(TextureAttribute.createDiffuse(region.getTexture())); boolean blended = true; float opacity = 1f; mat.set(new BlendingAttribute(blended, GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, opacity)); MeshPartBuilder mpb = mb.part("rect", GL20.GL_TRIANGLES, attr, mat); mpb.setUVRange(region); // the coordinates are offset so that we can easily set the center position to align with the entity's body float sz = 2f; // size float b = -sz/2; // base float max = sz/2; // max Vector3 bl = new Vector3(b, b, 0f); Vector3 br = new Vector3(b, max, 0f); Vector3 tr = new Vector3(max, max, 0f); Vector3 tl = new Vector3(max, b, 0f); Vector3 norm = new Vector3(0f, 0f, 1f); mpb.rect(bl, tl, tr, br, norm); billboardTestModel = mb.end(); }
Example #5
Source File: ModelManager.java From gdx-proto with Apache License 2.0 | 6 votes |
/** players are represented by cubes, with another cube marking the direction it is facing */ public void createPlayerModel() { ModelBuilder mb = new ModelBuilder(); ModelBuilder mb2 = new ModelBuilder(); long attr = Usage.Position | Usage.Normal; float r = 0.5f; float g = 1f; float b = 0.75f; Material material = new Material(ColorAttribute.createDiffuse(new Color(r, g, b, 1f))); Material faceMaterial = new Material(ColorAttribute.createDiffuse(Color.BLUE)); float w = 1f; float d = w; float h = 2f; mb.begin(); //playerModel = mb.createBox(w, h, d, material, attr); Node node = mb.node("box", mb2.createBox(w, h, d, material, attr)); // the face is just a box to show which direction the player is facing Node faceNode = mb.node("face", mb2.createBox(w/2, h/2, d/2, faceMaterial, attr)); faceNode.translation.set(0f, 0f, d/2); playerModel = mb.end(); }
Example #6
Source File: Utils3D.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
private static void createAxes() { ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material()); builder.setColor(Color.LIGHT_GRAY); for (float t = GRID_MIN; t <= GRID_MAX; t+=GRID_STEP) { builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX); builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t); } builder = modelBuilder.part("axes", GL20.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material()); builder.setColor(Color.RED); builder.line(0, 0, 0, 10, 0, 0); builder.setColor(Color.GREEN); builder.line(0, 0, 0, 0, 10, 0); builder.setColor(Color.BLUE); builder.line(0, 0, 0, 0, 0, 10); axesModel = modelBuilder.end(); axesInstance = new ModelInstance(axesModel); }
Example #7
Source File: Utils3D.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
public static void createFloor() { 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, -0.1f, 0, 10, .2f, 10); mpb.rect(-10, 0, -10, -10, 0, 10, 10, 0, 10, 10, 0, -10, 0, 1, 0); floorModel = modelBuilder.end(); floorInstance = new ModelInstance(floorModel); // TODO Set only when FBO is active floorInstance.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)); }
Example #8
Source File: SimpleRoom.java From gdx-vr with Apache License 2.0 | 6 votes |
@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 #9
Source File: ModelFactory.java From GdxDemo3D with Apache License 2.0 | 6 votes |
public static Model buildPlaneModel(final float width, final float height, final Material material, final float u1, final float v1, final float u2, final float v2) { ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder bPartBuilder = modelBuilder.part("rect", GL20.GL_TRIANGLES, VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates, material); bPartBuilder.setUVRange(u1, v1, u2, v2); bPartBuilder.rect(-(width * 0.5f), -(height * 0.5f), 0, (width * 0.5f), -(height * 0.5f), 0, (width * 0.5f), (height * 0.5f), 0, -(width * 0.5f), (height * 0.5f), 0, 0, 0, -1); return (modelBuilder.end()); }
Example #10
Source File: ScaleTool.java From Mundus with Apache License 2.0 | 6 votes |
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 #11
Source File: UsefulMeshs.java From Mundus with Apache License 2.0 | 6 votes |
public static Model createAxes() { final float GRID_MIN = -10f; final float GRID_MAX = 10f; final float GRID_STEP = 1f; ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, new Material()); builder.setColor(Color.LIGHT_GRAY); for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) { builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX); builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t); } builder = modelBuilder.part("axes", GL20.GL_LINES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, new Material()); builder.setColor(Color.RED); builder.line(0, 0, 0, 100, 0, 0); builder.setColor(Color.GREEN); builder.line(0, 0, 0, 0, 100, 0); builder.setColor(Color.BLUE); builder.line(0, 0, 0, 0, 0, 100); return modelBuilder.end(); }
Example #12
Source File: Terrain.java From Mundus with Apache License 2.0 | 6 votes |
public void init() { final int numVertices = this.vertexResolution * vertexResolution; final int numIndices = (this.vertexResolution - 1) * (vertexResolution - 1) * 6; mesh = new Mesh(true, numVertices, numIndices, attribs); this.vertices = new float[numVertices * stride]; mesh.setIndices(buildIndices()); buildVertices(); mesh.setVertices(vertices); MeshPart meshPart = new MeshPart(null, mesh, 0, numIndices, GL20.GL_TRIANGLES); meshPart.update(); ModelBuilder mb = new ModelBuilder(); mb.begin(); mb.part(meshPart, material); model = mb.end(); modelInstance = new ModelInstance(model); modelInstance.transform = transform; }
Example #13
Source File: TranslateTool.java From Mundus with Apache License 2.0 | 5 votes |
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 #14
Source File: ModelFactory.java From GdxDemo3D with Apache License 2.0 | 5 votes |
public static Model buildCompassModel() { float compassScale = 5; ModelBuilder modelBuilder = new ModelBuilder(); Model arrow = modelBuilder.createArrow(Vector3.Zero, Vector3.Y.cpy().scl(compassScale), null, VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal); modelBuilder.begin(); Mesh zArrow = arrow.meshes.first().copy(false); zArrow.transform(new Matrix4().rotate(Vector3.X, 90)); modelBuilder.part("part1", zArrow, GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(Color.BLUE))); modelBuilder.node(); Mesh yArrow = arrow.meshes.first().copy(false); modelBuilder.part("part2", yArrow, GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(Color.GREEN))); modelBuilder.node(); Mesh xArrow = arrow.meshes.first().copy(false); xArrow.transform(new Matrix4().rotate(Vector3.Z, -90)); modelBuilder.part("part3", xArrow, GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(Color.RED))); arrow.dispose(); return modelBuilder.end(); }
Example #15
Source File: UsefulMeshs.java From Mundus with Apache License 2.0 | 5 votes |
public static Model createArrowStub(Material mat, Vector3 from, Vector3 to) { ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder meshBuilder; // line meshBuilder = modelBuilder.part("line", GL20.GL_LINES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, mat); meshBuilder.line(from.x, from.y, from.z, to.x, to.y, to.z); // stub Node node = modelBuilder.node(); node.translation.set(to.x, to.y, to.z); meshBuilder = modelBuilder.part("stub", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal, mat); BoxShapeBuilder.build(meshBuilder, 2, 2, 2); return modelBuilder.end(); }
Example #16
Source File: Skybox.java From Mundus with Apache License 2.0 | 5 votes |
private Model createModel() { ModelBuilder modelBuilder = new ModelBuilder(); Model model = modelBuilder.createBox(1, 1, 1, new Material(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap)), VertexAttributes.Usage.Position); return model; }
Example #17
Source File: FluidSimulatorGeneric.java From fluid-simulator-v2 with Apache License 2.0 | 5 votes |
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 #18
Source File: GameRenderer.java From Radix with MIT License | 5 votes |
private void drawBlockSelection() { int curProgressInt = Math.round(RadixClient.getInstance().getPlayer().getBreakPercent() * 10) - 1; if ((blockBreakModel == null || blockBreakStage != curProgressInt) && curProgressInt >= 0) { if (blockBreakModel != null) blockBreakModel.dispose(); blockBreakStage = curProgressInt; ModelBuilder builder = new ModelBuilder(); blockBreakModel = builder.createBox(1f, 1f, 1f, new Material(TextureAttribute.createDiffuse(blockBreakStages[blockBreakStage]), new BlendingAttribute(), FloatAttribute.createAlphaTest(0.25f)), VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates); blockBreakModelInstance = new ModelInstance(blockBreakModel); } Vec3i curBlk = RadixClient.getInstance().getSelectedBlock(); if (curBlk != null && curProgressInt >= 0) { Gdx.gl.glPolygonOffset(100000, 2000000); blockOverlayBatch.begin(RadixClient.getInstance().getCamera()); blockBreakModelInstance.transform.translate(curBlk.x + 0.5f, curBlk.y + 0.5f, curBlk.z + 0.5f); blockOverlayBatch.render(blockBreakModelInstance); blockBreakModelInstance.transform.translate(-(curBlk.x + 0.5f), -(curBlk.y + 0.5f), -(curBlk.z + 0.5f)); blockOverlayBatch.end(); Gdx.gl.glPolygonOffset(100000, -2000000); } }
Example #19
Source File: Box.java From gdx-proto with Apache License 2.0 | 5 votes |
/** create some boxes to fill the level with some test geometry */ public static void createBoxes(int count) { ModelBuilder main = new ModelBuilder(); ModelBuilder mb = new ModelBuilder(); Material material = new Material(); if (Main.isClient()) { material.set(TextureAttribute.createDiffuse(Assets.manager.get("textures/marble.jpg", Texture.class))); } main.begin(); //float x = GameWorld.WORLD_WIDTH; //float y = GameWorld.WORLD_DEPTH; for (int i = 0; i < count; i++) { //float w = MathUtils.random(minW, maxW); float w = 8f; float d = 8f; float h = (i+1)*5f; tmp.set(10f + (w+2) * i, 0f, 10f + (d+2) * i); if (Main.isClient()) { mb.begin(); MeshPartBuilder mpb = mb.part("part-" + i, GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, material); mpb.box(w, h, d); Model boxModel = mb.end(); Node node = main.node("box-" + i, boxModel); node.translation.set(tmp); q.idt(); node.rotation.set(q); } //node.translation.set(MathUtils.random(x), 0f, MathUtils.random(y)); //q.set(Vector3.X, -90); mtx.set(q); mtx.setTranslation(tmp); btCollisionObject obj = Physics.inst.createBoxObject(tmp.set(w/2, h/2, d/2)); obj.setWorldTransform(mtx); Physics.applyStaticGeometryCollisionFlags(obj); Physics.inst.addStaticGeometryToWorld(obj); } Model finalModel = main.end(); instance = new ModelInstance(finalModel); }
Example #20
Source File: Chunk.java From Radix with MIT License | 5 votes |
@Override public void rerender() { if (cleanedUp) return; boolean neighborSunlightChanging = false; for(int x = startPosition.x - 16; x <= startPosition.x + 16; x += 16) { for(int z = startPosition.z - 16; z <= startPosition.z + 16; z += 16) { IChunk c = getWorld().getChunk(x, z); if(c != null && c.waitingOnLightFinish()) { neighborSunlightChanging = true; } } } if(neighborSunlightChanging) return; if (!setup) { meshBuilder = new MeshBuilder(); modelBuilder = new ModelBuilder(); setup = true; } sunlightChanged = false; if(meshing) { meshWhenDone = true; } else { meshing = true; parentWorld.addToMeshQueue(this::updateFaces); } }
Example #21
Source File: SceneSkybox.java From gdx-gltf with Apache License 2.0 | 5 votes |
public SceneSkybox(Cubemap cubemap){ super(); // create shader provider Config shaderConfig = new Config(); String basePathName = "net/mgsx/gltf/shaders/skybox"; shaderConfig.vertexShader = Gdx.files.classpath(basePathName + ".vs.glsl").readString(); shaderConfig.fragmentShader = Gdx.files.classpath(basePathName + ".fs.glsl").readString(); shaderProvider = new DefaultShaderProvider(shaderConfig); // create box float boxScale = (float)(1.0 / Math.sqrt(2.0)); boxModel = new ModelBuilder().createBox(boxScale, boxScale, boxScale, new Material(), VertexAttributes.Usage.Position); box = boxModel.nodes.first().parts.first().setRenderable(new Renderable()); // assign environment Environment env = new Environment(); env.set(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap)); env.set(new ColorAttribute(ColorAttribute.AmbientLight, Color.WHITE)); box.environment = env; // set hint to render last but before transparent ones box.userData = SceneRenderableSorter.Hints.OPAQUE_LAST; // set material options : preserve background depth box.material = new Material(ColorAttribute.createDiffuse(Color.WHITE)); box.material.set(new DepthTestAttribute(false)); // assign shader box.shader = shaderProvider.getShader(box); }
Example #22
Source File: UsefulMeshs.java From Mundus with Apache License 2.0 | 4 votes |
public static Model torus(Material mat, float width, float height, int divisionsU, int divisionsV) { ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder builder = modelBuilder.part("torus", GL20.GL_TRIANGLES, VertexAttributes.Usage.Position, mat); // builder.setColor(Color.LIGHT_GRAY); MeshPartBuilder.VertexInfo curr1 = v0.set(null, null, null, null); curr1.hasUV = curr1.hasNormal = false; curr1.hasPosition = true; MeshPartBuilder.VertexInfo curr2 = v1.set(null, null, null, null); curr2.hasUV = curr2.hasNormal = false; curr2.hasPosition = true; short i1, i2, i3 = 0, i4 = 0; int i, j, k; double s, t, twopi; twopi = 2 * Math.PI; for (i = 0; i < divisionsV; i++) { for (j = 0; j <= divisionsU; j++) { for (k = 1; k >= 0; k--) { s = (i + k) % divisionsV + 0.5; t = j % divisionsU; curr1.position.set( (float) ((width + height * Math.cos(s * twopi / divisionsV)) * Math.cos(t * twopi / divisionsU)), (float) ((width + height * Math.cos(s * twopi / divisionsV)) * Math.sin(t * twopi / divisionsU)), (float) (height * Math.sin(s * twopi / divisionsV))); k--; s = (i + k) % divisionsV + 0.5; curr2.position.set( (float) ((width + height * Math.cos(s * twopi / divisionsV)) * Math.cos(t * twopi / divisionsU)), (float) ((width + height * Math.cos(s * twopi / divisionsV)) * Math.sin(t * twopi / divisionsU)), (float) (height * Math.sin(s * twopi / divisionsV))); // curr2.uv.set((float) s, 0); i1 = builder.vertex(curr1); i2 = builder.vertex(curr2); builder.rect(i4, i2, i1, i3); i4 = i2; i3 = i1; } } } return modelBuilder.end(); }
Example #23
Source File: Terrain.java From gdx-proto with Apache License 2.0 | 4 votes |
/** * Creates a plane, used for testing * @param size the size of the plane * @return */ public static TerrainChunk CreatePlaneChunk (float size) { TerrainChunk chunk = new TerrainChunk(); // graphical representation of the ground Log.debug("createLevel - create ground"); if (Main.isClient()) { ModelBuilder mb = new ModelBuilder(); mb.begin(); Vector3 bl = new Vector3(); Vector3 tl = new Vector3(); Vector3 tr = new Vector3(); Vector3 br = new Vector3(); Vector3 norm = new Vector3(0f, 1f, 0f); // the size of each rect that makes up the ground Texture groundTex = Assets.manager.get("textures/ground1.jpg", Texture.class); Material groundMat = new Material(TextureAttribute.createDiffuse(groundTex)); MeshPartBuilder mpb = mb.part("ground", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, groundMat); float u1 = 0f; float v1 = 0f; float u2 = size / 5f; float v2 = size / 5f; mpb.setUVRange(u1, v1, u2, v2); bl.set(0, 0, 0); tl.set(0, 0, size); tr.set(size, 0, size); br.set(size, 0, 0); // mpb.rect(bl, tl, tr, br, norm); int divisions = ((int)size) / 4; mpb.patch(bl, tl, tr, br, norm, divisions, divisions); Model groundModel = mb.end(); chunk.modelInstance = new ModelInstance(groundModel); } // physical representation of the ground btCollisionObject groundObj = new btCollisionObject(); btCollisionShape groundShape = new btStaticPlaneShape(Vector3.Y, 0f); groundObj.setCollisionShape(groundShape); Physics.applyStaticGeometryCollisionFlags(groundObj); Physics.inst.addStaticGeometryToWorld(groundObj); chunk.body = groundObj; return chunk; }
Example #24
Source File: LevelBuilder.java From gdx-proto with Apache License 2.0 | 4 votes |
public static void init() { staticPieces = new Array<>(); groundPieces = new Array<>(); mb = new ModelBuilder(); models = new Array<>(); }
Example #25
Source File: LevelBuilder.java From gdx-proto with Apache License 2.0 | 4 votes |
public static void createLevel() { // graphical representation of the ground Log.debug("createLevel - create ground"); if (Main.isClient()) { ModelBuilder mb = new ModelBuilder(); mb.begin(); Vector3 bl = new Vector3(); Vector3 tl = new Vector3(); Vector3 tr = new Vector3(); Vector3 br = new Vector3(); Vector3 norm = new Vector3(0f, 1f, 0f); // the size of each rect that makes up the ground Texture groundTex = Assets.manager.get("textures/ground1.jpg", Texture.class); Material groundMat = new Material(TextureAttribute.createDiffuse(groundTex)); MeshPartBuilder mpb = mb.part("ground", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, groundMat); float u1 = 0f; float v1 = 0f; float u2 = groundPieceSize / 5f; float v2 = groundPieceSize / 5f; mpb.setUVRange(u1, v1, u2, v2); bl.set(0, 0, 0); tl.set(0, 0, groundPieceSize); tr.set(groundPieceSize, 0, groundPieceSize); br.set(groundPieceSize, 0, 0); //mpb.rect(bl, tl, tr, br, norm); int divisions = ((int) groundPieceSize) / 4; mpb.patch(bl, tl, tr, br, norm, divisions, divisions); Model groundModel = mb.end(); models.add(groundModel); groundPieces.clear(); int count = 0; for (int x = 0; x < GameWorld.WORLD_WIDTH; x += groundPieceSize) { for (int z = 0; z < GameWorld.WORLD_DEPTH; z += groundPieceSize) { count++; ModelInstance groundPiece = new ModelInstance(groundModel); groundPiece.transform.setToTranslation(x, 0f, z); groundPieces.add(groundPiece); } } Log.debug("createLevel - created " + count + " groundPieces"); } // physical representation of the ground btCollisionObject groundObj = new btCollisionObject(); btCollisionShape groundShape = new btStaticPlaneShape(Vector3.Y, 0f); groundObj.setCollisionShape(groundShape); Physics.applyStaticGeometryCollisionFlags(groundObj); Physics.inst.addStaticGeometryToWorld(groundObj); if (Main.isServer()) { Log.debug("createLevel - create static models"); // server creates static models here, client will create the models when received from server upon connection createStaticModels(25); } Log.debug("createLevel - create boxes"); Box.createBoxes(10); }