Skip to content

Commit 6ec7ead

Browse files
committed
Merge pull request #11 from Caresilabs/Terrain-Branch
Terrain Manager
2 parents 5f288cf + c4ee2c1 commit 6ec7ead

15 files changed

+1037
-81
lines changed

android/assets/models/mount.g3db

323 KB
Binary file not shown.

android/assets/models/mount.png

2.92 MB
Loading

android/assets/textures/hm.png

5.7 KB
Loading

android/assets/textures/hm_paint.png

2.89 MB
Loading

core/src/org/jrenner/fps/Assets.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public void loadAll() {
6969
manager.load("models/gate.g3db", HeadlessModel.class, modelParam);
7070
manager.load("models/strange-ramp1.g3db", HeadlessModel.class, modelParam);
7171
manager.load("models/strange-ramp2.g3db", HeadlessModel.class, modelParam);
72+
manager.load("models/mount.g3db", HeadlessModel.class, modelParam);
7273
} else {
7374
ModelLoader.ModelParameters modelParam = new ModelLoader.ModelParameters();
7475
modelParam.textureParameter = modTexParam;
@@ -77,6 +78,7 @@ public void loadAll() {
7778
manager.load("models/strange-ramp1.g3db", Model.class, modelParam);
7879
manager.load("models/strange-ramp2.g3db", Model.class, modelParam);
7980
manager.load("models/skybox.g3db", Model.class, modelParam);
81+
manager.load("models/mount.g3db", Model.class, modelParam);
8082
}
8183

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

142-
143144
// load Texture Atlas
144145
manager.load("texture-packs/texture-pack.atlas", TextureAtlas.class);
145146
}

core/src/org/jrenner/fps/HUD.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ public void update() {
181181
sb.append("\n\nPhysics time: ").append(String.format("%4s", Main.physicsTime));
182182
sb.append("\nGround dist: ").append(String.format("%.4f", player.entity.distFromGround));
183183
sb.append("\nGround normal: ").append(Tools.fmt(Physics.inst.getFloorNormal(player.entity.getPosition())));
184-
sb.append("\nGroundPiece visibility: ").append(View.visibleGroundPieces).append(" / ").append(LevelBuilder.groundPieces.size);
184+
//sb.append("\nGroundPiece visibility: ").append(View.visibleGroundPieces).append(" / ").append(View.totalGroundPieces);
185+
//sb.append("\nGroundPiece visibility: ").append(View.visibleGroundPieces).append(" / ").append(LevelBuilder.groundPieces.size);
185186
sb.append("\nEntity visibility: ").append(View.visibleEntities).append(" / ").append(Entity.list.size);
186187
}
187188
sb.append("\nPress T to chat\nPress R to respawn");

core/src/org/jrenner/fps/LevelBuilder.java

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package org.jrenner.fps;
22

3-
import com.badlogic.gdx.graphics.Color;
4-
import com.badlogic.gdx.graphics.GL20;
5-
import com.badlogic.gdx.graphics.Texture;
6-
import com.badlogic.gdx.graphics.g3d.Material;
3+
import org.jrenner.fps.headless.HeadlessModel;
4+
import org.jrenner.fps.terrain.Terrain;
5+
import org.jrenner.fps.terrain.TerrainChunk;
6+
77
import com.badlogic.gdx.graphics.g3d.Model;
88
import com.badlogic.gdx.graphics.g3d.ModelInstance;
9-
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
10-
import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute;
119
import com.badlogic.gdx.graphics.g3d.model.MeshPart;
1210
import com.badlogic.gdx.graphics.g3d.model.Node;
13-
import com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder;
1411
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
1512
import com.badlogic.gdx.math.MathUtils;
1613
import com.badlogic.gdx.math.Matrix4;
@@ -19,13 +16,7 @@
1916
import com.badlogic.gdx.physics.bullet.collision.btBvhTriangleMeshShape;
2017
import com.badlogic.gdx.physics.bullet.collision.btCollisionObject;
2118
import com.badlogic.gdx.physics.bullet.collision.btCollisionShape;
22-
import com.badlogic.gdx.physics.bullet.collision.btStaticPlaneShape;
2319
import com.badlogic.gdx.utils.Array;
24-
import com.badlogic.gdx.utils.GdxRuntimeException;
25-
import org.jrenner.fps.headless.HeadlessModel;
26-
27-
import static com.badlogic.gdx.graphics.VertexAttributes.Usage;
28-
import static com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo;
2920

