@@ -228,10 +228,10 @@ private void TriggerAllCabback()
228
228
private void CacheTreeImporterValues ( string assetPath )
229
229
{
230
230
// Variables used a lot are cached, since accessing any Reader array has a non-negligeable cost.
231
+ m_LODCount = ( uint ) m_Tree . Lod . Length ;
231
232
m_HasFacingData = TreeHasFacingData ( ) ;
232
233
m_HasBranch2Data = m_Tree . Wind . DoBranch2 ;
233
234
m_LastLodIsBillboard = m_Tree . BillboardInfo . LastLodIsBillboard ;
234
- m_LODCount = ( uint ) m_Tree . Lod . Length ;
235
235
m_CollisionObjectsCount = ( uint ) m_Tree . CollisionObjects . Length ;
236
236
237
237
WindConfigSDK windCfg = m_Tree . Wind ;
@@ -349,13 +349,13 @@ private Mesh CreateMeshAndGeometry(Lod lod, int lodIndex)
349
349
350
350
if ( ! isBillboard )
351
351
{
352
- if ( m_HasBranch2Data || m_HasFacingData )
352
+ if ( m_HasBranch2Data || m_HasFacingData ) // If Branch2 is available:
353
353
{
354
- mesh . SetUVs ( 2 , sTMeshGeometry . uvs [ 2 ] ) ;
354
+ mesh . SetUVs ( 2 , sTMeshGeometry . uvs [ 2 ] ) ; // Branch2Pos, Branch2Dir, Branch2Weight, <Unused>
355
355
}
356
- if ( m_HasBranch2Data && m_HasFacingData )
356
+ if ( m_HasBranch2Data && m_HasFacingData ) // If camera-facing geom is available:
357
357
{
358
- mesh . SetUVs ( 3 , sTMeshGeometry . uvs [ 3 ] ) ;
358
+ mesh . SetUVs ( 3 , sTMeshGeometry . uvs [ 3 ] ) ; // 2/3 Anchor XYZ, FacingFlag
359
359
}
360
360
}
361
361
@@ -405,17 +405,12 @@ private void CalculateMeshGeometry(STMeshGeometry sTMeshGeometry, Lod lod, bool
405
405
STVertex vertex = vertices [ i ] ;
406
406
407
407
sTMeshGeometry . vertices [ i ] . Set (
408
- vertex . Anchor . X + vertex . Offset . X ,
408
+ vertex . Anchor . X + ( vertex . CameraFacing ? - vertex . Offset . X : vertex . Offset . X ) ,
409
409
vertex . Anchor . Y + vertex . Offset . Y ,
410
410
vertex . Anchor . Z + vertex . Offset . Z ) ;
411
411
412
412
sTMeshGeometry . vertices [ i ] *= m_MeshSettings . scaleFactor ;
413
413
414
- if ( vertex . CameraFacing )
415
- {
416
- sTMeshGeometry . vertices [ i ] . x = vertex . Anchor . X - vertex . Offset . X ;
417
- }
418
-
419
414
sTMeshGeometry . normals [ i ] . Set ( vertex . Normal . X , vertex . Normal . Y , vertex . Normal . Z ) ;
420
415
421
416
Vector3 vertexTangent = new Vector3 ( vertex . Tangent . X , vertex . Tangent . Y , vertex . Tangent . Z ) ;
@@ -1264,6 +1259,7 @@ bool RippleHasAllCurvesValid(in WindRipple r)
1264
1259
// st9
1265
1260
cfg . branch1StretchLimit = wind . Branch1StretchLimit * scaleFactor ;
1266
1261
cfg . branch2StretchLimit = wind . Branch2StretchLimit * scaleFactor ;
1262
+ cfg . importScale = scaleFactor ;
1267
1263
cfg . treeExtentX = ( treeBounds . Max . X - treeBounds . Min . X ) * scaleFactor ;
1268
1264
cfg . treeExtentY = ( treeBounds . Max . Y - treeBounds . Min . Y ) * scaleFactor ;
1269
1265
cfg . treeExtentZ = ( treeBounds . Max . Z - treeBounds . Min . Z ) * scaleFactor ;
@@ -1277,7 +1273,7 @@ bool RippleHasAllCurvesValid(in WindRipple r)
1277
1273
CopyCurve ( shared . Turbulence , cfg . turbulenceShared ) ;
1278
1274
CopyCurve ( shared . Flexibility , cfg . flexibilityShared ) ;
1279
1275
cfg . independenceShared = shared . Independence ;
1280
- cfg . sharedHeightStart = wind . SharedStartHeight * scaleFactor ;
1276
+ cfg . sharedHeightStart = wind . SharedStartHeight ; // this is a % value
1281
1277
if ( BranchHasAllCurvesValid ( in shared ) )
1282
1278
{
1283
1279
cfg . doShared = 1 ;
@@ -1347,29 +1343,25 @@ private void SetWindParameters(ref SpeedTreeWindConfig9 cfg)
1347
1343
#region Others
1348
1344
private void CalculateScaleFactorFromUnit ( )
1349
1345
{
1350
- float scaleFactor = m_MeshSettings . scaleFactor ;
1351
-
1352
1346
switch ( m_MeshSettings . unitConversion )
1353
1347
{
1354
1348
// Use units in the imported file without any conversion.
1355
1349
case STUnitConversion . kLeaveAsIs :
1356
- scaleFactor = 1.0f ;
1350
+ m_MeshSettings . scaleFactor = 1.0f ;
1357
1351
break ;
1358
1352
case STUnitConversion . kFeetToMeters :
1359
- scaleFactor = SpeedTreeConstants . kFeetToMetersRatio ;
1353
+ m_MeshSettings . scaleFactor = SpeedTreeConstants . kFeetToMetersRatio ;
1360
1354
break ;
1361
1355
case STUnitConversion . kCentimetersToMeters :
1362
- scaleFactor = SpeedTreeConstants . kCentimetersToMetersRatio ;
1356
+ m_MeshSettings . scaleFactor = SpeedTreeConstants . kCentimetersToMetersRatio ;
1363
1357
break ;
1364
1358
case STUnitConversion . kInchesToMeters :
1365
- scaleFactor = SpeedTreeConstants . kInchesToMetersRatio ;
1359
+ m_MeshSettings . scaleFactor = SpeedTreeConstants . kInchesToMetersRatio ;
1366
1360
break ;
1367
1361
case STUnitConversion . kCustomConversion :
1368
1362
/* no-op */
1369
1363
break ;
1370
1364
}
1371
-
1372
- m_MeshSettings . scaleFactor = scaleFactor ;
1373
1365
}
1374
1366
1375
1367
private bool TreeHasFacingData ( )
0 commit comments