@@ -117,7 +117,45 @@ Let's review the code of the `mainProcessing` method first:
117117public class ModelGenerator {
118118 ...
119119 private void mainProcessing () throws IOException {
120- ...
120+ Logger . debug(" Loading model data [{}]" , modelPath);
121+ var modelFile = new File (modelPath);
122+ if (! modelFile. exists()) {
123+ throw new RuntimeException (" Model path does not exist [" + modelPath + " ]" );
124+ }
125+
126+ AIScene aiScene = aiImportFile(modelPath, FLAGS );
127+ if (aiScene == null ) {
128+ throw new RuntimeException (" Error loading model [modelPath: " + modelPath + " ]" );
129+ }
130+
131+ String modelId = modelFile. getName();
132+ if (modelId. contains(" ." )) {
133+ modelId = modelId. substring(0 , modelId. lastIndexOf(' .' ));
134+ }
135+
136+ ModelBinData modelBinData = new ModelBinData (modelPath);
137+
138+ int numMaterials = aiScene. mNumMaterials();
139+ Logger . debug(" Number of materials: {}" , numMaterials);
140+ List<MaterialData > matList = new ArrayList<> ();
141+ File parentDirectory = modelFile. getParentFile();
142+ for (int i = 0 ; i < numMaterials; i++ ) {
143+ var aiMaterial = AIMaterial . create(aiScene. mMaterials(). get(i));
144+ MaterialData material = processMaterial(aiScene, aiMaterial, modelId, parentDirectory. getPath(), i);
145+ matList. add(material);
146+ }
147+
148+ int numMeshes = aiScene. mNumMeshes();
149+ PointerBuffer aiMeshes = aiScene. mMeshes();
150+ List<MeshData > meshList = new ArrayList<> ();
151+ for (int i = 0 ; i < numMeshes; i++ ) {
152+ AIMesh aiMesh = AIMesh . create(aiMeshes. get(i));
153+ MeshData meshData = processMesh(aiMesh, matList, i, modelBinData);
154+ meshList. add(meshData);
155+ }
156+
157+ var model = new ModelData (modelId, meshList, modelBinData. getVtxFilePath(), modelBinData. getIdxFilePath());
158+
121159 String outModelFile = modelPath. substring(0 , modelPath. lastIndexOf(' .' )) + " .json" ;
122160 Writer writer = new FileWriter (outModelFile);
123161 var gson = new GsonBuilder (). setFieldNamingPolicy(FieldNamingPolicy . LOWER_CASE_WITH_UNDERSCORES ). setPrettyPrinting(). create();
0 commit comments