Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OBI Assets do not work with Octane Render
#2
The following code change to ObiRopeExtrudedRenderer is a brute force that makes it work with Octane.
Variant of the same strategy works for OBI Cloth as well.
But this should not be needed.
Is there anything that you can think of that's not as horrible as saving the runtime mesh to an asset file on every frame?

Code:
        public bool RealtimeMode = true;
        private string SaveFile;
        private bool MeshFileSaved = false;
        [SerializeField] private bool DebugOnePass = false;
        private void ClearMeshData()
        {
            extrudedMesh.Clear();
            vertices.Clear();
            normals.Clear();
            tangents.Clear();
            uvs.Clear();
            vertColors.Clear();
            tris.Clear();
        }

        private void CommitMeshData()
        {
            extrudedMesh.SetVertices(vertices);
            extrudedMesh.SetNormals(normals);
            extrudedMesh.SetTangents(tangents);
            extrudedMesh.SetColors(vertColors);
            extrudedMesh.SetUVs(0, uvs);
            extrudedMesh.SetTriangles(tris, 0, true);
            extrudedMesh.MarkModified(); //This should work. But does not
            extrudedMesh.UploadMeshData(false); //Adding this should definitely make it work but it does not

            #region Brute Force Method
            // This brute force method works
            // But this is really bad brute force and should not be needed.
            if (DebugOnePass ||((!RealtimeMode) && Application.isPlaying))
            {
                if (DebugOnePass)
                {
                    SaveFile = string.Empty;
                }
                DebugOnePass = false;
                if (string.IsNullOrEmpty(SaveFile))
                {
                    SaveFile = System.Guid.NewGuid().ToString().Replace(@"-", string.Empty);
                    SaveFile = string.Concat(SaveFile, @".asset");
                }
                if (MeshFileSaved)
                {
                    AssetDatabase.DeleteAsset(SavePath);
                }
                AssetDatabase.CreateAsset(extrudedMesh, SavePath);
                MeshFileSaved = true;
            }
            #endregion

        }
        private string SavePath
        {
            get
            {
                return string.Concat(@"Assets/DynamicMeshTemp/", SaveFile);
            }
        }

        private void OnDestroy()
        {
            if (!string.IsNullOrEmpty(SaveFile))
            {
                if (MeshFileSaved)
                {
                    AssetDatabase.DeleteAsset(SavePath);
                }
            }
        }
Reply


Messages In This Thread
RE: OBI Assets do not work with Octane Render - by tcwicks - 07-08-2021, 03:00 AM