Search Unity

CrossSection

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

?

What render pipeline are you using or going to use with the CrossSection Asset?

  1. Built-in

    29.7%
  2. URP

    54.9%
  3. HDRP

    15.4%
  4. other

    0 vote(s)
    0.0%
  1. zashour

    zashour

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

    tomekkie2

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

    zashour

    Joined:
    Sep 18, 2019
    Posts:
    11
    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:
    973
  5. santos9991

    santos9991

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

    zashour

    Joined:
    Sep 18, 2019
    Posts:
    11
    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:
    973
    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:
    973
    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:
    11

    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:
    973
    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:
    973
    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:
    11
    That's exactly what we want to do. Can you please share the script you used?
     
  14. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    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:
    11



    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:
    973
    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:
    17
    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:
    14
    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:
    973
    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:
    973
    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:
    11


    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:
    12
    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:
    973
    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:
    973
    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:
    973
    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:
    973
    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:
    973
    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:
    973
    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:
    973
    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:
    973
    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.
     
  36. mch_architect

    mch_architect

    Joined:
    May 16, 2017
    Posts:
    2
    Could I use crossection under its own material shader of the object ?
     
  37. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    No it needs to be a cross-section shader.
    Do you mean any specific shader?
     
    mch_architect likes this.
  38. mch_architect

    mch_architect

    Joined:
    May 16, 2017
    Posts:
    2
    Yes, because my mesh models have their own material shader for color, I wish they could be crossed section directly. Not only use the shaders provided in the asset (crosssection). Is it possible?
     
  39. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Means if now it looks like that:
    image_010_0000.png

    And you like to get it to look like that :
    image_011_0000.png

    On the first image you have separate material property set for the section (or more specifically for the inner side of the mesh)
    On the second image you have the same material property set for both.

    This is not a problem, I can tell how to get that, but please confirm if that is what you mean.
     
    Last edited: Mar 7, 2021
  40. TheFlyHawk

    TheFlyHawk

    Joined:
    Mar 23, 2016
    Posts:
    58
    Like this how to do
    upload_2021-4-24_14-51-2.png
     
  41. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Do you need it for the builtin pipeline?
    I have reworked here the cube section scene to get that.
    image_012_0000.png
     

    Attached Files:

  42. TheFlyHawk

    TheFlyHawk

    Joined:
    Mar 23, 2016
    Posts:
    58
    Thanks,is URP
     
  43. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    This is the cube_section_urp scene update package for URP.
     

    Attached Files:

  44. Bahmann

    Bahmann

    Joined:
    Mar 5, 2019
    Posts:
    15
    Hi!
    I'm wondering how to cut certain childs of a model with one plane and the other childs with a second plane? I tried seperating them into two different parent objects and assigned them to the two different cutting planes, but the plane still cuts anything with the cut shader attached, regardles of the parent object I select in the section setup.

    Working with CrossSectionBox_Urp Prefab in Unity 2019.4.4 URP and ClippingURP/Corner/Lit Shaders
     
  45. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    You could use the shader
     
  46. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    If you need only planes - you should use single plane sections and set the below properties:
    _SectionPoint: - point which has to be included in the section plane
    _SectionPlane: - normal of the section plane
    on local, not global, material level.

    Just use:
    Code (CSharp):
    1. material1.SetGlobalVector("_SectionPoint", plane1Point);
    2. material1.SetGlobalVector("_SectionPlane",plane1Normal);
    3. material2.SetGlobalVector("_SectionPoint", plane2Point);
    4. material2.SetGlobalVector("_SectionPlane",plane2Normal);
    instead of:
    Code (CSharp):
    1.  
    2. Shader.SetGlobalVector("_SectionPoint", planePoint);
    3. Shader.SetGlobalVector("_SectionPlane",planeNormal);
    You could have two separate groups of materials for these two planes.

    Do you have a specific reason to use box-section and CrossSectionBox_Urp Prefab?

    You can also take a look at this example scene: single_plane_individual - it should be inside the package.
    image_013_0000.png
     
    Last edited: May 31, 2021
  47. morfevs

    morfevs

    Joined:
    Dec 21, 2016
    Posts:
    19
    I have seen that on the cuts, the material can be two different types: a) a color that one can choose or b) a material with stripes.

    But I wonder, if its possible to have the same material than the one you are cutting. Like if you are cutting metal, you have the same metal material "inside"?

    Or how to make it happen?
     
  48. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Generally it can be almost the same material, but with a specific rendering order and specific stencil passes and settings.
    Stripes are just a texture example an the texture can also be the same as on the “main” material, like on this image from the above post.
     
    Last edited: Jun 7, 2021
  49. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    1,248
    Oh wow, this asset looks absolutely awesome!

    Will this asset work with Cinemachine, Timeline, Unity Recorder, HDRP 12 with Raytracing?
    (for offline rendering using Unity Recorder or perhaps Deckard)
     
  50. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    I am actually using Unity Recorder to take single screens or gifs or mp4 recordings from the asset demo scenes. It will probably also work with other assets. I have tested it with HDRP 11, will probably also work with 12.
     
    newguy123 likes this.