Skip to content

Commit

Permalink
Merge pull request #356 from Unity-Technologies/dev
Browse files Browse the repository at this point in the history
Prepare 2.1.0-preview.2
  • Loading branch information
clusty authored Sep 24, 2020
2 parents 41bca92 + 1077c78 commit 86224c1
Show file tree
Hide file tree
Showing 33 changed files with 478 additions and 47 deletions.
1 change: 0 additions & 1 deletion Source/abci/Importer/aiCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ void aiCamera::readSampleBody(Sample& sample, uint64_t idx)
auto ss = aiIndexToSampleSelector(idx);
auto ss2 = aiIndexToSampleSelector(idx + 1);

readVisibility(sample, ss);
m_schema.get(sample.cam_sp, ss);
m_schema.get(sample.cam_sp2, ss2);
}
Expand Down
2 changes: 0 additions & 2 deletions Source/abci/Importer/aiPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ void aiPoints::readSampleBody(Sample & sample, uint64_t idx)
auto ss2 = aiIndexToSampleSelector(idx + 1);
auto& summary = getSummary();

readVisibility(sample, ss);

// points
if (m_summary.has_points)
{
Expand Down
2 changes: 0 additions & 2 deletions Source/abci/Importer/aiPolyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,6 @@ void aiPolyMesh::readSampleBody(Sample& sample, uint64_t idx)
auto ss = aiIndexToSampleSelector(idx);
auto ss2 = aiIndexToSampleSelector(idx + 1);

readVisibility(sample, ss);

auto& topology = *sample.m_topology;
auto& refiner = topology.m_refiner;
auto& summary = m_summary;
Expand Down
14 changes: 10 additions & 4 deletions Source/abci/Importer/aiSchema.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ class aiTSchema : public aiSchema
int64_t sample_index = getSampleIndex(ss);
auto& config = getConfig();

if (!m_sample || (!m_constant && sample_index != m_last_sample_index) || m_force_update)
auto visible = readVisibility(ss) != 0;
auto updateVisibility = m_sample && m_sample->visibility != visible;
if (!m_sample || (!m_constant && sample_index != m_last_sample_index) || m_force_update ||
updateVisibility)
{
m_sample_index_changed = true;
if (!m_sample)
Expand All @@ -145,6 +148,7 @@ class aiTSchema : public aiSchema

if (sample && config.interpolate_samples)
{
sample->visibility = visible; // read the visibility
auto& ts = *m_time_sampling;
double requested_time = ss.getRequestedTime();
double index_time = ts.getSampleTime(sample_index);
Expand All @@ -165,7 +169,7 @@ class aiTSchema : public aiSchema
m_current_time_interval = (float)interval;

// skip if time offset is not changed
if (sample_index == m_last_sample_index && prev_offset == m_current_time_offset && !m_force_update)
if (sample_index == m_last_sample_index && prev_offset == m_current_time_offset && !m_force_update && !updateVisibility)
sample = nullptr;
}

Expand Down Expand Up @@ -193,14 +197,16 @@ class aiTSchema : public aiSchema
return m_schema.getUserProperties();
}

void readVisibility(Sample& sample, const abcSampleSelector& ss)
int8_t readVisibility(const abcSampleSelector& ss)
{
if (m_visibility_prop.valid() && m_visibility_prop.getNumSamples() > 0)
{
int8_t v;
m_visibility_prop.get(v, ss);
sample.visibility = v != 0;
return v;
}

return 1; // -1 deffered, 0 invisible, 1 visible
}

protected:
Expand Down
3 changes: 1 addition & 2 deletions Source/abci/Importer/aiXForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ void aiXform::readSampleBody(Sample& sample, uint64_t idx)
{
auto ss = aiIndexToSampleSelector(idx);
auto ss2 = aiIndexToSampleSelector(idx + 1);

readVisibility(sample, ss);

m_schema.get(sample.xf_sp, ss);
m_schema.get(sample.xf_sp2, ss2);
}
Expand Down
9 changes: 6 additions & 3 deletions com.unity.formats.alembic/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Changes in Alembic for Unity

## [2.1.0-preview.1] - 2020-06-16
## [2.1.0-preview.2] - 2020-09-24
### Feature
- Added Unity recorder integration (compatible with Unity Recorder >= 2.2.0).

### Changes
- Fixed a bug on Windows where file pointers would leak, and after some time all alembic loads would fail.
- Fixed a bug that caused a crash when exporting a GameObject with a MeshRender but without a MeshFilter Component.
- Fixed a bug where the visibility was not properly read if it was the only animated property of the object.
- When the timeline does discontinuous time updates (scrubbing), the alembic updates the scene synchronously.
- Updated dependency to Burst 1.3.6 (Eliminate the need to have a C++ compiler for x86-64 Mono builds).

## [2.0.1-preview.1] - 2019-08-07
## [2.0.1-preview.1] - 2020-05-29
### Changes
- Fixed a crash in the Alembic Exporter when GameObject names contained / in the name.
- Fixed a bug where the Alembic motion vector direction was inverted.
Expand All @@ -17,7 +20,7 @@
- Fixed a bug where the exported SkinnedMesh scale was wrong if the transform contained a scale change.
- Fixed a bug where the exporter was writing the incorrect Camera rotation parameters.

## [2.0.0-preview.1] - 2019-08-07
## [2.0.0-preview.1] - 2019-12-20
### Changes
- Minimum Unity version is 2019.3.
- Introduced public API for Alembic playback and recording.
Expand Down
Binary file not shown.
40 changes: 21 additions & 19 deletions com.unity.formats.alembic/Documentation~/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Use the Alembic package to import and export [Alembic](http://www.alembic.io/) f

The Alembic package brings in vertex cache data from a 3D modeling software, such as facial animation (skinning) and cloth simulation (dynamics). When you play it back inside Unity, it looks exactly the same as it did in the 3D modeling software.

## Overview
>**Important:** before you start using this package, you must be aware of its [known issues and limitations](#known-issues-and-limitations).

## Features

The Alembic package supports these features:

Expand All @@ -17,33 +20,32 @@ The Alembic package supports these features:

> **Note:** If you need to use the Alembic Clip Recorder feature, you must also install the [Unity Recorder](https://docs.unity3d.com/Packages/com.unity.recorder@latest/index.html) package (minimum version: 2.0.0).
## Requirements

The Alembic Package is compatible with Unity Editor 2018.1 and above.
## Package technical details

The package is available on these 64-bit desktop platforms:
* Microsoft® Windows® 10
* macOS® Sierra (10.12)
* GNU/Linux (CentOS 7, Ubuntu 16.x and Ubuntu 17.x)
### Installation

## Known limitations
To install this package, follow the instructions in the [Package Manager documentation](https://docs.unity3d.com/Manual/upm-ui-install.html).

* Alembic does not support Material import and export.
### Requirements

## Feedback
This version of Alembic for Unity is compatible with the following versions of the Unity Editor:

Tell Unity about your experience using Alembic for Unity on [the Alembic-For-Unity forum](https://forum.unity.com/threads/alembic-for-unity.521649/).
* 2019.3 and later (recommended)

## Installation

To install this package, follow the instructions in the [Package Manager documentation](https://docs.unity3d.com/Packages/com.unity.package-manager-ui@latest).
Alembic for Unity is available on these 64-bit desktop platforms:
* Microsoft® Windows® 10
* macOS® Sierra (10.12)
* GNU/Linux (CentOS 7, Ubuntu 16.x and Ubuntu 17.x)

To verify that the Alembic package is correctly installed, try to add an Alembic component to a GameObject or Camera:
### Known issues and limitations

1. Select a GameObject or Camera and open the Inspector view.
* Alembic for Unity **only supports** the following build targets: **Windows 64-bit**, **MacOS X** and **Linux 64-bit**.
* The Alembic format does not support Material import and export.
* Importing meshes with non-convex polygons results in malformed geometry (for example, triangles with flipped normals).
* Adding an FBX GameObject as a child of an Alembic Prefab prevents you from building your project. Instead, Create a new Prefab with both the FBX GameObject and the Alembic Prefab as children.

2. Click the **Add Component** button and search for **alem**.

If it installed properly, you can see some Alembic components in the list:
## Feedback

![Add Component drop-down menu shows Alembic component options](images/abc_verify.png)
Tell Unity about your experience using Alembic for Unity on [the Alembic-For-Unity forum](https://forum.unity.com/threads/alembic-for-unity.521649/).
55 changes: 50 additions & 5 deletions com.unity.formats.alembic/Editor/Exporter/AlembicExporterEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ namespace UnityEditor.Formats.Alembic.Exporter
[CustomEditor(typeof(AlembicExporter))]
class AlembicExporterEditor : Editor
{
bool m_foldCaptureComponents;
bool m_foldMeshComponents;
SavedBool m_foldCaptureComponents;
SavedBool m_foldMeshComponents;

internal static bool DrawSettings(SerializedObject so,
AlembicRecorderSettings settings,
string pathSettings, ref bool foldCaptureComponents, ref bool foldMeshComponents, bool recorder)
string pathSettings, ref SavedBool foldCaptureComponents, ref SavedBool foldMeshComponents, bool recorder)
{
bool dirty = false;
if (!recorder)
Expand Down Expand Up @@ -119,7 +119,7 @@ internal static bool DrawSettings(SerializedObject so,
EditorGUILayout.PropertyField(so.FindProperty(pathSettings + "assumeNonSkinnedMeshesAreConstant"), new GUIContent("Static MeshRenderers"));
GUILayout.Space(5);

foldCaptureComponents = EditorGUILayout.Foldout(foldCaptureComponents, "Capture Components");
foldCaptureComponents.value = EditorGUILayout.Foldout(foldCaptureComponents, "Capture Components");
if (foldCaptureComponents)
{
EditorGUI.indentLevel++;
Expand All @@ -129,7 +129,8 @@ internal static bool DrawSettings(SerializedObject so,
EditorGUI.indentLevel--;
}

foldMeshComponents = EditorGUILayout.Foldout(foldMeshComponents, "Mesh Components");

foldMeshComponents.value = EditorGUILayout.Foldout(foldMeshComponents, "Mesh Components");
if (foldMeshComponents)
{
EditorGUI.indentLevel++;
Expand All @@ -144,6 +145,12 @@ internal static bool DrawSettings(SerializedObject so,
return dirty;
}

public void OnEnable()
{
m_foldCaptureComponents = new SavedBool($"{target.GetType()}.m_foldCaptureComponents", false);
m_foldMeshComponents = new SavedBool($"{target.GetType()}.m_foldMeshComponents", false);
}

public override void OnInspectorGUI()
{
var t = target as AlembicExporter;
Expand Down Expand Up @@ -201,4 +208,42 @@ public override void OnInspectorGUI()
}
}
}

class SavedBool
{
bool m_Value;
string m_Name;
bool m_Loaded;
public SavedBool(string name, bool value)
{
m_Name = name;
m_Loaded = false;
m_Value = value;
}

private void Load()
{
if (m_Loaded)
return;
m_Loaded = true;
m_Value = EditorPrefs.GetBool(m_Name, m_Value);
}

public bool value
{
get { Load(); return m_Value; }
set
{
Load();
if (m_Value == value)
return;
m_Value = value;
EditorPrefs.SetBool(m_Name, value);
}
}
public static implicit operator bool(SavedBool s)
{
return s.value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor.Callbacks;
using UnityEngine;
using UnityEngine.Formats.Alembic.Importer;
using UnityEngine.SceneManagement;
using Object = UnityEngine.Object;
Expand All @@ -16,11 +17,20 @@ namespace UnityEditor.Formats.Alembic.Importer
static class AlembicBuildPostProcess
{
internal static readonly List<KeyValuePair<string, string>> FilesToCopy = new List<KeyValuePair<string, string>>();
internal static bool HaveAlembicInstances = false;
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
{
if (!TargetIsSupported(target))
{
if (HaveAlembicInstances)
{
Debug.LogWarning(
"Alembic only supports the following build targets: Windows 64-bit, MacOS X, or Linux 64-bit.");
}

HaveAlembicInstances = false;

return;
}

Expand Down Expand Up @@ -54,6 +64,8 @@ public void OnProcessScene(Scene scene, BuildReport report)
{
if (report == null || !AlembicBuildPostProcess.TargetIsSupported(report.summary.platform))
{
AlembicBuildPostProcess.HaveAlembicInstances |= scene.GetRootGameObjects()
.SelectMany(root => root.GetComponentsInChildren<AlembicStreamPlayer>(true)).Any();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ namespace UnityEditor.Formats.Alembic.Recorder
[CustomEditor(typeof(AlembicRecorderSettings))]
class AlembicRecorderSettingsEditor : RecorderEditor
{
bool m_foldCaptureComponents;
bool m_foldMeshComponents;
SavedBool m_foldCaptureComponents;
SavedBool m_foldMeshComponents;

public void OnEnable()
{
base.OnEnable();
m_foldCaptureComponents = new SavedBool($"{target.GetType()}.m_foldCaptureComponents", false);
m_foldMeshComponents = new SavedBool($"{target.GetType()}.m_foldMeshComponents", false);
}

public override void OnInspectorGUI()
{
base.OnInspectorGUI();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ internal class AlembicShotPlayable : PlayableBehaviour

public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
base.ProcessFrame(playable, info, playerData);

if (streamPlayer == null)
return;

var duration = streamPlayer.Duration;
var time = playable.GetTime();
streamPlayer.CurrentTime = (float)(time == duration ? duration : time % duration);
streamPlayer.Update();
streamPlayer.CurrentTime = (float)(time >= duration ? duration : time % duration);
if (info.evaluationType == FrameData.EvaluationType.Playback)
{
streamPlayer.Update();
}
else
{
streamPlayer.UpdateImmediately(streamPlayer.CurrentTime);
}
}
}
}
33 changes: 33 additions & 0 deletions com.unity.formats.alembic/Tests/Editor/VisibilityTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Formats.Alembic.Importer;

namespace UnityEditor.Formats.Alembic.Exporter.UnitTests
{
class VisibilityTests
{
// All the GUIDs in the visibility folder
[TestCase("1416eaf458d8341cfacec4fa81fd0527", TestName = "CameraStaticVisibility")]
[TestCase("98d61f23b1a66466f93ad970d9117b00", TestName = "xTranslateVisibilityAnim")]
[TestCase("38a3731774e2041268d2d2a9d27b69af", TestName = "meshStaticVisibility")]
[TestCase("13c41684e05b74a789421d803ab4cb08", TestName = "meshVisibilityAnim")]
[TestCase("369d852cb291c4c6aa11efc087bf3d2b", TestName = "pointCloudStaticVisibility")]
[TestCase("620c76eda38c746fb8547eaa4ce417c3", TestName = "pointCloudVisibilityAnim")]
[TestCase("b9cfb1cc6cd254c569e584c36db8f1b2", TestName = "xFormStaticVisibility")]
[TestCase("8611f071574ba40368ca1da3092d3e22", TestName = "xFormVisibilityAnim")]
public void VisibilityProperty(string guid)
{
var path = AssetDatabase.GUIDToAssetPath(guid);
var asset = AssetDatabase.LoadMainAssetAtPath(path);
var go = PrefabUtility.InstantiatePrefab(asset) as GameObject;
var player = go.GetComponent<AlembicStreamPlayer>();
var abcNode = go.transform.GetChild(0).gameObject;
player.UpdateImmediately(0);
Assert.IsTrue(abcNode.activeSelf);

player.UpdateImmediately(0.2f);
Assert.IsFalse(abcNode.activeSelf);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions com.unity.formats.alembic/Tests/Runtime/Data/visibility.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Loading

0 comments on commit 86224c1

Please sign in to comment.