Skip to content

Commit

Permalink
Fixed rendering of models where certain components don't have texture…
Browse files Browse the repository at this point in the history
… coords; Lady Smith model is now begin rendered right; cleaned up code some more; updated .gitignore to generically exclude *all* the .mayaSwatches folders;
  • Loading branch information
Andrei Bârsan committed May 23, 2013
1 parent 6fa2308 commit 0bc130b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -39,7 +39,7 @@ local.properties
.externalToolBuilders/

# Maya stuff
res/models/.mayaSwatches/
.mayaSwatches/

# Locally stored "Eclipse launch configurations"
*.launch
Expand Down
2 changes: 1 addition & 1 deletion res/models/LS.mtl
Expand Up @@ -24,4 +24,4 @@ newmtl LS_Shader_Base
Ke 0.000000 0.000000 0.000000
map_Kd LS_Diffuse_A.png
#map_Ks LS_Rim_A.png
#map_bump LS_NormalMap.png
map_bump LS_NormalMap.png
2 changes: 2 additions & 0 deletions res/models/LS.obj
Expand Up @@ -7,6 +7,8 @@ mtllib LS.mtl
# object BN_tailBone_S00
#

o LS

v -1.954513 102.541954 0.025000
v -1.954513 102.541954 -0.025000
v -1.906797 102.527016 -0.025000
Expand Down
Binary file modified res/tex/LS_Diffuse_A.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 6 additions & 64 deletions src/barsan/opengl/rendering/StaticModel.java
Expand Up @@ -65,8 +65,7 @@ public void buildVBOs() {
texcoords = new VBO(GL2.GL_ARRAY_BUFFER, size, TEX_COORDS_PER_POINT);
tangents = new VBO(GL2.GL_ARRAY_BUFFER, size, COORDS_PER_POINT);
binormals = new VBO(GL2.GL_ARRAY_BUFFER, size, COORDS_PER_POINT);

//*

for(Face f : master.faces) {
if(ModelLoader.loadingFronLHCoords) {
vertices.quickAppend(f.points);
Expand All @@ -88,7 +87,7 @@ public void buildVBOs() {
}
}

if(master.faces.get(0).texCoords != null) {
if(f.texCoords != null) {
texcoords.open();
if(ModelLoader.loadingFronLHCoords) {
for(Vector3 tc : f.texCoords) {
Expand All @@ -97,7 +96,6 @@ public void buildVBOs() {
texcoords.append(uv);
}
} else {

for(int i = f.texCoords.length - 1; i >=0; --i) {
Vector3 tc = f.texCoords[i];
uv[0] = tc.x;
Expand All @@ -107,70 +105,14 @@ public void buildVBOs() {
}
texcoords.close();
}
}
//*/


/*
for(MaterialGroup mg : defaultMaterialGroups) {
vertices.open();
for(int i = mg.beginIndex; i < mg.beginIndex + mg.length; ++i) {
Face f = master.faces.get(i);
for(int p = 0; p < pointsPerFace; ++p) {
vertices.append(f.points[p]);
}
}
vertices.close();
if(master.faces.get(mg.beginIndex).normals != null) {
normals.open();
for(int i = mg.beginIndex; i < mg.beginIndex + mg.length; ++i) {
Face f = master.faces.get(i);
for(int p = 0; p < pointsPerFace; ++p) {
normals.append(f.normals[p]);
}
}
normals.close();
// Wtf
for(Face f : master.faces) {
f.computeTangBinorm();
}
tangents.open();
for(int i = mg.beginIndex; i < mg.beginIndex + mg.length; ++i) {
Face f = master.faces.get(i);
for(int p = 0; p < pointsPerFace; ++p) {
tangents.append(f.tangents[p]);
}
}
tangents.close();
binormals.open();
for(int i = mg.beginIndex; i < mg.beginIndex + mg.length; ++i) {
Face f = master.faces.get(i);
for(int p = 0; p < pointsPerFace; ++p) {
binormals.append(f.binormals[p]);
}
}
binormals.close();
}
if(master.faces.get(0).texCoords != null) {
else {
texcoords.open();
for(int i = mg.beginIndex; i < mg.beginIndex + mg.length; ++i) {
Face f = master.faces.get(i);
for(int p = 0; p < pointsPerFace; ++p) {
uv[0] = f.texCoords[p].x;
uv[1] = f.texCoords[p].y;
texcoords.append(uv);
}
}
texcoords.append(new float[]{ 0, 0 });
texcoords.append(new float[]{ 0, 0 });
texcoords.append(new float[]{ 0, 0 });
texcoords.close();
}
}
*/

if(Yeti.get().settings.debugModels) {
Yeti.debug(String.format("VBOs for \"%s\" built. Normal element count: %d;" +
Expand Down
7 changes: 3 additions & 4 deletions src/barsan/opengl/resources/ModelLoader.java
Expand Up @@ -116,7 +116,7 @@ public static StaticModel fromObj(GL gl, Scanner input, int explicitPointsPerFac
line.substring(1).trim(),
vc, nc, tc);
model.master.faces.addAll(result);
fc++;
fc += result.size();
break;

case 'o':
Expand Down Expand Up @@ -226,7 +226,6 @@ private static List<Face> readFace(MaterialGroup mg, StaticModel model, String s
if(res.length < 3) {
throw new InputMismatchException(String.format("Bad number of geometry/texture/normal coordinates (%d)!", res.length));
}


if(model.getPointsPerFace() == 0) {
Yeti.debug("Model " + model.getName() + " now using " + res.length + " points per face.");
Expand All @@ -239,19 +238,19 @@ else if(model.getPointsPerFace() != res.length) {
throw new UnsupportedOperationException("Mesh with varying face sizes but" +
" no way of separating them.");
}

}

for(int i = 0; i < res.length; i++) {
if(res[i].contains("/")) {
String[] bits = res[i].split("/");

if(subCount == 1) {
throw new InputMismatchException("Invalid combination of geometry/texture/normal coordinates.");
}

verts[i] = Integer.parseInt(bits[0]);

// Negative inices provide relative references
// Negative indices provide relative references
if(verts[i] < 0) {
verts[i] = currentVertex + verts[i] + 1;
}
Expand Down
36 changes: 25 additions & 11 deletions src/barsan/opengl/scenes/NessieTestScene.java
Expand Up @@ -22,8 +22,6 @@
import barsan.opengl.rendering.lights.DirectionalLight;
import barsan.opengl.rendering.lights.PointLight;
import barsan.opengl.rendering.lights.SpotLight;
import barsan.opengl.rendering.materials.BasicMaterial;
import barsan.opengl.rendering.materials.Material;
import barsan.opengl.resources.ModelLoader;
import barsan.opengl.resources.ResourceLoader;
import barsan.opengl.util.Color;
Expand Down Expand Up @@ -64,7 +62,7 @@ public void init(GLAutoDrawable drawable) {
//*
DirectionalLight dl = new DirectionalLight(new Vector3(-2.0f, -1.0f, -1.0f).normalize());
dl.setCastsShadows(true);
dl.getDiffuse().a = 0.50f;
dl.getDiffuse().a = 0.25f;
lights.add(dl);
//*/

Expand All @@ -87,15 +85,31 @@ public void init(GLAutoDrawable drawable) {
//addModelInstance(box);

h = new StaticModelInstance(ResourceLoader.model("hm"));
h.getTransform().updateTranslate(-15.0f, -10.0f, -18.0f);
h.getTransform().updateTranslate(-15.0f, -12.0f, -18.0f);
h.getTransform().updateRotation(0.0f, 1.0f, 0.0f, -90.0f);
// h.getTransform().updateScale(0.1f);

addModelInstance(h);

StaticModelInstance littleSister = new StaticModelInstance(ResourceLoader.model("LS"));
littleSister.getTransform().updateScale(0.06f);
addModelInstance(littleSister);
//*
int lsc = 4;
float lsr = 12.0f;
Vector3 ht = h.getTransform().getTranslate();
Vector2 lsCenter = new Vector2(ht.x, ht.z);
float ls_angle = (float) Math.PI * 2.0f / lsc;
for(int i = 0; i < lsc; ++i) {
StaticModelInstance ladySmith = new StaticModelInstance(ResourceLoader.model("LS"));
ladySmith.getTransform().updateScale(0.037f);
ladySmith.getTransform().updateTranslate(
(float) -Math.cos(i * ls_angle) * lsr + lsCenter.x,
-12.0f,
(float) Math.sin(i * ls_angle) * lsr + lsCenter.y);

ladySmith.getTransform().updateRotation(0.0f, 1.0f, 0.0f, (float) Math.random() * 360);

addModelInstance(ladySmith);
}
//*/

floor = new StaticModelInstance(ModelLoader.buildPlane(
100.0f, 100.0f, 10, 10));
Expand Down Expand Up @@ -124,7 +138,7 @@ public void init(GLAutoDrawable drawable) {

int mlim = 2;
float mGrid = 2.5f;
//*
/*
for (int i = -mlim; i < mlim; ++i) {
for (int j = -mlim; j < mlim; ++j) {
Material mat = new BasicMaterial(Color.random());
Expand All @@ -147,13 +161,13 @@ public void init(GLAutoDrawable drawable) {
nessie.setDirectionalShadowDepth(new Vector2(-80, 150));

//*
int lightLim = 3;
float lgs = 18.0f;
int lightLim = 2;
float lightGridSize = 18.0f;
for(int i = -lightLim; i < lightLim; ++i) {
for(int j = -lightLim; j < lightLim; ++j) {
Color c = Color.random();
c.a = 16.0f;
PointLight light = new PointLight(new Vector3(i * lgs, -6.0f, j * lgs), c);
PointLight light = new PointLight(new Vector3(i * lightGridSize, -6.0f, j * lightGridSize), c);
light.setAttenuation(0.0f, 0.0f, 1.5f);
lights.add(light);
}
Expand Down

0 comments on commit 0bc130b

Please sign in to comment.