void usdiKickAsyncUpdateTask() { // kick async update tasks #if UNITY_EDITOR if (m_forceSingleThread) { usdiAsyncUpdate(m_time); } else #endif { if (m_asyncUpdate == null) { m_asyncUpdate = new usdi.DelegateTask( (arg) => { try { usdiAsyncUpdate(m_time); } finally { } }, "UsdStream: " + gameObject.name); } m_asyncUpdate.Run(); } }
public override void usdiAsyncUpdate(double time) { base.usdiAsyncUpdate(time); if (m_updateFlags.bits == 0) { return; } usdi.PointsData tmp = usdi.PointsData.default_value; usdi.usdiPointsReadSample(m_points, ref tmp, time, true); // allocate points data if (m_pointsData.num_points == tmp.num_points) { // no need to allocate } else { m_pointsData.num_points = tmp.num_points; m_positions = new Vector3[m_pointsData.num_points]; m_pointsData.points = usdi.GetArrayPtr(m_positions); if (m_summary.has_velocities) { m_velocities = new Vector3[m_pointsData.num_points]; m_pointsData.velocities = usdi.GetArrayPtr(m_velocities); } if (m_attrRot) { m_rotations = new Vector4[m_pointsData.num_points]; m_rotData.data = usdi.GetArrayPtr(m_rotations); m_rotData.num_elements = tmp.num_points; } } // read points data if (m_pointsData.num_points > 0) { #if UNITY_EDITOR if (m_stream.forceSingleThread) { usdi.usdiPointsReadSample(m_points, ref m_pointsData, m_timeRead, true); if (m_attrRot) { usdi.usdiAttrReadSample(m_attrRot, ref m_rotData, m_timeRead, true); } } else #endif { if (m_asyncRead == null) { if (m_attrRot) { m_asyncRead = new usdi.CompositeTask(new IntPtr[] { usdi.usdiTaskCreatePointsReadSample(m_points, ref m_pointsData, ref m_timeRead), usdi.usdiTaskCreateAttrReadSample(m_attrRot, ref m_rotData, ref m_timeRead) }); } else { m_asyncRead = new usdi.Task(usdi.usdiTaskCreatePointsReadSample(m_points, ref m_pointsData, ref m_timeRead)); } } m_timeRead = time; m_asyncRead.Run(); } } }
void ProcessCapture() { if (!m_recording) { return; } // for some reason, come here twice on first frame. skip second run. int frame = Time.frameCount; if (frame == m_prevFrame) { return; } m_prevFrame = frame; // wait for complete previous flush WaitFlush(); float begin_time = Time.realtimeSinceStartup; // capture components foreach (var c in m_capturers) { c.Capture(m_time); } // kick flush task #if UNITY_EDITOR if (m_forceSingleThread) { foreach (var c in m_capturers) { c.Flush(time); } } else #endif { if (m_asyncFlush == null) { m_asyncFlush = new usdi.DelegateTask((var) => { try { foreach (var c in m_capturers) { c.Flush(m_timeFlush); } } finally { } }, "UsdExporter: " + gameObject.name); } m_timeFlush = m_time; m_asyncFlush.Run(); } ++m_frameCount; switch (m_timeUnit.type) { case TimeUnit.Types.Frame_30FPS: case TimeUnit.Types.Frame_60FPS: m_time = m_frameCount; break; default: m_time += Time.deltaTime * m_timeUnit.scale; break; } m_elapsed = Time.realtimeSinceStartup - begin_time; usdiLog("UsdExporter.ProcessCapture(): " + (m_elapsed * 1000.0f) + "ms"); if (m_maxCaptureFrame > 0 && m_frameCount >= m_maxCaptureFrame) { EndCapture(); } }
// async public override void usdiAsyncUpdate(double time) { base.usdiAsyncUpdate(time); if (m_updateFlags.bits == 0 && !m_allocateMeshDataRequired && !m_updateIndicesRequired && !m_updateVerticesRequired) { return; } if (m_updateFlags.importConfigChanged || m_updateFlags.variantSetChanged) { usdi.usdiMeshGetSummary(m_mesh, ref m_meshSummary); } m_timeRead = time; if (isInstance) { m_allocateMeshDataRequired = false; m_updateIndicesRequired = false; m_updateVerticesRequired = false; m_updateSkinningRequired = false; usdi.usdiMeshReadSample(m_mesh, ref m_meshData, m_timeRead, true); while (m_submeshes.Count < m_meshData.num_submeshes) { usdiAddSubmesh(); } } else { if (!m_allocateMeshDataRequired) { m_allocateMeshDataRequired = m_meshSummary.topology_variance == usdi.TopologyVariance.Heterogenous || m_updateFlags.variantSetChanged; } if (!m_updateIndicesRequired) { m_updateIndicesRequired = m_allocateMeshDataRequired || m_meshSummary.topology_variance == usdi.TopologyVariance.Heterogenous || m_updateFlags.importConfigChanged; } if (!m_updateVerticesRequired) { m_updateVerticesRequired = m_updateIndicesRequired || m_meshSummary.topology_variance != usdi.TopologyVariance.Constant; } if (!m_updateSkinningRequired) { m_updateSkinningRequired = m_allocateMeshDataRequired || m_updateFlags.importConfigChanged; } } // todo: update heterogenous mesh when possible m_kickVBUpdate = #if UNITY_5_5_OR_NEWER m_stream.directVBUpdate&& !m_allocateMeshDataRequired && m_meshSummary.topology_variance == usdi.TopologyVariance.Homogenous; #else false; #endif if (m_allocateMeshDataRequired) { usdiAllocateMeshData(m_timeRead); } if (m_updateVerticesRequired) { if (m_kickVBUpdate) { usdi.usdiMeshReadSample(m_mesh, ref m_meshData, m_timeRead, false); // kick VB update task in usdiUpdate() } else { #if UNITY_EDITOR if (m_stream.forceSingleThread) { usdi.usdiMeshReadSample(m_mesh, ref m_meshData, m_timeRead, true); } else #endif { if (m_asyncRead == null) { m_asyncRead = new usdi.Task(usdi.usdiTaskCreateMeshReadSample(m_mesh, ref m_meshData, ref m_timeRead)); } m_asyncRead.Run(); } } } }