3021
public class LevelBuilder {
3122
public static LevelBuilder inst;
@@ -36,7 +27,6 @@ public class LevelBuilder {
3627

3728
public static void init() {
3829
staticPieces = new Array<>();
39-
groundPieces = new Array<>();
4030
mb = new ModelBuilder();
4131
models = new Array<>();
4232
}
@@ -47,58 +37,11 @@ public LevelBuilder() {
4737

4838
public static Array<ModelInstance> staticGeometry;
4939

50-
public static Array<ModelInstance> groundPieces;
51-
public static final float groundPieceSize = 100f;
52-
5340
public static void createLevel() {
54-
// graphical representation of the ground
55-
Log.debug("createLevel - create ground");
56-
if (Main.isClient()) {
57-
ModelBuilder mb = new ModelBuilder();
58-
mb.begin();
59-
Vector3 bl = new Vector3();
60-
Vector3 tl = new Vector3();
61-
Vector3 tr = new Vector3();
62-
Vector3 br = new Vector3();
63-
Vector3 norm = new Vector3(0f, 1f, 0f);
64-
// the size of each rect that makes up the ground
65-
Texture groundTex = Assets.manager.get("textures/ground1.jpg", Texture.class);
66-
Material groundMat = new Material(TextureAttribute.createDiffuse(groundTex));
67-
MeshPartBuilder mpb = mb.part("ground", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, groundMat);
68-
float u1 = 0f;
69-
float v1 = 0f;
70-
float u2 = groundPieceSize / 5f;
71-
float v2 = groundPieceSize / 5f;
72-
mpb.setUVRange(u1, v1, u2, v2);
73-
bl.set(0, 0, 0);
74-
tl.set(0, 0, groundPieceSize);
75-
tr.set(groundPieceSize, 0, groundPieceSize);
76-
br.set(groundPieceSize, 0, 0);
77-
//mpb.rect(bl, tl, tr, br, norm);
78-
int divisions = ((int) groundPieceSize) / 4;
79-
mpb.patch(bl, tl, tr, br, norm, divisions, divisions);
80-
Model groundModel = mb.end();
81-
models.add(groundModel);
82-
groundPieces.clear();
83-
int count = 0;
84-
for (int x = 0; x < GameWorld.WORLD_WIDTH; x += groundPieceSize) {
85-
for (int z = 0; z < GameWorld.WORLD_DEPTH; z += groundPieceSize) {
86-
count++;
87-
ModelInstance groundPiece = new ModelInstance(groundModel);
88-
groundPiece.transform.setToTranslation(x, 0f, z);
89-
groundPieces.add(groundPiece);
90-
}
91-
}
92-
Log.debug("createLevel - created " + count + " groundPieces");
93-
}
94-
95-
// physical representation of the ground
96-
btCollisionObject groundObj = new btCollisionObject();
97-
btCollisionShape groundShape = new btStaticPlaneShape(Vector3.Y, 0f);
98-
groundObj.setCollisionShape(groundShape);
99-
Physics.applyStaticGeometryCollisionFlags(groundObj);
100-
Physics.inst.addStaticGeometryToWorld(groundObj);
101-
41+
// Create a terrain
42+
TerrainChunk chunk = Terrain.CreateMeshChunk(Assets.manager.get("models/mount.g3db", Model.class));
43+
Terrain.addChunk(chunk, -50, -50);
44+
10245
if (Main.isServer()) {
10346
Log.debug("createLevel - create static models");
10447
// server creates static models here, client will create the models when received from server upon connection

core/src/org/jrenner/fps/Main.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.badlogic.gdx.InputMultiplexer;
77
import com.badlogic.gdx.utils.GdxRuntimeException;
88
import com.badlogic.gdx.utils.TimeUtils;
9+
910
import org.jrenner.fps.effects.BulletHit;
1011
import org.jrenner.fps.entity.Entity;
1112
import org.jrenner.fps.event.ClientEventManager;
@@ -21,6 +22,7 @@
2122
import org.jrenner.fps.net.client.LocalClient;
2223
import org.jrenner.fps.net.client.NetClient;
2324
import org.jrenner.fps.particles.Particles;
25+
import org.jrenner.fps.terrain.Terrain;
2426
import org.jrenner.fps.utils.Pooler;
2527

2628
public class Main extends ApplicationAdapter {
@@ -177,6 +179,7 @@ private void initializeSubModules() {
177179
Toggleable.init();
178180
}
179181
LevelBuilder.init();
182+
Terrain.init();
180183
Block.init();
181184
if (isClient()) {
182185
Shadow.init();

core/src/org/jrenner/fps/Terrain.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

core/src/org/jrenner/fps/View.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.jrenner.fps.graphics.ModelManager;
2525
import org.jrenner.fps.net.packages.ChatMessage;
2626
import org.jrenner.fps.particles.Particles;
27+
import org.jrenner.fps.terrain.Terrain;
28+
import org.jrenner.fps.terrain.TerrainChunk;
2729

2830
public class View implements Disposable {
2931
public static View inst;
@@ -83,7 +85,7 @@ public View() {
8385
camLight = new PointLight();
8486
float intensity = 100f;
8587
camLight.set(new Color(0.2f, 0.2f, 0.2f, 1f), 0f, 0f, 0f, intensity);
86-
ColorAttribute ambientLight = ColorAttribute.createAmbient(new Color(0.1f, 0.1f, 0.1f, 1f));
88+
ColorAttribute ambientLight = new ColorAttribute(ColorAttribute.AmbientLight, .1f , .1f, .1f ,1);
8789
environ.set(ambientLight);
8890
ColorAttribute fog = new ColorAttribute(ColorAttribute.Fog);
8991
fog.color.set(fogColor);
@@ -178,11 +180,23 @@ public void render() {
178180
updateCamera();
179181

180182
long skyStart = TimeUtils.millis();
181-
updateSky();
182183
modelBatch.begin(camera);
183184
if (Sky.isEnabled()) {
185+
Sky.update(camera.position);
184186
modelBatch.render(Sky.modelInstance);
185187
}
188+
189+
if (Terrain.chunks != null) {
190+
for (TerrainChunk chunk : Terrain.chunks) {
191+
chunk.render(modelBatch, environ);
192+
}
193+
}
194+
195+
if (LevelBuilder.staticGeometry != null) {
196+
for (ModelInstance staticGeo : LevelBuilder.staticGeometry) {
197+
modelBatch.render(staticGeo, environ);
198+
}
199+
}
186200
skyTimes.add((int) TimeUtils.timeSinceMillis(skyStart));
187201

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

231+
/*
232+
totalGroundPieces = 0;
233+
=======
217234
long groundStart = TimeUtils.millis();
235+
>>>>>>> FETCH_HEAD
218236
visibleGroundPieces = 0;
219237
for (ModelInstance groundPiece : LevelBuilder.groundPieces) {
220238
if (groundPieceVisibilityCheck(groundPiece)) {
221239
visibleGroundPieces++;
222240
modelBatch.render(groundPiece, environ);
223241
}
224242
}
225-
groundTimes.add((int) TimeUtils.timeSinceMillis(groundStart));
243+
<<<<<<< HEAD
244+
*/
245+
//groundTimes.add((int) TimeUtils.timeSinceMillis(groundStart));
226246
modelBatch.end();
227247

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

261-
private void updateSky() {
262-
if (Sky.isEnabled()) {
263-
Sky.update(camera.position);
264-
}
265-
}
266-
267281
private void updateLights() {
268282
camLight.position.set(camera.position);
269283
}
@@ -355,6 +369,9 @@ public void storeSize() {
355369
height = Gdx.graphics.getHeight();
356370
}
357371

372+
/*
373+
public static int totalGroundPieces;
374+
=======
358375
public static int visibleGroundPieces;
359376
private boolean groundPieceVisibilityCheck(ModelInstance modelInst) {
360377
float halfWidth = LevelBuilder.groundPieceSize / 2f;
@@ -366,6 +383,7 @@ private boolean groundPieceVisibilityCheck(ModelInstance modelInst) {
366383
// this naive method is useful for debugging to see pop-in/pop-out
367384
//return camera.frustum.pointInFrustum(tmp);
368385
}
386+
*/
369387

370388
public static int visibleEntities;
371389
private boolean entityVisibilityCheck(EntityModel entModel) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
package org.jrenner.fps.terrain;
3+
4+
import com.badlogic.gdx.graphics.PerspectiveCamera;
5+
import com.badlogic.gdx.graphics.g3d.Model;
6+
import com.badlogic.gdx.graphics.g3d.ModelInstance;
7+
import com.badlogic.gdx.math.Vector3;
8+
import com.badlogic.gdx.math.collision.BoundingBox;
9+
10+
public class GroundChunk extends ModelInstance {
11+
private static final BoundingBox box = new BoundingBox();
12+
public Vector3 position;
13+
public Vector3 dimensions;
14+
public float radius;
15+
16+
public GroundChunk (Model model) {
17+
super(model);
18+
calculateTransforms();
19+
calculateBoundingBox(box);
20+
dimensions = new Vector3(box.getDimensions());
21+
radius = dimensions.len() / 2f;
22+
position = new Vector3(box.getCenter());
23+
// Lists.groundChunks.add(this);
24+
}
25+
26+
public boolean isVisible (PerspectiveCamera cam) {
27+
return cam.frustum.sphereInFrustum(position, radius);
28+
}
29+
30+
}

0 commit comments

Comments
 (0)