- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticMeshLoader.java
More file actions
Latest commit
127 lines (107 loc) · 4 KB
/
Copy pathStaticMeshLoader.java
File metadata and controls
127 lines (107 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// from https://github.com/steelswing/assimp4j-52
importjassimp.AiMaterial;
importjassimp.AiMesh;
importjassimp.AiPostProcessSteps;
importjassimp.AiScene;
importjassimp.IHMCJassimp;
importjava.io.File;
importjava.io.IOException;
importjava.util.ArrayList;
importjava.util.HashSet;
importjava.util.List;
importjava.util.Set;
/**
* Copied from https://github.com/steelswing/assimp4j-52
* File: StaticMeshLoader.java
* Created on 30.12.2023, 2:35:16
*
* @author LWJGL2
*/
publicclassStaticMeshLoader {
publicstaticfinalSet<AiPostProcessSteps> ASSIMP_POST = newHashSet<AiPostProcessSteps>() {
{
add(AiPostProcessSteps.Triangulate);
add(AiPostProcessSteps.GenSmoothNormals);
add(AiPostProcessSteps.GenUVCoords);
add(AiPostProcessSteps.FlipUVs);
add(AiPostProcessSteps.CalcTangentSpace);
add(AiPostProcessSteps.JoinIdenticalVertices);
add(AiPostProcessSteps.OptimizeMeshes);
}
};
publicstaticList<Mesh> load(FilefilePath) throwsIOException {
List<Mesh> meshes = newArrayList<>();
AiScenescene = IHMCJassimp.importFile(filePath.getPath(), ASSIMP_POST);
for (AiMeshmesh : scene.getMeshes()) {
meshes.add(loadData(mesh, null));
}
returnmeshes;
}
privatestaticMeshloadData(AiMeshmesh, AiMaterialmaterial) {
float[] vertices = newfloat[mesh.getNumVertices() * 3];
float[] textureCoords = newfloat[mesh.getNumVertices() * 2];
float[] normals = newfloat[mesh.getNumVertices() * 3];
int[] indices = newint[mesh.getNumFaces() * 3];
intcounter = 0;
for (intv = 0; v < mesh.getNumVertices(); v++) {
vertices[counter++] = mesh.getPositionX(v);
vertices[counter++] = mesh.getPositionY(v);
vertices[counter++] = mesh.getPositionZ(v);
}
counter = 0;
for (intt = 0; t < mesh.getNumVertices(); t++) {
textureCoords[counter++] = mesh.getTexCoordU(t, 0);
textureCoords[counter++] = mesh.getTexCoordV(t, 0);
}
counter = 0;
for (intn = 0; n < mesh.getNumVertices(); n++) {
normals[counter++] = mesh.getNormalX(n);
normals[counter++] = mesh.getNormalY(n);
normals[counter++] = mesh.getNormalZ(n);
}
counter = 0;
for (intf = 0; f < mesh.getNumFaces(); f++) {
indices[counter++] = mesh.getFaceVertex(f, 0);
indices[counter++] = mesh.getFaceVertex(f, 1);
indices[counter++] = mesh.getFaceVertex(f, 2);
}
returnnewMesh(vertices, textureCoords, normals, indices, 0, material);
}
publicstaticclassMesh {
protectedAiMaterialmaterial;
protectedfloat[] vertices;
protectedfloat[] textureCoords;
protectedfloat[] normals;
protectedint[] indices;
protectedfloatfurthestPoint;
publicMesh(float[] vertices, float[] textureCoords, float[] normals, int[] indices, floatfurthestPoint, AiMaterialmaterial) {
this.vertices = vertices;
this.textureCoords = textureCoords;
this.normals = normals;
this.indices = indices;
this.furthestPoint = furthestPoint;
this.material = material;
}
publicMesh(float[] vertices, float[] textureCoords, float[] normals, int[] indices, floatfurthestPoint) {
this(vertices, textureCoords, normals, indices, furthestPoint, null);
}
publicfloat[] getVertices() {
returnvertices;
}
publicfloat[] getTextureCoords() {
returntextureCoords;
}
publicfloat[] getNormals() {
returnnormals;
}
publicint[] getIndices() {
returnindices;
}
publicfloatgetFurthestPoint() {
returnfurthestPoint;
}
publicAiMaterialgetMaterial() {
returnmaterial;
}
}
}