diff --git a/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporter.cs b/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporter.cs index 43a4d77ba..86330daac 100644 --- a/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporter.cs +++ b/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporter.cs @@ -70,13 +70,14 @@ public class AlembicImporter : ScriptedImporter { [SerializeField] public AlembicStreamSettings streamSettings = new AlembicStreamSettings(); [SerializeField] public float scaleFactor = 0.01f; - [SerializeField] public int startFrame =-1; - [SerializeField] public int endFrame =-1; + [SerializeField] public int startFrame = int.MinValue; + [SerializeField] public int endFrame = int.MaxValue; [SerializeField] public float AbcStartTime; [SerializeField] public float AbcEndTime; [SerializeField] public int AbcFrameCount; [SerializeField] public string importWarning; [SerializeField] public List varyingTopologyMeshNames = new List(); + [SerializeField] public List splittingMeshNames = new List(); public override void OnImportAsset(AssetImportContext ctx) { @@ -98,7 +99,7 @@ public override void OnImportAsset(AssetImportContext ctx) go.transform.localScale *= scaleFactor; AlembicStreamDescriptor streamDescriptor = ScriptableObject.CreateInstance(); - streamDescriptor.name = go.name + "ABCDesc"; + streamDescriptor.name = go.name + "_ABCDesc"; streamDescriptor.pathToAbc = destPath; streamDescriptor.settings = streamSettings; @@ -109,8 +110,8 @@ public override void OnImportAsset(AssetImportContext ctx) AbcEndTime = abcStream.AbcEndTime; AbcFrameCount = abcStream.AbcFrameCount; - startFrame = startFrame ==-1 ? 0 : startFrame; - endFrame = endFrame ==-1 ? AbcFrameCount : endFrame; + startFrame = startFrame < 0 ? 0 : startFrame; + endFrame = endFrame > AbcFrameCount-1 ? AbcFrameCount-1 : endFrame; streamDescriptor.minFrame = startFrame; streamDescriptor.maxFrame = endFrame; @@ -156,10 +157,13 @@ private void GenerateSubAssets( AssetImportContext ctx,AlembicTreeNode root,Alem AnimationCurve curve = new AnimationCurve(frames); var animationClip = new AnimationClip(); animationClip.SetCurve("",typeof(AlembicStreamPlayer),"currentTime",curve); - animationClip.name = "Default Animation"; + animationClip.name = root.linkedGameObj.name + "_Clip"; AddObjectToAsset(ctx,"Default Animation", animationClip); } + varyingTopologyMeshNames = new List(); + splittingMeshNames = new List(); + CollectSubAssets(ctx, root, material); streamDescr.hasVaryingTopology = varyingTopologyMeshNames.Count > 0; @@ -175,6 +179,10 @@ private void CollectSubAssets(AssetImportContext ctx, AlembicTreeNode node, Mat { varyingTopologyMeshNames.Add(node.linkedGameObj.name); } + else if (streamSettings.shareVertices && mesh.sampleSummary.splitCount > 1) + { + splittingMeshNames.Add(node.linkedGameObj.name); + } } var meshFilter = node.linkedGameObj.GetComponent(); diff --git a/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporterEditor.cs b/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporterEditor.cs index cf97bedc8..8ff1354db 100644 --- a/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporterEditor.cs +++ b/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicImporterEditor.cs @@ -22,17 +22,29 @@ public override void OnInspectorGUI() EditorGUILayout.PropertyField(serializedObject.FindProperty("streamSettings.turnQuadEdges")); EditorGUILayout.PropertyField(serializedObject.FindProperty("streamSettings.shareVertices")); + var splittingMeshes = serializedObject.FindProperty("splittingMeshNames"); + if (splittingMeshes.arraySize>0) + { + string message = "Meshes with shared vertices cannot be split."; + if (!splittingMeshes.hasMultipleDifferentValues) + { + message += "The following meshes won't be affected : \n" + string.Join(",", importer.splittingMeshNames.ToArray()) + "."; + } + EditorGUILayout.HelpBox(message,MessageType.Info); + } EditorGUILayout.PropertyField(serializedObject.FindProperty("streamSettings.treatVertexExtraDataAsStatics")); var varyingTopologyMeshes = serializedObject.FindProperty("varyingTopologyMeshNames"); if (varyingTopologyMeshes.arraySize>0) { - string message = "'Merge vertices' and 'Vertex extra data is static' do not apply to meshes with varying topology."; + string message = "'Share vertices' and 'Vertex extra data is static' do not apply to meshes with varying topology."; if (!varyingTopologyMeshes.hasMultipleDifferentValues) { - message = "The following meshes won't be affected : \n" + string.Join(",", importer.varyingTopologyMeshNames.ToArray()) + "."; + message += "The following meshes won't be affected : \n" + string.Join(",", importer.varyingTopologyMeshNames.ToArray()) + "."; } EditorGUILayout.HelpBox(message,MessageType.Info); } + + EditorGUILayout.PropertyField(serializedObject.FindProperty("streamSettings.use32BitsIndexBuffer")); #if !UNITY_2017_3_OR_NEWER @@ -47,14 +59,14 @@ public override void OnInspectorGUI() var abcFrameCount = serializedObject.FindProperty("AbcFrameCount"); var startFrame = serializedObject.FindProperty("startFrame"); var endFrame = serializedObject.FindProperty("endFrame"); - var frameLength = (abcFrameCount.intValue == 0) ? 0 : (abcEndTime.floatValue - abcStartTime.floatValue) / abcFrameCount.intValue; - var frameRate = (abcFrameCount.intValue == 0) ? 0 : (int)(1.0f/ frameLength); + var frameLength = (abcFrameCount.intValue == 1) ? 0 : (abcEndTime.floatValue - abcStartTime.floatValue) / (abcFrameCount.intValue-1); + var frameRate = (abcFrameCount.intValue == 1) ? 0 : (int)(1.0f/ frameLength); float startFrameVal = startFrame.intValue; float endFrameVal = endFrame.intValue; EditorGUI.BeginDisabledGroup(abcStartTime.hasMultipleDifferentValues || abcEndTime.hasMultipleDifferentValues || abcFrameCount.hasMultipleDifferentValues); EditorGUI.BeginChangeCheck(); - EditorGUILayout.MinMaxSlider("Time range",ref startFrameVal,ref endFrameVal,0,abcFrameCount.intValue); + EditorGUILayout.MinMaxSlider("Time range",ref startFrameVal,ref endFrameVal,0,abcFrameCount.intValue-1); startFrameVal = (float)Math.Floor(startFrameVal); endFrameVal = (float)Math.Floor(endFrameVal); @@ -96,7 +108,7 @@ public override void OnInspectorGUI() style.alignment = TextAnchor.LowerRight; if (!endFrame.hasMultipleDifferentValues && !startFrame.hasMultipleDifferentValues && !abcFrameCount.hasMultipleDifferentValues) { - EditorGUILayout.LabelField(new GUIContent(duration.ToString("0.00") +"s at " + frameRate + "fps (" + (frameCount+1) + " frames)"),style); + EditorGUILayout.LabelField(new GUIContent(duration.ToString("0.000") +"s at " + frameRate + "fps (" + (frameCount+1) + " frames)"),style); EditorGUILayout.LabelField(new GUIContent("frame " + startFrameVal.ToString("0") + " to " + endFrameVal.ToString("0")),style); } else diff --git a/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicStreamPlayerEditor.cs b/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicStreamPlayerEditor.cs index 690b827fe..b603d7231 100644 --- a/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicStreamPlayerEditor.cs +++ b/AlembicImporter/Assets/UTJ/Alembic/Editor/Importer/AlembicStreamPlayerEditor.cs @@ -20,7 +20,7 @@ public override void OnInspectorGUI() var minFrame = targetStreamDesc.minFrame; var maxFrame = targetStreamDesc.maxFrame; var frameLength = targetStreamDesc.FrameLength; - var frameRate = 1.0f / frameLength; + var frameRate = frameLength==0.0f ? 0.0f : 1.0f / frameLength; var hasVaryingTopology= false; var hasAcyclicFramerate = false; var multipleFramerates = false; @@ -99,7 +99,7 @@ public override void OnInspectorGUI() { int numFrames = (int)(endFrameVal - startFrameVal); float duration = numFrames * frameLength; - EditorGUILayout.LabelField(new GUIContent(duration.ToString("0.00") + "s at " + frameRate + "fps (" + (numFrames + 1) + " frames).", "Frame rate"), style); + EditorGUILayout.LabelField(new GUIContent(duration.ToString("0.000") + "s at " + frameRate + "fps (" + (numFrames+1) + " frames).", "Frame rate"), style); } else { diff --git a/AlembicImporter/Assets/UTJ/Alembic/Scripts/Importer/AlembicStream.cs b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Importer/AlembicStream.cs index c03a678c9..38cfef40d 100644 --- a/AlembicImporter/Assets/UTJ/Alembic/Scripts/Importer/AlembicStream.cs +++ b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Importer/AlembicStream.cs @@ -171,7 +171,11 @@ public void AbcLoad(bool createMissingNodes=false) m_Config.turnQuadEdges = settings.turnQuadEdges; m_Config.aspectRatio = AbcAPI.GetAspectRatio(settings.aspectRatioMode); m_Config.cacheTangentsSplits = true; +#if !UNITY_2017_3_OR_NEWER m_Config.use32BitsIndexBuffer = settings.use32BitsIndexBuffer; +#else + m_Config.use32BitsIndexBuffer = false; +#endif AbcAPI.aiSetConfig(m_Context, ref m_Config); AbcAPI.UpdateAbcTree(m_Context, alembicTreeRoot, m_Time, createMissingNodes); diff --git a/AlembicImporter/Assets/UTJ/Alembic/Scripts/Importer/AlembicStreamDescriptor.cs b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Importer/AlembicStreamDescriptor.cs index 96a75b190..90ce52000 100644 --- a/AlembicImporter/Assets/UTJ/Alembic/Scripts/Importer/AlembicStreamDescriptor.cs +++ b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Importer/AlembicStreamDescriptor.cs @@ -27,8 +27,8 @@ public float FrameLength { get { - if (abcFrameCount == 0) return 0; - return abcDuration / abcFrameCount; + if (abcFrameCount == 1) return 0; + return abcDuration / (abcFrameCount-1); } } } diff --git a/AlembicImporter/ProjectSettings/ProjectSettings.asset b/AlembicImporter/ProjectSettings/ProjectSettings.asset index 78d34872b..5dc33d7c8 100644 Binary files a/AlembicImporter/ProjectSettings/ProjectSettings.asset and b/AlembicImporter/ProjectSettings/ProjectSettings.asset differ diff --git a/AlembicImporter/ProjectSettings/ProjectVersion.txt b/AlembicImporter/ProjectSettings/ProjectVersion.txt index ada1fbd90..f0f965c4b 100644 --- a/AlembicImporter/ProjectSettings/ProjectVersion.txt +++ b/AlembicImporter/ProjectSettings/ProjectVersion.txt @@ -1 +1 @@ -m_EditorVersion: 2017.3.0b11 +m_EditorVersion: 2018.1.0b1 diff --git a/Plugin/abci/Foundation/aiLogger.cpp b/Plugin/abci/Foundation/aiLogger.cpp index d5a46910e..b602755f5 100644 --- a/Plugin/abci/Foundation/aiLogger.cpp +++ b/Plugin/abci/Foundation/aiLogger.cpp @@ -115,7 +115,7 @@ void aiLogger::_indent() } } -void aiLogger::warning(const char *fmt, va_list args) +void aiLogger::warning(const char *fmt, va_list args) const { if (isOpened()) { @@ -126,7 +126,7 @@ void aiLogger::warning(const char *fmt, va_list args) } } -void aiLogger::error(const char *fmt, va_list args) +void aiLogger::error(const char *fmt, va_list args) const { if (isOpened()) { @@ -137,7 +137,7 @@ void aiLogger::error(const char *fmt, va_list args) } } -void aiLogger::info(const char *fmt, va_list args) +void aiLogger::info(const char *fmt, va_list args) const { if (isOpened()) { @@ -148,7 +148,7 @@ void aiLogger::info(const char *fmt, va_list args) } } -void aiLogger::debug(const char *fmt, va_list args) +void aiLogger::debug(const char *fmt, va_list args) const { if (isOpened()) { diff --git a/Plugin/abci/Foundation/aiLogger.h b/Plugin/abci/Foundation/aiLogger.h index 8603b46b3..c4deae365 100644 --- a/Plugin/abci/Foundation/aiLogger.h +++ b/Plugin/abci/Foundation/aiLogger.h @@ -1,125 +1,122 @@ #pragma once - -#include -#include -#include - -class aiLogger -{ -public: - - static inline void Enable(bool on, const char *path) - { - if (on) - { - msInstance.open(path); - } - else - { - msInstance.close(); - } - } - - static inline void Indent(int level=1) - { - msInstance.indent(level); - } - - static inline void Unindent(int level=1) - { - msInstance.unindent(level); - } - - static inline void Warning(const char *fmt, ...) - { - if (!msInstance.isOpened()) - { - return; - } - - va_list args; - va_start(args, fmt); - - msInstance.warning(fmt, args); - - va_end(args); - } - - static inline void Error(const char *fmt, ...) - { - if (!msInstance.isOpened()) - { - return; - } - - va_list args; - va_start(args, fmt); - - msInstance.error(fmt, args); - - va_end(args); - } - - static inline void Info(const char *fmt, ...) - { - if (!msInstance.isOpened()) - { - return; - } - - va_list args; - va_start(args, fmt); - - msInstance.info(fmt, args); - - va_end(args); - } - - static inline void Debug(const char *fmt, ...) - { - if (!msInstance.isOpened()) - { - return; - } - - va_list args; - va_start(args, fmt); - - msInstance.debug(fmt, args); - - va_end(args); - } - -private: - - aiLogger(); - ~aiLogger(); - - void open(const char *path); - void close(); - - bool isOpened() const; - - void indent(int level); - void unindent(int level); - - void warning(const char *fmt, va_list args); - void error(const char *fmt, va_list args); - void info(const char *fmt, va_list args); - void debug(const char *fmt, va_list args); - -private: - - void _openDebug(); - void _close(); - void _indent(); - - std::string mPath; - FILE *mFile; - int mIndentLevel; - std::string mIndentString; - -private: - - static aiLogger msInstance; -}; +#include + +class aiLogger +{ +public: + + static inline void Enable(bool on, const char *path) + { + if (on) + { + msInstance.open(path); + } + else + { + msInstance.close(); + } + } + + static inline void Indent(int level=1) + { + msInstance.indent(level); + } + + static inline void Unindent(int level=1) + { + msInstance.unindent(level); + } + + static inline void Warning(const char *fmt, ...) + { + if (!msInstance.isOpened()) + { + return; + } + + va_list args; + va_start(args, fmt); + + msInstance.warning(fmt, args); + + va_end(args); + } + + static inline void Error(const char *fmt, ...) + { + if (!msInstance.isOpened()) + { + return; + } + + va_list args; + va_start(args, fmt); + + msInstance.error(fmt, args); + + va_end(args); + } + + static inline void Info(const char *fmt, ...) + { + if (!msInstance.isOpened()) + { + return; + } + + va_list args; + va_start(args, fmt); + + msInstance.info(fmt, args); + + va_end(args); + } + + static inline void Debug(const char *fmt, ...) + { + if (!msInstance.isOpened()) + { + return; + } + + va_list args; + va_start(args, fmt); + + msInstance.debug(fmt, args); + + va_end(args); + } + +private: + + aiLogger(); + ~aiLogger(); + + void open(const char *path); + void close(); + + bool isOpened() const; + + void indent(int level); + void unindent(int level); + + void warning(const char *fmt, va_list args) const; + void error(const char *fmt, va_list args) const; + void info(const char *fmt, va_list args) const; + void debug(const char *fmt, va_list args) const; + +private: + + void _openDebug(); + void _close(); + void _indent(); + + std::string mPath; + FILE *mFile; + int mIndentLevel; + std::string mIndentString; + +private: + + static aiLogger msInstance; +}; diff --git a/Plugin/abci/Foundation/aiThreadPool.cpp b/Plugin/abci/Foundation/aiThreadPool.cpp index 7ef73f23c..fde0e5b90 100644 --- a/Plugin/abci/Foundation/aiThreadPool.cpp +++ b/Plugin/abci/Foundation/aiThreadPool.cpp @@ -8,7 +8,7 @@ class aiWorkerThread { public: aiWorkerThread(aiThreadPool *pool); - void operator()(); + void operator()() const; private: aiThreadPool *m_pool; @@ -20,7 +20,7 @@ aiWorkerThread::aiWorkerThread(aiThreadPool *pool) { } -void aiWorkerThread::operator()() +void aiWorkerThread::operator()() const { std::function task; diff --git a/Plugin/abci/Foundation/aiThreadPool.h b/Plugin/abci/Foundation/aiThreadPool.h index 427933214..c4352c1c5 100644 --- a/Plugin/abci/Foundation/aiThreadPool.h +++ b/Plugin/abci/Foundation/aiThreadPool.h @@ -6,8 +6,6 @@ #include #include #include -#include -#include class aiWorkerThread; class aiThreadPool; diff --git a/Plugin/abci/Importer/aiContext.cpp b/Plugin/abci/Importer/aiContext.cpp index db6533cde..dbc2b78bd 100644 --- a/Plugin/abci/Importer/aiContext.cpp +++ b/Plugin/abci/Importer/aiContext.cpp @@ -187,7 +187,7 @@ void aiContext::setConfig(const aiConfig &config) m_config = config; } -void aiContext::gatherNodesRecursive(aiObject *n) const +void aiContext::gatherNodesRecursive(aiObject *n) { abcObject &abc = n->getAbcObject(); size_t numChildren = abc.getNumChildren(); @@ -368,7 +368,7 @@ float aiContext::getEndTime() const unsigned int aiContext::getFrameCount() const { - return m_numFrames -1; + return m_numFrames; } aiObject* aiContext::getTopObject() const diff --git a/Plugin/abci/Importer/aiContext.h b/Plugin/abci/Importer/aiContext.h index b7166f0d9..359357de5 100644 --- a/Plugin/abci/Importer/aiContext.h +++ b/Plugin/abci/Importer/aiContext.h @@ -1,6 +1,5 @@ #pragma once #include "aiThreadPool.h" -#include "aiMisc.h" typedef AbcGeom::IObject abcObject; typedef AbcGeom::IXform abcXForm; @@ -77,8 +76,8 @@ class aiContext static std::string normalizePath(const char *path); private: + static void gatherNodesRecursive(aiObject *n); void reset(); - void gatherNodesRecursive(aiObject *n) const; std::string m_path; Abc::IArchive m_archive; diff --git a/Plugin/abci/Importer/aiObject.cpp b/Plugin/abci/Importer/aiObject.cpp index 3a3395a7e..9b66608f7 100644 --- a/Plugin/abci/Importer/aiObject.cpp +++ b/Plugin/abci/Importer/aiObject.cpp @@ -71,7 +71,7 @@ void aiObject::removeChild(aiObject *c) auto it = std::find(m_children.begin(), m_children.end(), c); if (it != m_children.end()) { - c->m_parent = 0; + c->m_parent = nullptr; m_children.erase(it); } } @@ -109,9 +109,9 @@ void aiObject::cacheSamples(int64_t startIndex, int64_t endIndex) } } -aiXForm* aiObject::getXForm() { return m_xform.get(); } -aiPolyMesh* aiObject::getPolyMesh() { return m_polymesh.get(); } -aiCamera* aiObject::getCamera() { return m_camera.get(); } -aiPoints* aiObject::getPoints() { return m_points.get(); } +aiXForm* aiObject::getXForm() const { return m_xform.get(); } +aiPolyMesh* aiObject::getPolyMesh() const { return m_polymesh.get(); } +aiCamera* aiObject::getCamera() const { return m_camera.get(); } +aiPoints* aiObject::getPoints() const { return m_points.get(); } diff --git a/Plugin/abci/Importer/aiObject.h b/Plugin/abci/Importer/aiObject.h index feb275b41..ab122ae5b 100644 --- a/Plugin/abci/Importer/aiObject.h +++ b/Plugin/abci/Importer/aiObject.h @@ -21,10 +21,10 @@ class aiObject void readConfig(); void updateSample(const abcSampleSelector& ss); - aiXForm* getXForm(); - aiPolyMesh* getPolyMesh(); - aiCamera* getCamera(); - aiPoints* getPoints(); + aiXForm* getXForm() const; + aiPolyMesh* getPolyMesh() const; + aiCamera* getCamera() const; + aiPoints* getPoints() const; template void eachChildren(const F &f) diff --git a/Plugin/abci/Importer/aiPoints.cpp b/Plugin/abci/Importer/aiPoints.cpp index 415db9c7d..39797179d 100644 --- a/Plugin/abci/Importer/aiPoints.cpp +++ b/Plugin/abci/Importer/aiPoints.cpp @@ -1,9 +1,10 @@ #include "pch.h" -#include "aiInternal.h" +#include "aiInternal.h" #include "aiContext.h" #include "aiObject.h" #include "aiSchema.h" #include "aiPoints.h" +#include "aiMisc.h" // --- @@ -43,7 +44,6 @@ void aiPointsSample::getDataPointer(aiPointsData &data) } if (m_velocities) { m_tmp_velocities.resize(count); - int v_count = std::min(count, (int)m_velocities->size()); for (int i = 0; i < count; ++i) { m_tmp_velocities[i] = (*m_velocities)[m_sort_data[i].second]; } @@ -51,7 +51,6 @@ void aiPointsSample::getDataPointer(aiPointsData &data) } if (m_ids) { m_tmp_ids.resize(count); - int v_count = std::min(count, (int)m_ids->size()); for (int i = 0; i < count; ++i) { m_tmp_ids[i] = (*m_ids)[m_sort_data[i].second]; } @@ -189,8 +188,7 @@ aiPoints::Sample* aiPoints::newSample() aiPoints::Sample* aiPoints::readSample(const uint64_t idx, bool &topologyChanged) { - auto ss = aiIndexToSampleSelector(idx); - auto ss2 = aiIndexToSampleSelector(idx + 1); + auto ss = aiIndexToSampleSelector(idx); DebugLog("aiPoints::readSample(t=%d)", idx); Sample *ret = newSample(); diff --git a/Plugin/abci/Importer/aiPolyMesh.cpp b/Plugin/abci/Importer/aiPolyMesh.cpp index 7e869709d..4efee1a7f 100644 --- a/Plugin/abci/Importer/aiPolyMesh.cpp +++ b/Plugin/abci/Importer/aiPolyMesh.cpp @@ -5,6 +5,7 @@ #include "aiSchema.h" #include "aiPolyMesh.h" #include +#include "../../Tools/Common/Foundation.h" #define MAX_VERTEX_SPLIT_COUNT_16 65000 @@ -30,15 +31,15 @@ Topology::Topology() , m_TreatVertexExtraDataAsStatic(false) , m_use32BitsIndexBuffer(false) { - m_indices.reset(); - m_counts.reset(); + m_faceIndices.reset(); + m_vertexCountPerFace.reset(); } void Topology::clear() { aiLogger::Info("Topology::clear()"); - m_indices.reset(); - m_counts.reset(); + m_faceIndices.reset(); + m_vertexCountPerFace.reset(); m_tangentIndices.clear(); m_tangentsCount = 0; @@ -62,9 +63,9 @@ int Topology::getSplitCount() const int Topology::getSplitCount(aiPolyMeshSample * meshSample, bool forceRefresh) { - if (m_counts && m_indices) + if (m_vertexCountPerFace && m_faceIndices) { - if (m_faceSplitIndices.size() != m_counts->size() || forceRefresh) + if (m_faceSplitIndices.size() != m_vertexCountPerFace->size() || forceRefresh) { updateSplits(meshSample); } @@ -84,35 +85,35 @@ void Topology::updateSplits(aiPolyMeshSample * meshSample) int splitIndex = 0; size_t indexOffset = 0; - size_t ncounts = m_counts->size(); + size_t faceCount = m_vertexCountPerFace->size(); - m_faceSplitIndices.resize(ncounts); // number of faces + m_faceSplitIndices.resize(faceCount); // number of faces m_splits.clear(); - if (m_vertexSharingEnabled && meshSample != NULL && !meshSample->m_ownTopology) // only fixed topologies get this execution path + if (m_vertexSharingEnabled && meshSample != nullptr && !meshSample->m_ownTopology) // only fixed topologies get this execution path { m_splits.push_back(SplitInfo()); SplitInfo *curSplit = &(m_splits.back()); - for (size_t i = 0; ilastFace = ncounts-1; + curSplit->lastFace = faceCount-1; curSplit->vertexCount = m_FixedTopoPositionsIndexes.size(); } else { const int maxVertexSplitCount = m_use32BitsIndexBuffer ? MAX_VERTEX_SPLIT_COUNT_32 : MAX_VERTEX_SPLIT_COUNT_16; - m_splits.reserve(1 + m_indices->size() / maxVertexSplitCount); + m_splits.reserve(1 + m_faceIndices->size() / maxVertexSplitCount); m_splits.push_back(SplitInfo()); SplitInfo *curSplit = &(m_splits.back()); - for (size_t i = 0; iget()[i]; + size_t nv = (size_t)m_vertexCountPerFace->get()[i]; if (curSplit->vertexCount + nv > maxVertexSplitCount) { @@ -202,8 +203,8 @@ int Topology::prepareSubmeshes(const AbcGeom::IV2fGeomParam::Sample &uvs, } if (defaultFacesetIndex != -1) { - facesetIndices.resize(m_counts->size(), -1); - for (size_t i=0; isize(); ++i) + facesetIndices.resize(m_vertexCountPerFace->size(), -1); + for (size_t i=0; isize(); ++i) { if (facesetIndices[i] == -1) { facesetIndices[i] = defaultFacesetIndex; @@ -213,7 +214,7 @@ int Topology::prepareSubmeshes(const AbcGeom::IV2fGeomParam::Sample &uvs, } else { - facesetIndices.resize(m_counts->size(), -1); + facesetIndices.resize(m_vertexCountPerFace->size(), -1); } int nsplits = getSplitCount(sample, false); @@ -225,9 +226,9 @@ int Topology::prepareSubmeshes(const AbcGeom::IV2fGeomParam::Sample &uvs, Submesh &submesh = m_submeshes.back(); - for (size_t i=0; isize(); ++i) + for (size_t i=0; isize(); ++i) { - submesh.triangleCount += (m_counts->get()[i] - 2); + submesh.triangleCount += (m_vertexCountPerFace->get()[i] - 2); } m_splits[0].submeshCount = 1; @@ -235,17 +236,17 @@ int Topology::prepareSubmeshes(const AbcGeom::IV2fGeomParam::Sample &uvs, else { int vertexIndex = 0; - Submesh *curMesh = 0; - const Util::uint32_t *uvIndices = 0; - const abcV2 *uvValues = 0; + Submesh *curMesh; + const Util::uint32_t *uvIndices = nullptr; + const abcV2 *uvValues = nullptr; std::map submeshIndices; std::vector splitSubmeshIndices(nsplits, 0); - for (size_t i=0; isize(); ++i) + for (size_t i=0; isize(); ++i) { - int nv = m_counts->get()[i]; + int nv = m_vertexCountPerFace->get()[i]; if (nv == 0) { @@ -289,7 +290,7 @@ int Topology::prepareSubmeshes(const AbcGeom::IV2fGeomParam::Sample &uvs, if(m_vertexSharingEnabled) curMesh->vertexIndices.reserve(m_FixedTopoPositionsIndexes.size()); else - curMesh->vertexIndices.reserve(m_indices->size()); + curMesh->vertexIndices.reserve(m_faceIndices->size()); split.submeshCount = splitSubmeshIndices[splitIndex]; } @@ -340,11 +341,10 @@ int Topology::getSplitSubmeshCount(int splitIndex) const // --- -aiPolyMeshSample::aiPolyMeshSample(aiPolyMesh *schema, Topology *topo, bool ownTopo, bool vertexSharingEnabled) +aiPolyMeshSample::aiPolyMeshSample(aiPolyMesh *schema, Topology *topo, bool ownTopo) : super(schema) , m_topology(topo) , m_ownTopology(ownTopo) - , m_vertexSharingEnabled(vertexSharingEnabled) { } @@ -406,8 +406,8 @@ void aiPolyMeshSample::computeSmoothNormals(const aiConfig &config) memset(&m_smoothNormals[0], 0, sizeof(m_smoothNormals[0])*m_smoothNormals.size()); - const auto &counts = *(m_topology->m_counts); - const auto &indices = *(m_topology->m_indices); + const auto &counts = *(m_topology->m_vertexCountPerFace); + const auto &indices = *(m_topology->m_faceIndices); const auto &positions = *m_positions; size_t nf = counts.size(); @@ -458,12 +458,12 @@ void aiPolyMeshSample::computeSmoothNormals(const aiConfig &config) for (abcV3& v : m_smoothNormals) { v.normalize(); } } -void aiPolyMeshSample::computeTangentIndices(const aiConfig &config, const abcV3 *inN, bool indexedNormals) +void aiPolyMeshSample::computeTangentIndices(const aiConfig &config, const abcV3 *inN, bool indexedNormals) const { aiLogger::Info("%s: Compute tangent indices...", getSchema()->getObject()->getFullName()); - const auto &counts = *(m_topology->m_counts); - const auto &indices = *(m_topology->m_indices); + const auto &counts = *(m_topology->m_vertexCountPerFace); + const auto &indices = *(m_topology->m_faceIndices); const auto &uvVals = *(m_uvs.getVals()); const auto &uvIdxs = *(m_uvs.getIndices()); const Util::uint32_t *Nidxs = (indexedNormals ? m_normals.getIndices()->get() : 0); @@ -521,8 +521,8 @@ void aiPolyMeshSample::computeTangents(const aiConfig &config, const abcV3 *inN, { aiLogger::Info("%s: Compute %stangents", getSchema()->getObject()->getFullName(), (config.tangentsMode == aiTangentsMode::Smooth ? "smooth " : "")); - const auto &counts = *(m_topology->m_counts); - const auto &indices = *(m_topology->m_indices); + const auto &counts = *(m_topology->m_vertexCountPerFace); + const auto &indices = *(m_topology->m_faceIndices); const auto &positions = *m_positions; const auto &uvVals = *(m_uvs.getVals()); const auto &uvIdxs = *(m_uvs.getIndices()); @@ -676,7 +676,7 @@ void aiPolyMeshSample::updateConfig(const aiConfig &config, bool &topoChanged, b { bool tangentsModeChanged = (config.tangentsMode != m_config.tangentsMode); - const abcV3 *N = 0; + const abcV3 *N = nullptr; bool Nindexed = false; if (smoothNormalsRequired) @@ -755,7 +755,7 @@ void aiPolyMeshSample::getSummary(bool forceRefresh, aiMeshSampleSummary &summar } -void aiPolyMeshSample::getDataPointer(aiPolyMeshData &dst) +void aiPolyMeshSample::getDataPointer(aiPolyMeshData &dst) const { if (m_positions) { dst.positionCount = m_positions->valid() ? (int)m_positions->size() : 0; @@ -785,13 +785,13 @@ void aiPolyMeshSample::getDataPointer(aiPolyMeshData &dst) } if (m_topology) { - if (m_topology->m_indices) { - dst.indexCount = (int)m_topology->m_indices->size(); - dst.indices = (int*)m_topology->m_indices->get(); + if (m_topology->m_faceIndices) { + dst.indexCount = (int)m_topology->m_faceIndices->size(); + dst.indices = (int*)m_topology->m_faceIndices->get(); } - if (m_topology->m_counts) { - dst.faceCount = (int)m_topology->m_counts->size(); - dst.faces = (int*)m_topology->m_counts->get(); + if (m_topology->m_vertexCountPerFace) { + dst.faceCount = (int)m_topology->m_vertexCountPerFace->size(); + dst.faces = (int*)m_topology->m_vertexCountPerFace->get(); dst.triangulatedIndexCount = m_topology->m_triangulatedIndexCount; } } @@ -1095,8 +1095,8 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) float vertexMotionScale = static_cast(m_config.vertexMotionScale); const SplitInfo &split = m_topology->m_splits[splitIndex]; - const auto &counts = *(m_topology->m_counts); - const auto &indices = m_config.turnQuadEdges ? m_topology->m_indicesSwapedFaceWinding.data() : m_topology->m_indices->get(); + const auto &faceCount = *(m_topology->m_vertexCountPerFace); + const auto &indices = m_config.turnQuadEdges ? m_topology->m_indicesSwapedFaceWinding.data() : m_topology->m_faceIndices->get(); const auto &positions = *m_positions; const auto &nextPositions = *m_nextPositions; @@ -1177,7 +1177,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if ( m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1208,7 +1208,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if( m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1236,7 +1236,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if ( m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1265,7 +1265,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if ( m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1298,7 +1298,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if (m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1330,7 +1330,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if ( m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1359,7 +1359,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if ( m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1389,7 +1389,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if ( m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1424,7 +1424,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if ( m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1457,7 +1457,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if ( m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1486,7 +1486,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if ( m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1516,7 +1516,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if ( m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1551,7 +1551,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if (m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1578,7 +1578,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if (m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1602,7 +1602,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if (m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1627,7 +1627,7 @@ void aiPolyMeshSample::fillVertexBuffer(int splitIndex, aiPolyMeshData &data) { for (size_t i=split.firstFace; i<=split.lastFace; ++i) { - int nv = counts[i]; + int nv = faceCount[i]; for (int j = 0; j < nv; ++j, ++o, ++k) { if (m_topology->m_FixedTopoPositionsIndexes.size()) @@ -1704,7 +1704,7 @@ void aiPolyMeshSample::fillSubmeshIndices(const aiSubmeshSummary &summary, aiSub if (it != m_topology->submeshEnd()) { bool ccw = m_config.swapFaceWinding; - const auto &counts = *(m_topology->m_counts); + const auto &counts = *(m_topology->m_vertexCountPerFace); const Submesh &submesh = *it; int index = 0; @@ -1828,11 +1828,11 @@ aiPolyMesh::Sample* aiPolyMesh::newSample() { if (dontUseCache() || !m_varyingTopology) { - sample = new Sample(this, &m_sharedTopology, false, m_config.shareVertices && !m_varyingTopology); + sample = new Sample(this, &m_sharedTopology, false); } else { - sample = new Sample(this, new Topology(), true, m_config.shareVertices && !m_varyingTopology); + sample = new Sample(this, new Topology(), true); } } else @@ -1848,53 +1848,55 @@ aiPolyMesh::Sample* aiPolyMesh::newSample() aiPolyMesh::Sample* aiPolyMesh::readSample(const uint64_t idx, bool &topologyChanged) { + auto ss = aiIndexToSampleSelector(idx); auto ss2 = aiIndexToSampleSelector(idx + 1); DebugLog("aiPolyMesh::readSample(t=%d)", idx); - Sample *ret = newSample(); + Sample *sample = newSample(); + auto topology = sample->m_topology; topologyChanged = m_varyingTopology; - ret->m_topology->EnableVertexSharing(m_config.shareVertices && !m_varyingTopology); - ret->m_topology->Enable32BitsIndexbuffers(m_config.use32BitsIndexBuffer); - ret->m_topology->TreatVertexExtraDataAsStatic(m_config.treatVertexExtraDataAsStatic && !m_varyingTopology); + topology->EnableVertexSharing(m_config.shareVertices && !m_varyingTopology); + topology->Enable32BitsIndexbuffers(m_config.use32BitsIndexBuffer); + topology->TreatVertexExtraDataAsStatic(m_config.treatVertexExtraDataAsStatic && !m_varyingTopology); - if (!ret->m_topology->m_counts || m_varyingTopology) + if (!topology->m_vertexCountPerFace || m_varyingTopology) { DebugLog(" Read face counts"); - m_schema.getFaceCountsProperty().get(ret->m_topology->m_counts, ss); - ret->m_topology->m_triangulatedIndexCount = CalculateTriangulatedIndexCount(*ret->m_topology->m_counts); + m_schema.getFaceCountsProperty().get(topology->m_vertexCountPerFace, ss); + topology->m_triangulatedIndexCount = CalculateTriangulatedIndexCount(*topology->m_vertexCountPerFace); topologyChanged = true; } - if (!ret->m_topology->m_indices || m_varyingTopology) + if (!topology->m_faceIndices || m_varyingTopology) { DebugLog(" Read face indices"); - m_schema.getFaceIndicesProperty().get(ret->m_topology->m_indices, ss); + m_schema.getFaceIndicesProperty().get(topology->m_faceIndices, ss); topologyChanged = true; } DebugLog(" Read positions"); - m_schema.getPositionsProperty().get(ret->m_positions, ss); + m_schema.getPositionsProperty().get(sample->m_positions, ss); if (!m_varyingTopology && m_config.interpolateSamples) { DebugLog(" Read last positions"); - m_schema.getPositionsProperty().get(ret->m_nextPositions, ss2); + m_schema.getPositionsProperty().get(sample->m_nextPositions, ss2); } - ret->m_velocities.reset(); + sample->m_velocities.reset(); auto velocitiesProp = m_schema.getVelocitiesProperty(); if (velocitiesProp.valid()) { DebugLog(" Read velocities"); - velocitiesProp.get(ret->m_velocities, ss); + velocitiesProp.get(sample->m_velocities, ss); } - bool smoothNormalsRequired = ret->smoothNormalsRequired(); + bool smoothNormalsRequired = sample->smoothNormalsRequired(); - ret->m_normals.reset(); + sample->m_normals.reset(); auto normalsParam = m_schema.getNormalsParam(); if (!m_ignoreNormals && normalsParam.valid()) { @@ -1906,16 +1908,16 @@ aiPolyMesh::Sample* aiPolyMesh::readSample(const uint64_t idx, bool &topologyCha normalsParam.getIndexed(m_sharedNormals, ss); } - ret->m_normals = m_sharedNormals; + sample->m_normals = m_sharedNormals; } else { DebugLog(" Read normals"); - normalsParam.getIndexed(ret->m_normals, ss); + normalsParam.getIndexed(sample->m_normals, ss); } } - ret->m_uvs.reset(); + sample->m_uvs.reset(); auto uvsParam = m_schema.getUVsParam(); if (!m_ignoreUVs && uvsParam.valid()) { @@ -1927,61 +1929,61 @@ aiPolyMesh::Sample* aiPolyMesh::readSample(const uint64_t idx, bool &topologyCha uvsParam.getIndexed(m_sharedUVs, ss); } - ret->m_uvs = m_sharedUVs; + sample->m_uvs = m_sharedUVs; } else { DebugLog(" Read uvs"); - uvsParam.getIndexed(ret->m_uvs, ss); + uvsParam.getIndexed(sample->m_uvs, ss); } } auto boundsParam = m_schema.getSelfBoundsProperty(); if (boundsParam) { - boundsParam.get(ret->m_bounds, ss); + boundsParam.get(sample->m_bounds, ss); } if (smoothNormalsRequired) { - ret->computeSmoothNormals(m_config); + sample->computeSmoothNormals(m_config); } - if (ret->tangentsRequired()) + if (sample->tangentsRequired()) { - const abcV3 *normals = 0; + const abcV3 *normals = nullptr; bool indexedNormals = false; if (smoothNormalsRequired) { - normals = &ret->m_smoothNormals[0]; + normals = &sample->m_smoothNormals[0]; } - else if (ret->m_normals.valid()) + else if (sample->m_normals.valid()) { - normals = ret->m_normals.getVals()->get(); - indexedNormals = (ret->m_normals.getScope() == AbcGeom::kFacevaryingScope); + normals = sample->m_normals.getVals()->get(); + indexedNormals = (sample->m_normals.getScope() == AbcGeom::kFacevaryingScope); } - if (normals && ret->m_uvs.valid()) + if (normals && sample->m_uvs.valid()) { // topology may be shared, check tangent indices - if (ret->m_topology->m_tangentIndices.empty() || !m_config.cacheTangentsSplits) + if (topology->m_tangentIndices.empty() || !m_config.cacheTangentsSplits) { - ret->computeTangentIndices(m_config, normals, indexedNormals); + sample->computeTangentIndices(m_config, normals, indexedNormals); } - ret->computeTangents(m_config, normals, indexedNormals); + sample->computeTangents(m_config, normals, indexedNormals); } } if (m_config.turnQuadEdges) { - if (m_varyingTopology || ret->m_topology->m_indicesSwapedFaceWinding.size() == 0) + if (m_varyingTopology || topology->m_indicesSwapedFaceWinding.size() == 0) { - auto faces = ret->m_topology->m_counts; + auto faces = topology->m_vertexCountPerFace; auto totalFaces = faces->size(); - auto * facesIndices = ret->m_topology->m_indices->get(); - ret->m_topology->m_indicesSwapedFaceWinding.reserve(ret->m_topology->m_indices->size()); + auto * facesIndices = topology->m_faceIndices->get(); + topology->m_indicesSwapedFaceWinding.reserve(topology->m_faceIndices->size()); auto index = 0; const uint32_t indexRemap[4] = {3,0,1,2}; @@ -1992,24 +1994,24 @@ aiPolyMesh::Sample* aiPolyMesh::readSample(const uint64_t idx, bool &topologyCha { for (auto i = 0; i < faceSize; i++) { - ret->m_topology->m_indicesSwapedFaceWinding.push_back(facesIndices[index + indexRemap[i]]); + topology->m_indicesSwapedFaceWinding.push_back(facesIndices[index + indexRemap[i]]); } } else { for (auto i = 0; i < faceSize; i++) { - ret->m_topology->m_indicesSwapedFaceWinding.push_back(facesIndices[index + i]); + topology->m_indicesSwapedFaceWinding.push_back(facesIndices[index + i]); } } index += faceSize; } - if (ret->m_uvs.valid()) + if (sample->m_uvs.valid()) { index = 0; - const auto& uvIndices = *ret->m_uvs.getIndices(); - ret->m_topology->m_UvIndicesSwapedFaceWinding.reserve(ret->m_uvs.getIndices()->size()); + const auto& uvIndices = *sample->m_uvs.getIndices(); + topology->m_UvIndicesSwapedFaceWinding.reserve(sample->m_uvs.getIndices()->size()); for (auto faceIndex = 0; faceIndex < totalFaces; faceIndex++) { @@ -2018,14 +2020,14 @@ aiPolyMesh::Sample* aiPolyMesh::readSample(const uint64_t idx, bool &topologyCha { for (auto i = 0; i < faceSize; i++) { - ret->m_topology->m_UvIndicesSwapedFaceWinding.push_back(uvIndices[index + indexRemap[i]]); + topology->m_UvIndicesSwapedFaceWinding.push_back(uvIndices[index + indexRemap[i]]); } } else { for (auto i = 0; i < faceSize; i++) { - ret->m_topology->m_UvIndicesSwapedFaceWinding.push_back(uvIndices[index+i]); + topology->m_UvIndicesSwapedFaceWinding.push_back(uvIndices[index+i]); } } index += faceSize; @@ -2033,15 +2035,15 @@ aiPolyMesh::Sample* aiPolyMesh::readSample(const uint64_t idx, bool &topologyCha } } } - else if (ret->m_topology->m_indicesSwapedFaceWinding.size()>0) + else if (topology->m_indicesSwapedFaceWinding.size()>0) { - ret->m_topology->m_indicesSwapedFaceWinding.clear(); + topology->m_indicesSwapedFaceWinding.clear(); } - if (m_config.shareVertices && !m_varyingTopology && ret != NULL && !ret->m_ownTopology && topologyChanged) - GenerateVerticesToFacesLookup(ret); + if (m_config.shareVertices && !m_varyingTopology && sample != NULL && !sample->m_ownTopology && topologyChanged) + GenerateVerticesToFacesLookup(sample); - return ret; + return sample; } // generates two lookup tables: @@ -2049,11 +2051,12 @@ aiPolyMesh::Sample* aiPolyMesh::readSample(const uint64_t idx, bool &topologyCha // m_FixedTopoPositionsIndexes : list of resulting positions. value is index into the abc "position" vector. size is greter than or equal to "position" array. void aiPolyMesh::GenerateVerticesToFacesLookup(aiPolyMeshSample *sample) const { - auto faces = sample->m_topology->m_counts; + auto topology = sample->m_topology; + auto faces = topology->m_vertexCountPerFace; auto * facesIndices = m_config.turnQuadEdges ? - sample->m_topology->m_indicesSwapedFaceWinding.data() : sample->m_topology->m_indices->get(); - uint32_t totalFaces = faces->size(); + topology->m_indicesSwapedFaceWinding.data() : topology->m_faceIndices->get(); + uint32_t totalFaces = static_cast(faces->size()); // 1st, figure out which face uses which vertices (for sharing identification) std::unordered_map< uint32_t, std::vector> indexesOfFacesValues; @@ -2068,30 +2071,27 @@ void aiPolyMesh::GenerateVerticesToFacesLookup(aiPolyMeshSample *sample) const // 2nd, figure out which vertex can be merged, which cannot. // If all faces targetting a vertex give it the same normal and UV, then it can be shared. const abcV3 * normals = sample->m_smoothNormals.empty() && sample->m_normals.valid() ? sample->m_normals.getVals()->get() : sample->m_smoothNormals.data(); - bool normalsIndexed = !sample->m_smoothNormals.empty() ? false : sample->m_normals.valid() && ( sample->m_normals.getScope() == AbcGeom::kFacevaryingScope); - const int32_t *Vidxs = sample->m_topology->m_indices->get(); - const uint32_t *Nidxs; - if (normalsIndexed) - Nidxs = sample->m_normals.getIndices()->get(); - + bool normalsIndexed = !sample->m_smoothNormals.empty() ? false : sample->m_normals.valid() && (sample->m_normals.getScope() == AbcGeom::kFacevaryingScope); + const uint32_t *Nidxs = normalsIndexed ? sample->m_normals.getIndices()->get() : (uint32_t*)(topology->m_faceIndices->get()); + bool hasUVs = sample->m_uvs.valid(); const auto &uvVals = *(sample->m_uvs.getVals()); - const auto &uvIdxs = m_config.turnQuadEdges || !hasUVs ? sample->m_topology->m_UvIndicesSwapedFaceWinding : *sample->m_uvs.getIndices(); + const auto &uvIdxs = m_config.turnQuadEdges || !hasUVs ? topology->m_UvIndicesSwapedFaceWinding : *sample->m_uvs.getIndices(); - sample->m_topology->m_FixedTopoPositionsIndexes.clear(); - sample->m_topology->m_FaceIndexingReindexed.clear(); - sample->m_topology->m_FaceIndexingReindexed.resize( sample->m_topology->m_indices->size() ); - sample->m_topology->m_FixedTopoPositionsIndexes.reserve(sample->m_positions->size()); - sample->m_topology->m_FreshlyReadTopologyData = true; + topology->m_FixedTopoPositionsIndexes.clear(); + topology->m_FaceIndexingReindexed.clear(); + topology->m_FaceIndexingReindexed.resize(topology->m_faceIndices->size() ); + topology->m_FixedTopoPositionsIndexes.reserve(sample->m_positions->size()); + topology->m_FreshlyReadTopologyData = true; std::unordered_map< uint32_t, std::vector>::iterator itr = indexesOfFacesValues.begin(); while (itr != indexesOfFacesValues.end()) { std::vector& vertexUsages = itr->second; uint32_t vertexUsageIndex = 0; - uint32_t vertexUsageMaxIndex = itr->second.size(); - const Abc::V2f * prevUV = NULL; - const abcV3 * prevN = NULL; + size_t vertexUsageMaxIndex = itr->second.size(); + const Abc::V2f * prevUV = nullptr; + const abcV3 * prevN = nullptr; bool share = true; do { @@ -2099,8 +2099,8 @@ void aiPolyMesh::GenerateVerticesToFacesLookup(aiPolyMeshSample *sample) const // same Normal? if( normals ) { - const abcV3 & N = normals[Nidxs ? (normalsIndexed ? Nidxs[index] : Vidxs[index]) : index]; - if (prevN == NULL) + const abcV3 & N = normals[Nidxs ? Nidxs[index] : index]; + if (prevN == nullptr) prevN = &N; else share = N == *prevN; @@ -2109,7 +2109,7 @@ void aiPolyMesh::GenerateVerticesToFacesLookup(aiPolyMeshSample *sample) const if (hasUVs) { const Abc::V2f & uv = uvVals[uvIdxs[index]]; - if (prevUV == NULL) + if (prevUV == nullptr) prevUV = &uv; else share = uv == *prevUV; @@ -2119,15 +2119,15 @@ void aiPolyMesh::GenerateVerticesToFacesLookup(aiPolyMeshSample *sample) const // Verdict is in for this vertex. if (share) - sample->m_topology->m_FixedTopoPositionsIndexes.push_back(itr->first); + topology->m_FixedTopoPositionsIndexes.push_back(itr->first); std::vector::iterator indexItr = itr->second.begin(); while( indexItr != itr->second.end() ) { if (!share) - sample->m_topology->m_FixedTopoPositionsIndexes.push_back(itr->first); + topology->m_FixedTopoPositionsIndexes.push_back(itr->first); - sample->m_topology->m_FaceIndexingReindexed[*indexItr] = sample->m_topology->m_FixedTopoPositionsIndexes.size() - 1; + topology->m_FaceIndexingReindexed[*indexItr] = topology->m_FixedTopoPositionsIndexes.size() - 1; ++indexItr; } @@ -2135,6 +2135,14 @@ void aiPolyMesh::GenerateVerticesToFacesLookup(aiPolyMeshSample *sample) const } // We now have a lookup for face value indexes that re-routes to shared indexes when possible! + // Splitting does not work with shared vertices, if the resulting mesh still exceeds the splitting threshold, then disable vertex sharing. + const int maxVertexSplitCount = topology->m_use32BitsIndexBuffer ? MAX_VERTEX_SPLIT_COUNT_32 : MAX_VERTEX_SPLIT_COUNT_16; + if(topology->m_FixedTopoPositionsIndexes.size() / maxVertexSplitCount>0) + { + topology->m_vertexSharingEnabled = false; + topology->m_FixedTopoPositionsIndexes.clear(); + topology->m_FaceIndexingReindexed.clear(); + } } void aiPolyMesh::updatePeakIndexCount() const @@ -2149,7 +2157,7 @@ void aiPolyMesh::updatePeakIndexCount() const auto indicesProp = m_schema.getFaceIndicesProperty(); auto countsProp = m_schema.getFaceCountsProperty(); - int numSamples = (int)indicesProp.getNumSamples(); + int numSamples = static_cast(indicesProp.getNumSamples()); if (numSamples == 0) { return; } size_t cMax = 0; diff --git a/Plugin/abci/Importer/aiPolyMesh.h b/Plugin/abci/Importer/aiPolyMesh.h index da59b5635..076631f2e 100644 --- a/Plugin/abci/Importer/aiPolyMesh.h +++ b/Plugin/abci/Importer/aiPolyMesh.h @@ -43,8 +43,6 @@ struct SplitInfo size_t indexOffset; size_t vertexCount; size_t submeshCount; - std::unordered_map verticiesXRefs; // org face index (not it's refred value), index in position vector - size_t uniqueValues; inline SplitInfo(size_t ff=0, size_t io=0) : firstFace(ff) @@ -155,10 +153,10 @@ class Topology inline void TreatVertexExtraDataAsStatic(bool value) { m_TreatVertexExtraDataAsStatic = value; } public: - Abc::Int32ArraySamplePtr m_indices; + Abc::Int32ArraySamplePtr m_faceIndices; std::vector m_indicesSwapedFaceWinding; std::vector m_UvIndicesSwapedFaceWinding; - Abc::Int32ArraySamplePtr m_counts; + Abc::Int32ArraySamplePtr m_vertexCountPerFace; int m_triangulatedIndexCount; Submeshes m_submeshes; @@ -183,7 +181,7 @@ class aiPolyMeshSample : public aiSampleBase { typedef aiSampleBase super; public: - aiPolyMeshSample(aiPolyMesh *schema, Topology *topo, bool ownTopo, bool vertexSharingEnabled ); + aiPolyMeshSample(aiPolyMesh *schema, Topology *topo, bool ownTopo ); virtual ~aiPolyMeshSample(); void updateConfig(const aiConfig &config, bool &topoChanged, bool &dataChanged) override; @@ -196,11 +194,11 @@ typedef aiSampleBase super; bool tangentsRequired() const; void getSummary(bool forceRefresh, aiMeshSampleSummary &summary, aiPolyMeshSample* sample) const; - void getDataPointer(aiPolyMeshData &data); + void getDataPointer(aiPolyMeshData &data) const; void copyData(aiPolyMeshData &data); void copyDataWithTriangulation(aiPolyMeshData &data, bool always_expand_indices); - void computeTangentIndices(const aiConfig &config, const abcV3 *N, bool Nindexed); + void computeTangentIndices(const aiConfig &config, const abcV3 *N, bool Nindexed) const; void computeTangents(const aiConfig &config, const abcV3 *N, bool Nindexed); void computeSmoothNormals(const aiConfig &config); @@ -226,7 +224,6 @@ typedef aiSampleBase super; std::vector m_tangents; Submeshes::iterator m_curSubmesh; - bool m_vertexSharingEnabled; }; diff --git a/Plugin/abci/Importer/aiSchema.h b/Plugin/abci/Importer/aiSchema.h index c99ccbad6..c38fca592 100644 --- a/Plugin/abci/Importer/aiSchema.h +++ b/Plugin/abci/Importer/aiSchema.h @@ -217,7 +217,7 @@ aiSampleBase* aiTSchema::updateSample(const abcSampleSelector& ss) readConfig(); - Sample* sample = NULL; + Sample* sample; bool topologyChanged = false; int64_t sampleIndex = getSampleIndex(ss);