Browse Source

Adding bone support

master
Gauvain Roussel-Tarbouriech 1 year ago
parent
commit
4caa4e9a75
1 changed files with 34 additions and 4 deletions
  1. 34
    4
      obj2kh2v.cpp

+ 34
- 4
obj2kh2v.cpp View File

@@ -36,6 +36,7 @@ int main(int argc, char* argv[]){
36 36
     std::string line;
37 37
 
38 38
     std::vector<std::string> dsm_mem;
39
+    std::vector<int> bones;
39 40
     dsm_mem.push_back(".align 0");
40 41
     line = ";";
41 42
     line+=argv[1];
@@ -96,6 +97,24 @@ int main(int argc, char* argv[]){
96 97
     input.clear();
97 98
     input.seekg(0, std::ios::beg);
98 99
 
100
+    while (getline(input, line))
101
+    {
102
+        if (line.substr(0,3) == "vb ")
103
+        {
104
+			std::istringstream s(line.substr(2));
105
+			int v;
106
+            s >> v;
107
+            bones.push_back(v);
108
+			printf("bone= %d\n", v);		
109
+		}
110
+
111
+	}
112
+    if(bones.size()==0){
113
+        bones.push_back(vertex_count);
114
+    }
115
+    input.clear();
116
+    input.seekg(0, std::ios::beg);
117
+
99 118
 
100 119
     // making temporary entries for uvs to insert later on
101 120
     int uv_pos=dsm_mem.size();
@@ -190,9 +209,20 @@ int main(int argc, char* argv[]){
190 209
     dsm_mem.push_back("stcycl 01, 01; We write code to memory without skips/overwrite");
191 210
     dsm_mem.push_back("");
192 211
     dsm_mem.push_back("unpack[r] V4_32, ,*; Vertex affiliation header");
212
+    printf("%lu", bones.size());
193 213
     vertex_affiliation = dsm_mem.size()-1;
194
-    line = ".int " + std::to_string(vertex_count) + ", 0, 0, 0";
195
-    dsm_mem.push_back(line);
214
+    for(int i=0; i<ceil(float(bones.size())/4); i++){
215
+        line = ".int " + std::to_string(bones[(i*4)]);
216
+        int z=1;
217
+        while((i*4)+z<bones.size() && z < 4){
218
+        line+= ", " + std::to_string(bones[(i*4)+z]);
219
+        z++;
220
+        }
221
+        for(z;z<4;z++){
222
+            line+=", 0";
223
+        }
224
+        dsm_mem.push_back(line);
225
+    }
196 226
     dsm_mem.push_back(".EndUnpack");
197 227
     dsm_mem.push_back("vifnop");
198 228
     dsm_mem.push_back("vifnop; We wait for data to be kicked in");
@@ -205,10 +235,10 @@ int main(int argc, char* argv[]){
205 235
 		//checked!
206 236
         
207 237
 
208
-        line=".int " + std::to_string(face_count*3) + ", 4, " + std::to_string(4+(face_count*3)+vertex_count) + ", " + std::to_string(4+(face_count*3)+vertex_count+1) + "; Number of u+v+flag+index, their offset, offset of vertex affiliation header, offset of mat definiti    on(end)";
238
+        line=".int " + std::to_string(face_count*3) + ", 4, " + std::to_string(4+(face_count*3)+vertex_count) + ", " + std::to_string(int(4+(face_count*3)+vertex_count+ceil(float(bones.size())/4))) + "; Number of u+v+flag+index, their offset, offset of vertex affiliation header, offset of mat definition(end)";
209 239
         dsm_mem[tmpheader]=line;
210 240
         dsm_mem[tmpheader+1]=".int 0, 0, 0, 0; Nobody care about vertices merging and colors";
211
-        line=".int " + std::to_string(vertex_count) + ", " + std::to_string(4+(face_count*3)) + ", 0, 1; Number of vertices, their offset, reserved and number of array attribution";
241
+        line=".int " + std::to_string(vertex_count) + ", " + std::to_string(4+(face_count*3)) + ", 0, " + std::to_string(bones.size()) + "; Number of vertices, their offset, reserved and number of array attribution";
212 242
         dsm_mem[tmpheader+2]=line;
213 243
         line="unpack[mr] V3_32, " + std::to_string(4+(face_count*3)) + ", *; Vertex definition";
214 244
         dsm_mem[vertices_arg]=line;

Loading…
Cancel
Save