started adding bone stuff

This commit is contained in:
DaniTheSkunk 2022-12-12 02:06:58 +00:00
parent db610763ac
commit 007be3e9f3
7 changed files with 141 additions and 8 deletions

View File

@ -1,8 +1,12 @@
package com.danitheskunk.skunkworks;
import org.lwjgl.assimp.AIMatrix4x4;
public final class Mat4f {
private final double[] data;
public static Mat4f IDENTITY = new Mat4f();
public Mat4f() {
data = new double[16];
set(0, 0, 1.0);
@ -11,6 +15,32 @@ public final class Mat4f {
set(3, 3, 1.0);
}
public static Mat4f fromAiMat(AIMatrix4x4 aiMat) {
var mat = new Mat4f();
mat.set(0, 0, aiMat.a1());
mat.set(1, 0, aiMat.a2());
mat.set(2, 0, aiMat.a3());
mat.set(3, 0, aiMat.a4());
mat.set(0, 1, aiMat.b1());
mat.set(1, 1, aiMat.b2());
mat.set(2, 1, aiMat.b3());
mat.set(3, 1, aiMat.b4());
mat.set(0, 2, aiMat.c1());
mat.set(1, 2, aiMat.c2());
mat.set(2, 2, aiMat.c3());
mat.set(3, 2, aiMat.c4());
mat.set(0, 3, aiMat.d1());
mat.set(1, 3, aiMat.d2());
mat.set(2, 3, aiMat.d3());
mat.set(3, 3, aiMat.d4());
return mat;
}
public static Mat4f perspective(
double fovy, double aspect, double zNear, double zFar
) {

View File

@ -15,14 +15,6 @@ public class Test extends BaseGame {
public Test() {
super(new Vec2i(40 * 12, 22 * 12), "Skunkworks");
var path = "C:\\Program Files (x86)" +
"\\Steam\\steamapps\\common\\Unreal " +
"Tournament\\System\\UnrealTournament.ini";
var data = engine.loadDataWatched(path);
data.onReload(() -> System.out.println(data.get("URL", "Host")));
var fontThin = window.loadFontTileset("fonts\\thin-6x12.png");
var fontThin2 = window.loadFontTileset("fonts\\thin-12x12.png");
term = new Terminal(new Vec2i(40, 22), fontThin2, fontThin);

View File

@ -0,0 +1,5 @@
package com.danitheskunk.skunkworks.backends.gl;
public class BasePipeline {
}

View File

@ -0,0 +1,47 @@
package com.danitheskunk.skunkworks.gfx.threedee;
import com.danitheskunk.skunkworks.Mat4f;
import org.lwjgl.assimp.AIBone;
import java.util.ArrayList;
import java.util.List;
public class Bone {
private String name;
private List<VertexWeight> vertexWeights;
private Mat4f offsetMatrix;
public Bone() {
vertexWeights = new ArrayList<>();
offsetMatrix = Mat4f.IDENTITY;
}
public static Bone fromAIBone(AIBone aiBone) {
var bone = new Bone();
var weightBuffer = aiBone.mWeights();
bone.name = aiBone.mName().dataString();
while(weightBuffer.hasRemaining()) {
var weight = VertexWeight.fromAiWeight(weightBuffer.get());
bone.vertexWeights.add(weight);
}
bone.offsetMatrix = Mat4f.fromAiMat(aiBone.mOffsetMatrix());
var node = aiBone.mNode();
if(node.address() != 0) {
System.out.println(node.mName().dataString());
}
return bone;
}
public VertexWeight getVertexWeight(int i) {
return vertexWeights.get(i);
}
public int getVertexWeightCount() {
return vertexWeights.size();
}
}

View File

@ -4,6 +4,7 @@ import com.danitheskunk.skunkworks.Vec2f;
import com.danitheskunk.skunkworks.Vec3f;
import com.danitheskunk.skunkworks.Vec3i;
import com.danitheskunk.skunkworks.gfx.ITexture;
import org.lwjgl.assimp.AIBone;
import org.lwjgl.assimp.AIMesh;
import java.util.ArrayList;
@ -27,6 +28,7 @@ public class Mesh {
var vertexBuffer = aiMesh.mVertices();
var faceBuffer = aiMesh.mFaces();
var texCoordsBuffer = aiMesh.mTextureCoords(0);
var boneBuffer = aiMesh.mBones();
while(vertexBuffer.remaining() > 0) {
var vert = vertexBuffer.get();
@ -51,6 +53,13 @@ public class Mesh {
mesh.addUV(new Vec2f(x, 1.0 - y));
}
while(boneBuffer.remaining() > 0) {
var aiBone = AIBone.create(boneBuffer.get());
var bone = Bone.fromAIBone(aiBone);
//System.out.printf("bone: %s\n", bone.mName().dataString());
}
return mesh;
}

View File

@ -58,6 +58,9 @@ public class Model {
System.out.printf("tex %dx%d\n", img.getWidth(), img.getHeight());
}
var node = ai.mRootNode();
walkNodes(node);
var numMeshes = ai.mNumMeshes();
var meshPB = ai.mMeshes();
@ -75,6 +78,16 @@ public class Model {
faces += aiMesh.mNumFaces();
}
/*
var animationBuffer = ai.mAnimations();
while(animationBuffer.hasRemaining()) {
var aiAnim = AIAnimation.create(animationBuffer.get());
System.out.printf("anim: %s\n", aiAnim.mName().dataString());
}
*/
//window.setDebug(true);
System.out.printf("numMeshes: %d, faces: %d, textures: %d\n",
@ -84,6 +97,18 @@ public class Model {
);
}
private void walkNodes(AINode node) {
System.out.println(node.mName().dataString());
var childBuffer = node.mChildren();
if(childBuffer == null) {
return;
}
while(childBuffer.hasRemaining()) {
var child = AINode.create(childBuffer.get());
walkNodes(child);
}
}
public int getMeshCount() {
return meshes.length;
}

View File

@ -0,0 +1,25 @@
package com.danitheskunk.skunkworks.gfx.threedee;
import org.lwjgl.assimp.AIVertexWeight;
public class VertexWeight {
private final int index;
private final float weight;
public VertexWeight(int index, float weight) {
this.index = index;
this.weight = weight;
}
public static VertexWeight fromAiWeight(AIVertexWeight aiWeight) {
return new VertexWeight(aiWeight.mVertexId(), aiWeight.mWeight());
}
public int getIndex() {
return index;
}
public float getWeight() {
return weight;
}
}