Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug Bad rotation values for Terrain DetailInstanceTransform via ComputeDetailInstanceTransforms

Discussion in 'World Building' started by sachaamm, Sep 27, 2023.

  1. sachaamm

    sachaamm

    Joined:
    Apr 11, 2016
    Posts:
    46
    Hi ! i get bad rotation values using the terrain data method called "ComputeDetailInstanceTransforms" which is supposed to return me the transform, including rotationY of my detail object in the terrain. attaching these values give me incoherent results, the detail object position is correct but the DetailInstanceTransform.rotationY value is mismatching what is used to render the detail object. Am i missing something ? I tried to adjust the rotation with a defined offset, but offsets in results are not identical, which makes me wondering what i'm doing wrong. Here is the code i used :

    Code (CSharp):
    1.  
    2.  
    3. int detailPatchCount = terrain.terrainData.detailPatchCount;
    4.            
    5.             for (int x = 0; x < detailPatchCount; x++)
    6.             {
    7.                 for (int y = 0; y < detailPatchCount; y++)
    8.                 {
    9.                     DetailInstanceTransform[] detailsTransforms =
    10.                         data.ComputeDetailInstanceTransforms(x, y, detailPrototype, 1, out Bounds bounds);
    11.                    
    12.                     foreach (var dt in detailsTransforms)
    13.                     {
    14.                         DetailedObjectInstance dti = new();
    15.                         dti.Prefab = data.detailPrototypes[detailPrototype].prototype;
    16.                         dti.Position = new Vector3(dt.posX, dt.posY, dt.posZ);
    17.                         dti.Rotation = new Vector3(0, dt.rotationY * Mathf.Rad2Deg, 0);
    18.                         dti.RotationY = dt.rotationY;
    19.                         dti.Scale = new Vector3(dt.scaleXZ, dt.scaleY, dt.scaleXZ);
    20.                         dti.PrototypeIndex = detailPrototype;
    21.                        
    22.                         output.Add(dti);
    23.                     }
    24.                 }
    25.  
    26. // Later... After getting detail instances data
    27.  
    28. // Instantiating a collider regarding the detail transform data
    29. GameObject detailColliderGo = Instantiate(navColliderPrefab, t, true);
    30. detailColliderGo.transform.position = detailInstance.Position;
    31. detailColliderGo.transform.rotation = Quaternion.Euler(detailInstance.Rotation); // Incorrect rotation value
    32. detailColliderGo.transform.localScale = detailInstance.Scale;
    33. detailColliderGo.transform.name = detailInstance.Rotation.ToString() + " " + detailInstance.RotationY;
    34.             }
     

    Attached Files:

  2. sachaamm

    sachaamm

    Joined:
    Apr 11, 2016
    Posts:
    46
    This is a bug due to Nature Renderer, overriding vegetation rendering