Skip to content

Commit 591f7b6

Browse files
author
Christopher Remde
committed
Small improvements to Converter
1 parent f0cf18a commit 591f7b6

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

Converter/Sequence_Converter.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,13 @@ def convert_model(self, file):
192192

193193
# For pointclouds, normals can be estimated
194194
if(self.convertSettings.generateNormals and self.convertSettings.isPointcloud):
195-
ms.compute_normal_for_point_clouds(k = 10, flipflag = False)
195+
ms.compute_normal_for_point_clouds(k = 10, flipflag = False, smoothiter = 10)
196196
normals = ms.current_mesh().vertex_normal_matrix().astype(np.float32)
197197

198+
#Pointcloud normal estimation leads to randomly flipped normals between frames
199+
200+
#To counteract this, we calculate the average normal direction of the pointcloud, and then compare it to the
201+
#last frame's average normal
198202
averageNormal = [np.average(normals[:,0]), np.average(normals[:,1]), np.average(normals[:,2])]
199203

200204
if not self.firstEstimation:
@@ -203,7 +207,8 @@ def convert_model(self, file):
203207
v1_norm = averageNormal / np.linalg.norm(averageNormal)
204208
v2_norm = self.lastAverageNormal / np.linalg.norm(self.lastAverageNormal)
205209

206-
# Compute the dot product
210+
# The dot product let's us know how if the average normals point in the same direction
211+
# (-1 for opposite, 1 for same direction)
207212
dot_product = np.dot(v1_norm, v2_norm)
208213

209214
#Flip normals if the average normal differs too much from the last frame
@@ -310,7 +315,7 @@ def convert_model(self, file):
310315

311316
byteCombination = []
312317

313-
#Flip vertices and bytes to match Unity's coordinate system
318+
#Flip vertice positions and normals to match Unity's coordinate system
314319
vertices[:,0] *= -1
315320
normals[:,0] *= -1
316321

Converter/Sequence_Metadata.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MetaData():
2121
hasNormals = False
2222
maxVertexCount = 0
2323
maxIndiceCount = 0
24-
maxBounds = [0,0,0,0,0,0]
24+
minMaxBounds = [0,0,0,0,0,0]
2525
textureWidth = 0
2626
textureHeight = 0
2727
textureSizeDDS = 0
@@ -44,7 +44,7 @@ def get_as_dict(self):
4444
"hasNormals" : self.hasNormals,
4545
"maxVertexCount": self.maxVertexCount,
4646
"maxIndiceCount" : self.maxIndiceCount,
47-
"maxBounds" : self.maxBounds,
47+
"maxBounds" : self.minMaxBounds,
4848
"textureWidth" : self.textureWidth,
4949
"textureHeight" : self.textureHeight,
5050
"textureSizeDDS" : self.textureSizeDDS,
@@ -71,12 +71,16 @@ def set_metadata_Model(self, vertexCount, indiceCount, headerSize, bounds, geome
7171
self.maxIndiceCount = indiceCount
7272

7373
for maxBound in range(3):
74-
if self.maxBounds[maxBound] < bounds.max()[maxBound]:
75-
self.maxBounds[maxBound] = bounds.max()[maxBound]
74+
if self.minMaxBounds[maxBound] < bounds.max()[maxBound]:
75+
self.minMaxBounds[maxBound] = bounds.max()[maxBound]
7676

7777
for minBound in range(3):
78-
if self.maxBounds[minBound + 3] > bounds.min()[minBound]:
79-
self.maxBounds[minBound + 3] = bounds.min()[minBound]
78+
if self.minMaxBounds[minBound + 3] > bounds.min()[minBound]:
79+
self.minMaxBounds[minBound + 3] = bounds.min()[minBound]
80+
81+
# Flip bounds x axis, as we also flip the model's x axis to match Unity's coordinate system
82+
self.minMaxBounds[0] *= -1 # Min X
83+
self.minMaxBounds[3] *= -1 # Max X
8084

8185
self.headerSizes[listIndex] = headerSize
8286
self.verticeCounts[listIndex] = vertexCount

0 commit comments

Comments
 (0)