Thanks to visit codestin.com
Credit goes to github.com

Skip to content

URP Support #126

Open
Open
@unitycoder

Description

@unitycoder

using Unity 2019.4.25f1 + URP 7.7.1

temporary fix for URP+WorldSpace Canvas issue (point cloud get "stuck" inside canvas)
You dont need to do this, if you don't have world space canvas.
This is only for V1 (.bin) and V2 (.ucpc) formats.

  • Create script CustomRenderPassFeature.cs (copy below)
  • Select UniversalRenderPipelineAsset_Renderer
  • Click Add Renderer Feature/CustomRenderPassFeature *this wont be visible, if you didnt create the script first
  • Modify PointCloudViewerDX11.cs, add this line to class variables (somewhere before Awake() line):
    public static PointCloudViewerDX11 instance;
    Modify Awake() to:
void Awake()
{
    instance = this;
    applicationStreamingAssetsPath = Application.streamingAssetsPath;
}
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public class CustomRenderPassFeature : ScriptableRendererFeature
{
    class CustomRenderPass : ScriptableRenderPass
    {
        CommandBuffer commandBuffer;

        public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
        {
            commandBuffer = new CommandBuffer { name = "PointCloudViewer" };
        }

        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            if (unitycodercom_PointCloudBinaryViewer.PointCloudViewerDX11.instance == null) return;
            commandBuffer.Clear();
            commandBuffer.DrawProcedural(Matrix4x4.identity, unitycodercom_PointCloudBinaryViewer.PointCloudViewerDX11.instance.cloudMaterial, 0, MeshTopology.Points, unitycodercom_PointCloudBinaryViewer.PointCloudViewerDX11.instance.points.Length);
            context.ExecuteCommandBuffer(commandBuffer);
        }

        public override void FrameCleanup(CommandBuffer cmd)
        {
        }
    }

    CustomRenderPass m_ScriptablePass;
    public override void Create()
    {
        m_ScriptablePass = new CustomRenderPass();
        m_ScriptablePass.renderPassEvent = RenderPassEvent.AfterRenderingOpaques;
    }

    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    {
        renderer.EnqueuePass(m_ScriptablePass);
    }
}


Using Unity 2020.3.21f1 + URP 10.6.0 + V3 (.pcroot) viewer

  • Create script CustomRenderPassFeature.cs (copy contents below)
  • Select UniversalRenderPipelineAsset_Renderer
  • Click Add Renderer Feature/CustomRenderPassFeature *this wont be visible, if you didn't create the script first
  • Modify PointCloudViewerTilesDX11.cs, add these changes:
// BEFORE
PointCloudTile[] tiles;
// AFTER
internal PointCloudTile[] tiles;
// BEFORE
int tilesCount = 0;
// AFTER
internal int tilesCount = 0;
// BEFORE
        void Awake()
        {
            applicationStreamingAssetsPath = Application.streamingAssetsPath;
            FixMainThreadHelper();
        }
// AFTER
        public static PointCloudViewerTilesDX11 instance;
        void Awake()
        {
            instance = this;
            applicationStreamingAssetsPath = Application.streamingAssetsPath;
            FixMainThreadHelper();
        }
// BEFORE
public void OnRenderObject()
// AFTER
public void DisabledOnRenderObject()

CustomRenderPassFeature .cs:

using unitycodercom_PointCloudBinaryViewer;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public class CustomRenderPassFeature : ScriptableRendererFeature
{
    class CustomRenderPass : ScriptableRenderPass
    {
        CommandBuffer commandBuffer;

        public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
        {
            commandBuffer = new CommandBuffer { name = "PointCloudViewer" };
        }

        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            if (PointCloudViewerTilesDX11.instance == null) return;

            commandBuffer.Clear();
            for (int i = 0, len = PointCloudViewerTilesDX11.instance.tilesCount; i < len; i++)
            {
                if (PointCloudViewerTilesDX11.instance.tiles[i].isReady == false || PointCloudViewerTilesDX11.instance.tiles[i].isLoading == true || PointCloudViewerTilesDX11.instance.tiles[i].visiblePoints == 0) continue;
                commandBuffer.DrawProcedural(Matrix4x4.identity, PointCloudViewerTilesDX11.instance.tiles[i].material, 0, MeshTopology.Points, PointCloudViewerTilesDX11.instance.tiles[i].visiblePoints);
            }
            context.ExecuteCommandBuffer(commandBuffer);
        }

        public override void FrameCleanup(CommandBuffer cmd)
        {
        }
    }

    CustomRenderPass m_ScriptablePass;
    public override void Create()
    {
        m_ScriptablePass = new CustomRenderPass();
        m_ScriptablePass.renderPassEvent = RenderPassEvent.AfterRenderingOpaques;
    }

    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    {
        renderer.EnqueuePass(m_ScriptablePass);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions