Skip to content

Commit

Permalink
Minor bug fixes and code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasch-unity3d committed Dec 7, 2017
1 parent 9929eab commit fee0a5f
Show file tree
Hide file tree
Showing 19 changed files with 333 additions and 312 deletions.
Expand Up @@ -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<string> varyingTopologyMeshNames = new List<string>();
[SerializeField] public List<string> splittingMeshNames = new List<string>();

public override void OnImportAsset(AssetImportContext ctx)
{
Expand All @@ -98,7 +99,7 @@ public override void OnImportAsset(AssetImportContext ctx)
go.transform.localScale *= scaleFactor;

AlembicStreamDescriptor streamDescriptor = ScriptableObject.CreateInstance<AlembicStreamDescriptor>();
streamDescriptor.name = go.name + "ABCDesc";
streamDescriptor.name = go.name + "_ABCDesc";
streamDescriptor.pathToAbc = destPath;
streamDescriptor.settings = streamSettings;

Expand All @@ -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;
Expand Down Expand Up @@ -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<string>();
splittingMeshNames = new List<string>();

CollectSubAssets(ctx, root, material);

streamDescr.hasVaryingTopology = varyingTopologyMeshNames.Count > 0;
Expand All @@ -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<MeshFilter>();
Expand Down
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down
Expand Up @@ -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);
Expand Down
Expand Up @@ -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);
}
}
}
Expand Down
Binary file modified AlembicImporter/ProjectSettings/ProjectSettings.asset
Binary file not shown.
2 changes: 1 addition & 1 deletion AlembicImporter/ProjectSettings/ProjectVersion.txt
@@ -1 +1 @@
m_EditorVersion: 2017.3.0b11
m_EditorVersion: 2018.1.0b1
8 changes: 4 additions & 4 deletions Plugin/abci/Foundation/aiLogger.cpp
Expand Up @@ -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())
{
Expand All @@ -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())
{
Expand All @@ -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())
{
Expand All @@ -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())
{
Expand Down

0 comments on commit fee0a5f

Please sign in to comment.