add clamping and tiny offsetting to uv coordinates... rendering tiny bit more correctly
This commit is contained in:
parent
324a081fc9
commit
a62577234e
|
@ -1,5 +1,6 @@
|
||||||
package com.danitheskunk.skunkworks;
|
package com.danitheskunk.skunkworks;
|
||||||
|
|
||||||
|
import com.danitheskunk.skunkworks.gfx.IRenderContext;
|
||||||
import com.danitheskunk.skunkworks.gfx.ITexture;
|
import com.danitheskunk.skunkworks.gfx.ITexture;
|
||||||
import com.danitheskunk.skunkworks.gfx.Image;
|
import com.danitheskunk.skunkworks.gfx.Image;
|
||||||
import com.danitheskunk.skunkworks.gfx.threedee.IRenderContext3D;
|
import com.danitheskunk.skunkworks.gfx.threedee.IRenderContext3D;
|
||||||
|
@ -10,6 +11,7 @@ import java.nio.IntBuffer;
|
||||||
|
|
||||||
public class Test3D extends BaseGame {
|
public class Test3D extends BaseGame {
|
||||||
private Mesh[] meshes;
|
private Mesh[] meshes;
|
||||||
|
private ITexture dtex;
|
||||||
|
|
||||||
public Test3D() {
|
public Test3D() {
|
||||||
super(new Vec2i(1920, 1080), "Skunkworks 3d test");
|
super(new Vec2i(1920, 1080), "Skunkworks 3d test");
|
||||||
|
@ -20,9 +22,11 @@ public class Test3D extends BaseGame {
|
||||||
);
|
);
|
||||||
var path = "C:\\stream\\models\\Dani.glb";
|
var path = "C:\\stream\\models\\Dani.glb";
|
||||||
//path = "C:\\stream\\models\\Amber_Arakada_V5_Blendshape.glb";
|
//path = "C:\\stream\\models\\Amber_Arakada_V5_Blendshape.glb";
|
||||||
|
//path = "C:\\stream\\models\\Temp Chan 3.glb";
|
||||||
var bytes = engine.loadBytes(path);
|
var bytes = engine.loadBytes(path);
|
||||||
var flags = Assimp.aiProcess_Triangulate;
|
var flags = Assimp.aiProcess_Triangulate;
|
||||||
flags |= Assimp.aiProcess_OptimizeGraph;
|
//flags |= Assimp.aiProcess_FixInfacingNormals;
|
||||||
|
//flags |= Assimp.aiProcess_OptimizeGraph;
|
||||||
flags |= Assimp.aiProcess_PreTransformVertices;
|
flags |= Assimp.aiProcess_PreTransformVertices;
|
||||||
//flags |= Assimp.aiProcess_OptimizeMeshes;
|
//flags |= Assimp.aiProcess_OptimizeMeshes;
|
||||||
//flags |= Assimp.aiProcess_Debone;
|
//flags |= Assimp.aiProcess_Debone;
|
||||||
|
@ -90,6 +94,7 @@ public class Test3D extends BaseGame {
|
||||||
faces += aiMesh.mNumFaces();
|
faces += aiMesh.mNumFaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dtex = meshes[14].getTexture();
|
||||||
|
|
||||||
|
|
||||||
//window.setDebug(true);
|
//window.setDebug(true);
|
||||||
|
@ -105,11 +110,17 @@ public class Test3D extends BaseGame {
|
||||||
new Test3D().run();
|
new Test3D().run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void render(IRenderContext rc) {
|
||||||
|
//rc.drawTexture(Vec2i.ZERO, dtex);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void render3D(IRenderContext3D rc) {
|
protected void render3D(IRenderContext3D rc) {
|
||||||
for(int i = 0; i < meshes.length; ++i) {
|
for(int i = 0; i < meshes.length; ++i) {
|
||||||
rc.renderMesh(meshes[i]);
|
rc.renderMesh(meshes[i]);
|
||||||
}
|
}
|
||||||
|
//rc.renderMesh(meshes[14]);
|
||||||
/*
|
/*
|
||||||
rc.renderTriangle(new Vec3f(-10, -10, 1),
|
rc.renderTriangle(new Vec3f(-10, -10, 1),
|
||||||
new Vec3f(10, -10, 1),
|
new Vec3f(10, -10, 1),
|
||||||
|
|
|
@ -8,8 +8,8 @@ import com.danitheskunk.skunkworks.gfx.threedee.Mesh;
|
||||||
import static org.lwjgl.opengl.GL46.*;
|
import static org.lwjgl.opengl.GL46.*;
|
||||||
|
|
||||||
public class RenderContext3D extends BaseRenderContext3D {
|
public class RenderContext3D extends BaseRenderContext3D {
|
||||||
private TextureAtlas textureAtlas;
|
|
||||||
private final int texCoordIndex;
|
private final int texCoordIndex;
|
||||||
|
private TextureAtlas textureAtlas;
|
||||||
|
|
||||||
public RenderContext3D(int texCoordIndex) {
|
public RenderContext3D(int texCoordIndex) {
|
||||||
this.texCoordIndex = texCoordIndex;
|
this.texCoordIndex = texCoordIndex;
|
||||||
|
@ -34,6 +34,26 @@ public class RenderContext3D extends BaseRenderContext3D {
|
||||||
var t1 = mesh.getUV(tri.getX());
|
var t1 = mesh.getUV(tri.getX());
|
||||||
var t2 = mesh.getUV(tri.getY());
|
var t2 = mesh.getUV(tri.getY());
|
||||||
var t3 = mesh.getUV(tri.getZ());
|
var t3 = mesh.getUV(tri.getZ());
|
||||||
|
|
||||||
|
assert (t1.getX() >= 0.0 && t1.getX() <= 1.0);
|
||||||
|
assert (t1.getY() >= 0.0 && t1.getY() <= 1.0);
|
||||||
|
assert (t2.getX() >= 0.0 && t2.getX() <= 1.0);
|
||||||
|
assert (t2.getY() >= 0.0 && t2.getY() <= 1.0);
|
||||||
|
assert (t3.getX() >= 0.0 && t3.getX() <= 1.0);
|
||||||
|
assert (t3.getY() >= 0.0 && t3.getY() <= 1.0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
t1 = new Vec2f(t1.getX() * 0.8 + 0.1,
|
||||||
|
t1.getY() * 0.8 + 0.1
|
||||||
|
);
|
||||||
|
t2 = new Vec2f(t2.getX() * 0.8 + 0.1,
|
||||||
|
t2.getY() * 0.8 + 0.1
|
||||||
|
);
|
||||||
|
t3 = new Vec2f(t3.getX() * 0.8 + 0.1,
|
||||||
|
t3.getY() * 0.8 + 0.1
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
//t1 = new Vec2f(t1.getX(), 1.0 - t1.getY());
|
//t1 = new Vec2f(t1.getX(), 1.0 - t1.getY());
|
||||||
//t2 = new Vec2f(t2.getX(), 1.0 - t2.getY());
|
//t2 = new Vec2f(t2.getX(), 1.0 - t2.getY());
|
||||||
//t3 = new Vec2f(t3.getX(), 1.0 - t3.getY());
|
//t3 = new Vec2f(t3.getX(), 1.0 - t3.getY());
|
||||||
|
@ -41,6 +61,9 @@ public class RenderContext3D extends BaseRenderContext3D {
|
||||||
t2 = Vec2f.add(texOff, Vec2f.mul(texMult, t2));
|
t2 = Vec2f.add(texOff, Vec2f.mul(texMult, t2));
|
||||||
t3 = Vec2f.add(texOff, Vec2f.mul(texMult, t3));
|
t3 = Vec2f.add(texOff, Vec2f.mul(texMult, t3));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glVertexAttrib2d(texCoordIndex, t1.getX(), t1.getY());
|
glVertexAttrib2d(texCoordIndex, t1.getX(), t1.getY());
|
||||||
glVertex3d(p1.getX(), p1.getY() - 0.5, p1.getZ() + 0.5);
|
glVertex3d(p1.getX(), p1.getY() - 0.5, p1.getZ() + 0.5);
|
||||||
glVertexAttrib2d(texCoordIndex, t2.getX(), t2.getY());
|
glVertexAttrib2d(texCoordIndex, t2.getX(), t2.getY());
|
||||||
|
|
|
@ -48,7 +48,9 @@ public class Mesh {
|
||||||
|
|
||||||
while(texCoordsBuffer.remaining() > 0) {
|
while(texCoordsBuffer.remaining() > 0) {
|
||||||
var uv = texCoordsBuffer.get();
|
var uv = texCoordsBuffer.get();
|
||||||
mesh.addUV(new Vec2f(uv.x(), 1.0 - uv.y()));
|
var x = Math.max(0.0001, Math.min(uv.x(), 0.9999));
|
||||||
|
var y = Math.max(0.0001, Math.min(uv.y(), 0.9999));
|
||||||
|
mesh.addUV(new Vec2f(x, 1.0 - y));
|
||||||
}
|
}
|
||||||
|
|
||||||
return mesh;
|
return mesh;
|
||||||
|
|
Loading…
Reference in New Issue