コード例 #1
0
    /// <summary>
    /// Synchronous (non-threaded) version of DecodeMesh for Edtior purpose.
    /// </summary>
    /// <param name="data">Drace file data</param>
    /// <returns>The Mesh</returns>
    public Mesh DecodeMeshSync(NativeArray <byte> data)
    {
        Profiler.BeginSample("JobPrepare");
        var job = new DracoJob();

        job.data    = data;
        job.result  = new NativeArray <int>(1, defaultAllocator);
        job.outMesh = new NativeArray <IntPtr>(1, defaultAllocator);

        job.Run();
        Profiler.EndSample();

        int    result    = job.result[0];
        IntPtr dracoMesh = job.outMesh[0];

        job.result.Dispose();
        job.outMesh.Dispose();

        if (result <= 0)
        {
            Debug.LogError("Failed: Decoding error.");
            return(null);
        }

        return(CreateMesh(dracoMesh));
    }
コード例 #2
0
    public IEnumerator DecodeMesh(NativeArray <byte> data)
    {
        Profiler.BeginSample("JobPrepare");
        var job = new DracoJob();

        job.data      = data;
        job.result    = new NativeArray <int>(1, defaultAllocator);
        job.outMesh   = new NativeArray <IntPtr>(1, defaultAllocator);
        job.weightsId = -1;
        job.jointsId  = -1;

        var jobHandle = job.Schedule();

        Profiler.EndSample();

        while (!jobHandle.IsCompleted)
        {
            yield return(null);
        }
        jobHandle.Complete();

        int    result    = job.result[0];
        IntPtr dracoMesh = job.outMesh[0];

        job.result.Dispose();
        job.outMesh.Dispose();

        if (result <= 0)
        {
            Debug.LogError("Failed: Decoding error.");
            yield break;
        }

        bool hasTexcoords;
        bool hasNormals;
        var  mesh = CreateMesh(dracoMesh, out hasNormals, out hasTexcoords);

        if (!hasNormals)
        {
            mesh.RecalculateNormals();
        }
        if (hasTexcoords)
        {
            mesh.RecalculateTangents();
        }

        if (onMeshesLoaded != null)
        {
            onMeshesLoaded(mesh);
        }
    }
コード例 #3
0
    /// <summary>
    /// Synchronous (non-threaded) version of DecodeMesh for Edtior purpose.
    /// </summary>
    /// <param name="data">Drace file data</param>
    /// <returns>The Mesh</returns>
    public Mesh DecodeMeshSync(NativeArray <byte> data)
    {
        Profiler.BeginSample("JobPrepare");
        var job = new DracoJob();

        job.data      = data;
        job.result    = new NativeArray <int>(1, defaultAllocator);
        job.outMesh   = new NativeArray <IntPtr>(1, defaultAllocator);
        job.weightsId = -1;
        job.jointsId  = -1;

        job.Run();
        Profiler.EndSample();

        int    result    = job.result[0];
        IntPtr dracoMesh = job.outMesh[0];

        job.result.Dispose();
        job.outMesh.Dispose();

        if (result <= 0)
        {
            Debug.LogError("Failed: Decoding error.");
            return(null);
        }

        bool hasTexcoords;
        bool hasNormals;
        var  mesh = CreateMesh(dracoMesh, out hasNormals, out hasTexcoords);

        if (!hasNormals)
        {
            mesh.RecalculateNormals();
        }
        if (hasTexcoords)
        {
            mesh.RecalculateTangents();
        }

        return(mesh);
    }
コード例 #4
0
    public IEnumerator DecodeMesh(NativeArray <byte> data)
    {
        Profiler.BeginSample("JobPrepare");
        var job = new DracoJob();

        job.data    = data;
        job.result  = new NativeArray <int>(1, defaultAllocator);
        job.outMesh = new NativeArray <IntPtr>(1, defaultAllocator);

        var jobHandle = job.Schedule();

        Profiler.EndSample();

        while (!jobHandle.IsCompleted)
        {
            yield return(null);
        }
        jobHandle.Complete();

        int    result    = job.result[0];
        IntPtr dracoMesh = job.outMesh[0];

        job.result.Dispose();
        job.outMesh.Dispose();

        if (result <= 0)
        {
            Debug.LogError("Failed: Decoding error.");
            yield break;
        }

        var mesh = CreateMesh(dracoMesh);

        if (onMeshesLoaded != null)
        {
            onMeshesLoaded(mesh);
        }
    }