Skip to content

Added LODRenderable #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added android/assets/models/mount.g3db
Binary file not shown.
Binary file added android/assets/models/mount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/assets/textures/hm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/assets/textures/hm_paint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion core/src/org/jrenner/fps/Assets.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void loadAll() {
manager.load("models/gate.g3db", HeadlessModel.class, modelParam);
manager.load("models/strange-ramp1.g3db", HeadlessModel.class, modelParam);
manager.load("models/strange-ramp2.g3db", HeadlessModel.class, modelParam);
manager.load("models/mount.g3db", HeadlessModel.class, modelParam);
} else {
ModelLoader.ModelParameters modelParam = new ModelLoader.ModelParameters();
modelParam.textureParameter = modTexParam;
Expand All @@ -77,6 +78,7 @@ public void loadAll() {
manager.load("models/strange-ramp1.g3db", Model.class, modelParam);
manager.load("models/strange-ramp2.g3db", Model.class, modelParam);
manager.load("models/skybox.g3db", Model.class, modelParam);
manager.load("models/mount.g3db", Model.class, modelParam);
}

if (Main.isClient()) {
Expand Down Expand Up @@ -139,7 +141,6 @@ private void loadTextures() {
manager.load("textures/skybox/zpos.png", Texture.class, skyTextureParam);
manager.load("textures/skybox/zneg.png", Texture.class, skyTextureParam);


// load Texture Atlas
manager.load("texture-packs/texture-pack.atlas", TextureAtlas.class);
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/org/jrenner/fps/HUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ public void update() {
sb.append("\n\nPhysics time: ").append(String.format("%4s", Main.physicsTime));
sb.append("\nGround dist: ").append(String.format("%.4f", player.entity.distFromGround));
sb.append("\nGround normal: ").append(Tools.fmt(Physics.inst.getFloorNormal(player.entity.getPosition())));
sb.append("\nGroundPiece visibility: ").append(View.visibleGroundPieces).append(" / ").append(LevelBuilder.groundPieces.size);
//sb.append("\nGroundPiece visibility: ").append(View.visibleGroundPieces).append(" / ").append(View.totalGroundPieces);
//sb.append("\nGroundPiece visibility: ").append(View.visibleGroundPieces).append(" / ").append(LevelBuilder.groundPieces.size);
sb.append("\nEntity visibility: ").append(View.visibleEntities).append(" / ").append(Entity.list.size);
}
sb.append("\nPress T to chat\nPress R to respawn");
Expand Down
73 changes: 8 additions & 65 deletions core/src/org/jrenner/fps/LevelBuilder.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package org.jrenner.fps;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g3d.Material;
import org.jrenner.fps.headless.HeadlessModel;
import org.jrenner.fps.terrain.Terrain;
import org.jrenner.fps.terrain.TerrainChunk;

import com.badlogic.gdx.graphics.g3d.Model;
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.model.MeshPart;
import com.badlogic.gdx.graphics.g3d.model.Node;
import com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Matrix4;
Expand All @@ -19,13 +16,7 @@
import com.badlogic.gdx.physics.bullet.collision.btBvhTriangleMeshShape;
import com.badlogic.gdx.physics.bullet.collision.btCollisionObject;
import com.badlogic.gdx.physics.bullet.collision.btCollisionShape;
import com.badlogic.gdx.physics.bullet.collision.btStaticPlaneShape;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.GdxRuntimeException;
import org.jrenner.fps.headless.HeadlessModel;

import static com.badlogic.gdx.graphics.VertexAttributes.Usage;
import static com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo;

public class LevelBuilder {
public static LevelBuilder inst;
Expand All @@ -36,7 +27,6 @@ public class LevelBuilder {

public static void init() {
staticPieces = new Array<>();
groundPieces = new Array<>();
mb = new ModelBuilder();
models = new Array<>();
}
Expand All @@ -47,58 +37,11 @@ public LevelBuilder() {

public static Array<ModelInstance> staticGeometry;

public static Array<ModelInstance> groundPieces;
public static final float groundPieceSize = 100f;

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);

// Create a terrain
TerrainChunk chunk = Terrain.CreateMeshChunk(Assets.manager.get("models/mount.g3db", Model.class));
Terrain.addChunk(chunk, -50, -50);

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
Expand Down
3 changes: 3 additions & 0 deletions core/src/org/jrenner/fps/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.TimeUtils;

import org.jrenner.fps.effects.BulletHit;
import org.jrenner.fps.entity.Entity;
import org.jrenner.fps.event.ClientEventManager;
Expand All @@ -21,6 +22,7 @@
import org.jrenner.fps.net.client.LocalClient;
import org.jrenner.fps.net.client.NetClient;
import org.jrenner.fps.particles.Particles;
import org.jrenner.fps.terrain.Terrain;
import org.jrenner.fps.utils.Pooler;

public class Main extends ApplicationAdapter {
Expand Down Expand Up @@ -177,6 +179,7 @@ private void initializeSubModules() {
Toggleable.init();
}
LevelBuilder.init();
Terrain.init();
Block.init();
if (isClient()) {
Shadow.init();
Expand Down
5 changes: 0 additions & 5 deletions core/src/org/jrenner/fps/Terrain.java

This file was deleted.

36 changes: 27 additions & 9 deletions core/src/org/jrenner/fps/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.jrenner.fps.graphics.ModelManager;
import org.jrenner.fps.net.packages.ChatMessage;
import org.jrenner.fps.particles.Particles;
import org.jrenner.fps.terrain.Terrain;
import org.jrenner.fps.terrain.TerrainChunk;

public class View implements Disposable {
public static View inst;
Expand Down Expand Up @@ -83,7 +85,7 @@ public View() {
camLight = new PointLight();
float intensity = 100f;
camLight.set(new Color(0.2f, 0.2f, 0.2f, 1f), 0f, 0f, 0f, intensity);
ColorAttribute ambientLight = ColorAttribute.createAmbient(new Color(0.1f, 0.1f, 0.1f, 1f));
ColorAttribute ambientLight = new ColorAttribute(ColorAttribute.AmbientLight, .1f , .1f, .1f ,1);
environ.set(ambientLight);
ColorAttribute fog = new ColorAttribute(ColorAttribute.Fog);
fog.color.set(fogColor);
Expand Down Expand Up @@ -178,11 +180,23 @@ public void render() {
updateCamera();

long skyStart = TimeUtils.millis();
updateSky();
modelBatch.begin(camera);
if (Sky.isEnabled()) {
Sky.update(camera.position);
modelBatch.render(Sky.modelInstance);
}

if (Terrain.chunks != null) {
for (TerrainChunk chunk : Terrain.chunks) {
chunk.render(modelBatch, environ);
}
}

if (LevelBuilder.staticGeometry != null) {
for (ModelInstance staticGeo : LevelBuilder.staticGeometry) {
modelBatch.render(staticGeo, environ);
}
}
skyTimes.add((int) TimeUtils.timeSinceMillis(skyStart));

// includes 3d models and billboards
Expand Down Expand Up @@ -214,15 +228,21 @@ public void render() {
}
staticTimes.add((int) TimeUtils.timeSinceMillis(staticStart));

/*
totalGroundPieces = 0;
=======
long groundStart = TimeUtils.millis();
>>>>>>> FETCH_HEAD
visibleGroundPieces = 0;
for (ModelInstance groundPiece : LevelBuilder.groundPieces) {
if (groundPieceVisibilityCheck(groundPiece)) {
visibleGroundPieces++;
modelBatch.render(groundPiece, environ);
}
}
groundTimes.add((int) TimeUtils.timeSinceMillis(groundStart));
<<<<<<< HEAD
*/
//groundTimes.add((int) TimeUtils.timeSinceMillis(groundStart));
modelBatch.end();

// draw particle effects in a separate batch to make depth testing work better
Expand Down Expand Up @@ -258,12 +278,6 @@ private void drawParticleEffects() {
modelBatch.render(Particles.inst.system);
}

private void updateSky() {
if (Sky.isEnabled()) {
Sky.update(camera.position);
}
}

private void updateLights() {
camLight.position.set(camera.position);
}
Expand Down Expand Up @@ -355,6 +369,9 @@ public void storeSize() {
height = Gdx.graphics.getHeight();
}

/*
public static int totalGroundPieces;
=======
public static int visibleGroundPieces;
private boolean groundPieceVisibilityCheck(ModelInstance modelInst) {
float halfWidth = LevelBuilder.groundPieceSize / 2f;
Expand All @@ -366,6 +383,7 @@ private boolean groundPieceVisibilityCheck(ModelInstance modelInst) {
// this naive method is useful for debugging to see pop-in/pop-out
//return camera.frustum.pointInFrustum(tmp);
}
*/

public static int visibleEntities;
private boolean entityVisibilityCheck(EntityModel entModel) {
Expand Down
Loading