Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. We are looking for your feedback about Templates! Tell us about your experiences by taking our survey.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[RELEASED] crossSection tool

Discussion in 'Assets and Asset Store' started by tomekkie2, Jan 21, 2014.

  1. zashour

    zashour

    Joined:
    Sep 18, 2019
    Posts:
    10
    I have tried the SectionSetup file but still I am getting the same errors.
     
  2. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    When does that happen?
    Is that during the build process?
     
  3. zashour

    zashour

    Joined:
    Sep 18, 2019
    Posts:
    10
    The problem has been fixed. I deleted the entire asset and import it again and then replaced the SectionSetup file.


    Thank you so much!!
     
    tomekkie2 likes this.
  4. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
  5. santos9991

    santos9991

    Joined:
    Oct 31, 2018
    Posts:
    14
    The version for HDRP the shaders are make with Shader graph?
     
  6. zashour

    zashour

    Joined:
    Sep 18, 2019
    Posts:
    10
    I would like to enable touching capability where the user can touch objects in the scene to retrieve object related information, however, when the object is sliced, I cannot touch the object at the section plane. I believe this is happening, because touching an object in the scene requires the raycast to hit the object's collider box, but when slicing the object, it does not cut through the collider box or change the collider box size.

    Is there a way to cut or change the collider box size according to the section plane?
     
    Last edited: Oct 15, 2020
  7. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    Yes, the cross-section shaders for the HDRP version are shader graphs. The asset contains modified versions of shader graphs included into the Universal RP package, including:
    Autodesk Interactive Masked
    Autodesk Interactive Transparent
    Autodesk Interactive
    PhysicalMaterial3DsMax
    PhysicalMaterial3DsMaxTransparent

    The shader used for section surface is a modified version of the HDRP/Unlit.
     
  8. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    I would cast a ray against the MeshCollider on the object and the section plane.

    If the ray hits the object at distance d1, check if it also hits the section plane.
    If it hits the section plane at distance d2 and point p2 and d2>d1, cast an opposite direction ray from the point p2 against the MeshCollider on the object.
    If the last ray does bring some result that means the section plane is beyond the object, if does not - means the plane cuts the object and p2 is your interaction point.
    Of course If your object is more complex and has more MeshColliders you have to take all of them into account.
     
  9. zashour

    zashour

    Joined:
    Sep 18, 2019
    Posts:
    10

    I am sorry, I don't get it. Can you elaborate more.
     
  10. CharlesCox44

    CharlesCox44

    Joined:
    Jul 17, 2017
    Posts:
    3
    Hello, our team recently bought this plugin, but I have one question. Right now, there are examples to cross section the model on ONE planar axis, either XY or Z. This is great but would it be possible to Crossection in multiple planar axis simultaneously? I couldn't find an example so I was curious if this is possible.
     
  11. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    Yes, it is possible.
    The asset contains examples with:
    - 2 intersecting planes (pie section),
    - 3 perpendicular planes (corner section) and
    - 6 planes (box section).
     
  12. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    I think the collider boxes or BoxCollider's are not of much use - unless your cross-section object just consist of boxes - if you like to touch or click the objects precisely.

    Following my suggestios here:
    you can get a result like on the .gif image below.
    (The cylinders are numbered from bottom to the top: Cylinder0, Cylinder1, Cylinder2, Cylinder3, Cylinder4)

    Untitled-3.gif
     
    Last edited: Oct 18, 2020
  13. zashour

    zashour

    Joined:
    Sep 18, 2019
    Posts:
    10
    That's exactly what we want to do. Can you please share the script you used?
     
  14. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    Code (CSharp):
    1.  
    2. using System;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6.  
    7. public class PlaneSectionInteraction : MonoBehaviour
    8. {
    9.     Collider[] objectColliders;
    10.     public Transform gizmo;
    11.     public Text info;
    12.     public Image mouseImg;
    13.     Color imgColor;
    14.  
    15.     void Start()
    16.     {
    17.         objectColliders = GetComponentsInChildren<Collider>();
    18.         imgColor = mouseImg.color;
    19.     }
    20.  
    21.     void Update()
    22.     {
    23.         if (Input.GetMouseButtonDown(0))
    24.         {
    25.             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    26.             mouseImg.rectTransform.position = Input.mousePosition;
    27.             imgColor.a = 1;
    28.             mouseImg.color = imgColor;
    29.             //Physics.queriesHitBackfaces = true;
    30.             RaycastHit[] hits = Physics.RaycastAll(ray, Mathf.Infinity);
    31.             Plane sectionPlane = new Plane(gizmo.forward, gizmo.position);
    32.  
    33.             if (hits.Length > 0)
    34.             {
    35.                 List<RaycastHit> hitList = new List<RaycastHit>(hits);
    36.                 hitList.Sort((x, y) => x.distance.CompareTo(y.distance));//if you need descending sort, swap x and y on the right-hand side of the arrow =>.
    37.                 RaycastHit farthesttHit = hitList[hitList.Count - 1];
    38.  
    39.                 //how big can be the farthest object? we need to cast the back ray from behind it
    40.                 GameObject farthestGo = farthesttHit.transform.gameObject;
    41.                 Collider farthestColl = farthestGo.GetComponent<Collider>();
    42.                 float maxsize = Vector3.Magnitude(farthestColl.bounds.size);
    43.  
    44.                 float raycastBackDistance = farthesttHit.distance + 1 + maxsize;
    45.                 Ray backRay = new Ray(ray.GetPoint(raycastBackDistance), -ray.direction);
    46.                 RaycastHit[] backHits = Physics.RaycastAll(backRay, raycastBackDistance - Camera.main.nearClipPlane);
    47.  
    48.                 //recalculate distances in relation to the camera
    49.                 for (int i = 0; i< backHits.Length; i++) backHits[i].distance = raycastBackDistance - backHits[i].distance;
    50.  
    51.                 hitList.AddRange(backHits);
    52.                 hitList.Sort((x, y) => x.distance.CompareTo(y.distance));
    53.                 List<RaycastHit> objectHitList = new List<RaycastHit>();
    54.                 for (int i = 0; i < hitList.Count; i++)
    55.                 {
    56.                     //Debug.Log(hitList[i].distance.ToString());
    57.                     //Sort out hits, objectColliders only
    58.                     if (Array.IndexOf(objectColliders, hitList[i].collider) == -1) continue;
    59.                     //
    60.                     //Only hits behind the plane
    61.                     if (sectionPlane.GetDistanceToPoint(hitList[i].point) > 0) continue;
    62.                     objectHitList.Add(hitList[i]);
    63.                 }
    64.  
    65.                 if (objectHitList.Count == 0)
    66.                 {
    67.                     info.text = hitList[0].transform.name + " was hit";
    68.                     return; // object is outside raycasts
    69.                 }
    70.  
    71.                 if (Array.IndexOf(objectColliders, hitList[0].collider) == -1)
    72.                 {
    73.                     Debug.Log("the object is hidden by " + hitList[0].collider.name);
    74.                     info.text = "the object is hidden by " + hitList[0].collider.name;
    75.                     return; // object is hidden
    76.                 }
    77.  
    78.                 bool sectionWasHit = (Vector3.Dot(ray.direction, objectHitList[0].normal) > 0);
    79.  
    80.                 info.text = objectHitList[0].transform.name + " was hit " + (sectionWasHit ? "on the section plane" : "on the outside");  
    81.             }
    82.             else
    83.             {
    84.                 info.text = "no hits";
    85.             }
    86.         }
    87.         imgColor.a -= 0.02f;
    88.         mouseImg.color = imgColor;
    89.     }
    90. }
    91.  
    The script should be attached to the cross-section GameObject.
     
    Last edited: Feb 15, 2021
  15. zashour

    zashour

    Joined:
    Sep 18, 2019
    Posts:
    10



    Thank you so much
     
  16. TobySch

    TobySch

    Joined:
    Jun 15, 2018
    Posts:
    8
    @tomekkie2 Are there any updates regarding SinglePass Instanced support? It would be nice to know if I could use your asset with URP in VR.

    cheers
     
  17. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    No need to update.
    This video - which actually serves on the AssetStore as the cover media of the asset - was taken from OculusGo VR headset, using Single Pass Instanced a.k.a. Single Pass Stereo.

     
  18. santos9991

    santos9991

    Joined:
    Oct 31, 2018
    Posts:
    14
    Hi, I bought the crossSection to use HDRP, after installation the following errors occurred.

    Shader error in 'CrossSectionHDRP/StencilShow': 'GetSurfaceAndBuiltinData': output parameter 'surfaceData' not completely initialized at Assets/WorldSpaceTransitions/crossSection (HDRP)/StencilShaders/UnlitEnhancedData.hlsl(88) (on d3d11)
     
  19. h3space

    h3space

    Joined:
    Jul 28, 2020
    Posts:
    6
    Hi tomekkie, is the feature to avoid artefacts on adjacent geometry still present in HDRP?
    I enabled _retractBackfaces bool in the material, and set the global variable: Shader.SetGlobalFloat("_BackfaceExtrusion", 0.1f); in a script, but doesn't seem to do anything.
    EDIT: I saw an example scene for HDRP but using a plane cut, we're using the clip box, not sure if it's not working using a box.
    EDIT 2: I think I got it working, I think it was due to the materials used had some toggles on that it shoudn't (single sided and instancing).
     
    Last edited: Oct 26, 2020
  20. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    It should work on these shader graphs, which have the backfaceExtrusion subgraph included. There are some graphs without this subgraph in the asset. There is no problem to add this subgraph to them.
     
  21. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    Apologies and thanks for letting me know. I have just to check it thoroughly and will let you know when I find a fix.
     
  22. zashour

    zashour

    Joined:
    Sep 18, 2019
    Posts:
    10


    Hi,
    The method provided uses gizmo, however, I am trying to implement this method using section-box which does include any gizmo.

    Is there a way to achieve this?
    Note: we are using box colliders since all the objects in the scene are boxes.



    I have also tried your method using the sample scene (single_plane capped) and attached the code in the SecionPlaneCapped game object, but the object name does not appear in the UI text box. Whenever I click on the object, I get this message [the section plane was hit in front of the SectionPlaneCapped].

    Am I attaching the code to the correct game object, or I might be using the wrong sample scene?
     
  23. Itzhak_P

    Itzhak_P

    Joined:
    Apr 28, 2015
    Posts:
    2
    Hi, is there a way to hide the hatches so I could see the inside of the model through the cross section?
    I tried to disable the hatch game objects, but I'm left with white material instead that still blocks the view.
     
  24. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    That is a matter of switchng the backface rendering on the material off which should not be a problem, but the detailed explanation may depend on render pipeline you are using; is it the builtin, urp or hdrp renderline? - as the asset supports all of them.
     
  25. smgololobov

    smgololobov

    Joined:
    Jan 28, 2020
    Posts:
    4
    Hello.
    I bought your package. Why are there no HDRP files in the package? Tried to install on different Unity versions on 2020.1.17 and on 2020.2.2
     
  26. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    Please click the "Package content" button and you will see it.
    But it probably will not work in the latest 2020.2.2. version, because too much has changed in Unity rendering, especially in URP and HDRP and now I am working on update. I should finish the URP soon and then will get to HDRP.
     
  27. smgololobov

    smgololobov

    Joined:
    Jan 28, 2020
    Posts:
    4
    Sorry, maybe I am doing something wrong. Here is what is imported from me. The content here is different from what is in the asset store. It's not even about work. It's about the composition of the package.
     

    Attached Files:

  28. smgololobov

    smgololobov

    Joined:
    Jan 28, 2020
    Posts:
    4
    Excuse me. I cleared the cache and downloaded the package again.
     
    tomekkie2 likes this.
  29. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    I have just checked and this is what I am getting.
    Zrzut ekranu 2021-01-25 073941.png
     
  30. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    I am working on the update, because some shaders/functionalities are not working in Unity 2020.2.2. version, because much has changed in Unity rendering, especially in URP and HDRP.
    I have just got the URP back to work in Unity 2020.2 and should finish that soon and then get to HDRP and built-in the latest.
     
  31. smgololobov

    smgololobov

    Joined:
    Jan 28, 2020
    Posts:
    4
    Fine. Thanks for the cool asset.
     
    tomekkie2 likes this.
  32. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    Apologies for answering so late, but have also discovered this script was not working well and re-edited it. I have updated it here and I will include it into the asset update.
    The script should be attached to the TestGameObject, because it is set to work on the collection of colliders inside GameObject.

    For use with section box it needs some modification.
    The idea is to cast a ray from the camera and back through the gameobject, including all the colliders.
    Then to sort the hits from the both rays by distance from the camera.

    Then check where are the hits in relation to the not-clipped (remaining) area, whether inside or behind, and what was hit, and what normal - same as or opprosite to - ray from camera.
     
  33. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    Apologies for answering that late.
    The asset was uploaded with Unity 2020.1.0f1, and this error may appear in later versions.

    A fix is to put the below line
    surfaceData.normalWS = 0.0;


    just after the 117th line in the UnlitEnhancedData.hlsl file.

    If someone were getting the same error message from the CapWrite.shader - please add the line:
    ZERO_INITIALIZE(SurfaceData, surfaceData);

    after this line:
    ZERO_INITIALIZE(BuiltinData, builtinData);
     
    Last edited: Feb 7, 2021
  34. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    v2EffectsTw.gif View attachment 795659 A support for post processing effects is also included in the package.
    A demo scene with crossSection asset used together with Post-Processing Stack v2 got included inside the submitted update.
     
    Last edited: Feb 16, 2021
  35. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    657
    The update was accepted by the AssetStore.
    Everything is updated to Unity 2020.2.2, URP 10.2.2 and HDRP 10.2.2 now.
     
unityunity