@@ -228,10 +228,10 @@ private void TriggerAllCabback()
228228 private void CacheTreeImporterValues ( string assetPath )
229229 {
230230 // Variables used a lot are cached, since accessing any Reader array has a non-negligeable cost.
231+ m_LODCount = ( uint ) m_Tree . Lod . Length ;
231232 m_HasFacingData = TreeHasFacingData ( ) ;
232233 m_HasBranch2Data = m_Tree . Wind . DoBranch2 ;
233234 m_LastLodIsBillboard = m_Tree . BillboardInfo . LastLodIsBillboard ;
234- m_LODCount = ( uint ) m_Tree . Lod . Length ;
235235 m_CollisionObjectsCount = ( uint ) m_Tree . CollisionObjects . Length ;
236236
237237 WindConfigSDK windCfg = m_Tree . Wind ;
@@ -349,13 +349,13 @@ private Mesh CreateMeshAndGeometry(Lod lod, int lodIndex)
349349
350350 if ( ! isBillboard )
351351 {
352- if ( m_HasBranch2Data || m_HasFacingData )
352+ if ( m_HasBranch2Data || m_HasFacingData ) // If Branch2 is available:
353353 {
354- mesh . SetUVs ( 2 , sTMeshGeometry . uvs [ 2 ] ) ;
354+ mesh . SetUVs ( 2 , sTMeshGeometry . uvs [ 2 ] ) ; // Branch2Pos, Branch2Dir, Branch2Weight, <Unused>
355355 }
356- if ( m_HasBranch2Data && m_HasFacingData )
356+ if ( m_HasBranch2Data && m_HasFacingData ) // If camera-facing geom is available:
357357 {
358- mesh . SetUVs ( 3 , sTMeshGeometry . uvs [ 3 ] ) ;
358+ mesh . SetUVs ( 3 , sTMeshGeometry . uvs [ 3 ] ) ; // 2/3 Anchor XYZ, FacingFlag
359359 }
360360 }
361361
@@ -405,17 +405,12 @@ private void CalculateMeshGeometry(STMeshGeometry sTMeshGeometry, Lod lod, bool
405405 STVertex vertex = vertices [ i ] ;
406406
407407 sTMeshGeometry . vertices [ i ] . Set (
408- vertex . Anchor . X + vertex . Offset . X ,
408+ vertex . Anchor . X + ( vertex . CameraFacing ? - vertex . Offset . X : vertex . Offset . X ) ,
409409 vertex . Anchor . Y + vertex . Offset . Y ,
410410 vertex . Anchor . Z + vertex . Offset . Z ) ;
411411
412412 sTMeshGeometry . vertices [ i ] *= m_MeshSettings . scaleFactor ;
413413
414- if ( vertex . CameraFacing )
415- {
416- sTMeshGeometry . vertices [ i ] . x = vertex . Anchor . X - vertex . Offset . X ;
417- }
418-
419414 sTMeshGeometry . normals [ i ] . Set ( vertex . Normal . X , vertex . Normal . Y , vertex . Normal . Z ) ;
420415
421416 Vector3 vertexTangent = new Vector3 ( vertex . Tangent . X , vertex . Tangent . Y , vertex . Tangent . Z ) ;
@@ -1264,6 +1259,7 @@ bool RippleHasAllCurvesValid(in WindRipple r)
12641259 // st9
12651260 cfg . branch1StretchLimit = wind . Branch1StretchLimit * scaleFactor ;
12661261 cfg . branch2StretchLimit = wind . Branch2StretchLimit * scaleFactor ;
1262+ cfg . importScale = scaleFactor ;
12671263 cfg . treeExtentX = ( treeBounds . Max . X - treeBounds . Min . X ) * scaleFactor ;
12681264 cfg . treeExtentY = ( treeBounds . Max . Y - treeBounds . Min . Y ) * scaleFactor ;
12691265 cfg . treeExtentZ = ( treeBounds . Max . Z - treeBounds . Min . Z ) * scaleFactor ;
@@ -1277,7 +1273,7 @@ bool RippleHasAllCurvesValid(in WindRipple r)
12771273 CopyCurve ( shared . Turbulence , cfg . turbulenceShared ) ;
12781274 CopyCurve ( shared . Flexibility , cfg . flexibilityShared ) ;
12791275 cfg . independenceShared = shared . Independence ;
1280- cfg . sharedHeightStart = wind . SharedStartHeight * scaleFactor ;
1276+ cfg . sharedHeightStart = wind . SharedStartHeight ; // this is a % value
12811277 if ( BranchHasAllCurvesValid ( in shared ) )
12821278 {
12831279 cfg . doShared = 1 ;
@@ -1347,29 +1343,25 @@ private void SetWindParameters(ref SpeedTreeWindConfig9 cfg)
13471343 #region Others
13481344 private void CalculateScaleFactorFromUnit ( )
13491345 {
1350- float scaleFactor = m_MeshSettings . scaleFactor ;
1351-
13521346 switch ( m_MeshSettings . unitConversion )
13531347 {
13541348 // Use units in the imported file without any conversion.
13551349 case STUnitConversion . kLeaveAsIs :
1356- scaleFactor = 1.0f ;
1350+ m_MeshSettings . scaleFactor = 1.0f ;
13571351 break ;
13581352 case STUnitConversion . kFeetToMeters :
1359- scaleFactor = SpeedTreeConstants . kFeetToMetersRatio ;
1353+ m_MeshSettings . scaleFactor = SpeedTreeConstants . kFeetToMetersRatio ;
13601354 break ;
13611355 case STUnitConversion . kCentimetersToMeters :
1362- scaleFactor = SpeedTreeConstants . kCentimetersToMetersRatio ;
1356+ m_MeshSettings . scaleFactor = SpeedTreeConstants . kCentimetersToMetersRatio ;
13631357 break ;
13641358 case STUnitConversion . kInchesToMeters :
1365- scaleFactor = SpeedTreeConstants . kInchesToMetersRatio ;
1359+ m_MeshSettings . scaleFactor = SpeedTreeConstants . kInchesToMetersRatio ;
13661360 break ;
13671361 case STUnitConversion . kCustomConversion :
13681362 /* no-op */
13691363 break ;
13701364 }
1371-
1372- m_MeshSettings . scaleFactor = scaleFactor ;
13731365 }
13741366
13751367 private bool TreeHasFacingData ( )
0 commit comments