Skip to content

Commit 5069375

Browse files
authored
Merge branch 'dev' into light_schema
2 parents 08f95cd + 596fc81 commit 5069375

35 files changed

+1899
-844
lines changed

.yamato/upm-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
test_editors:
22
- version: trunk
3-
- version: 2021.1
3+
- version: 2021.2
44
- version: 2020.3
55
- version: 2019.4
66
test_platforms:
77
- name: win
88
type: Unity::VM
9-
image: package-ci/win10:v1.15.0
9+
image: package-ci/win10:stable
1010
flavor: b1.large
1111
- name: mac
1212
type: Unity::VM::osx

package/com.unity.formats.usd/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changes in usd-unitysdk for Unity
22

3+
## [3.0.0-exp.2] - 2021-09-29
4+
### Features
5+
- All interpolation types are now properly supported for Mesh standard attributes (normals, tangents, uvs, colors).
6+
7+
### Bug Fixes
8+
- Fixed the import of facevarying UVs which showed seams on Meshes.
9+
- Fixed an import bug causing abstract primitives to be loaded as Game Objects.
10+
- Fixed the broken Alembic Import.
11+
- Fixed a crash caused by writing to an invalid USD primitive.
12+
313
## [3.0.0-exp.1] - 2021-06-15
414
### Features
515
- New Import/Export API. See the ImportHelpers and ExportHelpers class (#237).

package/com.unity.formats.usd/Dependencies/USD.NET.Unity/Geometry/GprimSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public class GprimSample : BoundableSample
2525
// writing color, however the cost of recombining these in C# is too great (time/memory), so
2626
// instead, they are fused during serialization in C++.
2727
[VertexData, FusedDisplayColor]
28-
public Color[] colors;
28+
public Primvar<Color[]> colors = new Primvar<Color[]>();
2929
}
3030
}

package/com.unity.formats.usd/Dependencies/USD.NET.Unity/Geometry/MeshSampleBase.cs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ public class MeshSampleBase : PointBasedSample
2424
public int[] faceVertexIndices;
2525
public Vector3[] points;
2626
public Vector3[] normals;
27-
[VertexData]
28-
public Vector4[] tangents;
27+
[VertexData] public Vector4[] tangents;
2928

3029
// Regarding UVs: this feels like a very specific solution for "default primvar data", which
3130
// is fine, but this type of data may be specific to a given pipeline, though here it is
@@ -37,21 +36,12 @@ public class MeshSampleBase : PointBasedSample
3736
/// When not explicitly specified by the shader, "st" should be considered the default uv set.
3837
/// </summary>
3938
/// <remarks>
40-
/// UV object types should be Vector{2,3,4}[], List of Vector{2,3,4}, or null.
39+
/// UV object types should be Vector{2,3}[], List of Vector{2,3}, or null.
4140
/// </remarks>
42-
[VertexData] public object st;
43-
44-
/// <summary>
45-
/// When primvars:st:indices are specified, the st texture coordinates are indexed like
46-
/// vertex positions.
47-
/// </summary>
48-
[UsdNamespace("primvars:st")]
49-
public int[] indices;
50-
51-
// These are Unity friendly UV sets.
52-
[VertexData] public object uv;
53-
[VertexData] public object uv2;
54-
[VertexData] public object uv3;
55-
[VertexData] public object uv4;
41+
public Primvar<object> st = new Primvar<object>();
42+
public Primvar<object> uv = new Primvar<object>();
43+
public Primvar<object> uv2 = new Primvar<object>();
44+
public Primvar<object> uv3 = new Primvar<object>();
45+
public Primvar<object> uv4 = new Primvar<object>();
5646
}
5747
}

package/com.unity.formats.usd/Dependencies/USD.NET.Unity/USD.NET.Unity.api

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ namespace USD.NET.Unity
107107

108108
[USD.NET.UsdSchema(@"UsdGeomGprim")] public class GprimSample : USD.NET.Unity.BoundableSample
109109
{
110-
[USD.NET.FusedDisplayColor] [USD.NET.VertexData] public UnityEngine.Color[] colors;
110+
[USD.NET.FusedDisplayColor] [USD.NET.VertexData] public USD.NET.Primvar<UnityEngine.Color[]> colors;
111111
public GprimSample() {}
112112
}
113113

@@ -164,15 +164,14 @@ namespace USD.NET.Unity
164164
[USD.NET.UsdSchema(@"Mesh")] public class MeshSampleBase : USD.NET.Unity.PointBasedSample
165165
{
166166
public int[] faceVertexIndices;
167-
[USD.NET.UsdNamespace(@"primvars:st")] public int[] indices;
168167
public UnityEngine.Vector3[] normals;
169168
public UnityEngine.Vector3[] points;
170-
[USD.NET.VertexData] public object st;
169+
public USD.NET.Primvar<object> st;
171170
[USD.NET.VertexData] public UnityEngine.Vector4[] tangents;
172-
[USD.NET.VertexData] public object uv;
173-
[USD.NET.VertexData] public object uv2;
174-
[USD.NET.VertexData] public object uv3;
175-
[USD.NET.VertexData] public object uv4;
171+
public USD.NET.Primvar<object> uv;
172+
public USD.NET.Primvar<object> uv2;
173+
public USD.NET.Primvar<object> uv3;
174+
public USD.NET.Primvar<object> uv4;
176175
public MeshSampleBase() {}
177176
}
178177

package/com.unity.formats.usd/Dependencies/USD.NET/USD.NET.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14782,6 +14782,8 @@ namespace USD.NET
1478214782
public class Primvar<T> : USD.NET.PrimvarBase, USD.NET.ValueAccessor
1478314783
{
1478414784
public T value;
14785+
public bool IsArray { get; }
14786+
public int Length { get; }
1478514787
public Primvar() {}
1478614788
public virtual object GetValue();
1478714789
public virtual System.Type GetValueType();

package/com.unity.formats.usd/Dependencies/USD.NET/serialization/Primvar.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ public Type GetValueType()
142142
return typeof(T);
143143
}
144144

145+
public bool IsArray => typeof(T).IsArray;
146+
147+
public int Length => (IsArray && value != null) ? (value as Array).Length : 0;
148+
145149
// Furture work: support IdTargets. See "ID Attribute API" here:
146150
// http://graphics.pixar.com/usd/docs/api/class_usd_geom_primvar.html
147151
}

package/com.unity.formats.usd/Dependencies/USD.NET/serialization/Scene.cs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -710,38 +710,55 @@ public void Read<T>(SdfPath path, System.Reflection.PropertyInfo propInfo, ref T
710710
memberValue = (T)o;
711711
}
712712

713-
static readonly HashSet<System.Reflection.MemberInfo> m_empty = new HashSet<System.Reflection.MemberInfo>();
714-
private void ReadInternal<T>(SdfPath path,
713+
void ReadInternal<T>(SdfPath path,
715714
T sample,
716715
UsdTimeCode timeCode) where T : SampleBase
717716
{
718717
var prim = GetUsdPrim(path);
719718
if (!prim) { return; }
720719

721720
var accessMap = AccessMask;
722-
bool? mayVary = false;
723721
HashSet<System.Reflection.MemberInfo> dynamicMembers = null;
724722

723+
// mayVary is nullable and has an accumulation semantic:
724+
// null = members have already been checked for animation
725+
// false = no dynamic members found
726+
// true = at least one member has been found dynamic
727+
bool? mayVary = false;
728+
729+
// When reading animation data, the access map optimizes which prim members need to be read
725730
if (accessMap != null)
726731
{
727-
lock (m_stageLock) {
728-
if (!accessMap.Included.TryGetValue(path, out dynamicMembers)
729-
&& IsPopulatingAccessMask)
732+
var populatingAccessMask = IsPopulatingAccessMask;
733+
lock (m_stageLock)
734+
{
735+
// Check which attributes of the prim are dynamic
736+
var primFound = accessMap.Included.TryGetValue(path, out dynamicMembers);
737+
738+
// Populating the access map happens when reading the first frame of animation
739+
// so if the prim is not already in the map add it and everything will be deserialized
740+
if (!primFound && populatingAccessMask)
730741
{
731742
dynamicMembers = new HashSet<System.Reflection.MemberInfo>();
732743
accessMap.Included.Add(path, dynamicMembers);
733744
}
734745
}
735746

736-
if (!IsPopulatingAccessMask)
747+
// If we are not populating the access map it means it's been done already so only dynamic members should be deserialized
748+
if (!populatingAccessMask)
737749
{
750+
// If there are no dynamic members, then no need to call deserialize
751+
if (dynamicMembers == null)
752+
return;
753+
754+
// Notify the deserialization service that only dynamic members should be read
738755
mayVary = null;
739-
dynamicMembers = dynamicMembers ?? m_empty;
740756
}
741757
}
742758

743759
m_usdIo.Deserialize(sample, prim, timeCode, dynamicMembers, ref mayVary);
744760

761+
// If no members are varying, remove the prim from the access map.
745762
lock (m_stageLock) {
746763
if (accessMap != null && mayVary != null)
747764
{

package/com.unity.formats.usd/Dependencies/USD.NET/serialization/UsdIo.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System;
1616
using System.Collections.Generic;
1717
using System.Reflection;
18+
using pxr;
1819

1920
namespace USD.NET
2021
{
@@ -591,8 +592,8 @@ bool ReadAttr(string attrName, Type csType, ref object csValue, pxr.UsdTimeCode
591592
{
592593
bool isNewPrimvar = csValue != null
593594
&& csType.IsGenericType
594-
&& csType.GetGenericTypeDefinition() == typeof(Primvar<>);
595-
bool isPrimvar = Reflect.IsPrimvar(memberInfo) || isNewPrimvar;
595+
&& csType.GetGenericTypeDefinition() == typeof(Primvar<>); // This is true for Primvar type only
596+
bool isPrimvar = Reflect.IsPrimvar(memberInfo) || isNewPrimvar; // This is true for VertexData + Primvar type...
596597
string ns = IntrinsicTypeConverter.JoinNamespace(usdNamespace,
597598
Reflect.GetNamespace(memberInfo));
598599

@@ -827,22 +828,33 @@ bool ReadAttr(string attrName, Type csType, ref object csValue, pxr.UsdTimeCode
827828
// If this is a Primvar<T>, read the associated primvar metadata and indices.
828829
if (pvBase != null)
829830
{
830-
var attr = prim.GetAttribute(sdfAttrName);
831+
UsdAttribute attr = null;
832+
if (Reflect.IsFusedDisplayColor(memberInfo))
833+
{
834+
var gprim = new pxr.UsdGeomGprim(prim);
835+
if (gprim)
836+
attr = gprim.GetDisplayColorAttr();
837+
}
838+
else
839+
{
840+
attr = prim.GetAttribute(sdfAttrName);
841+
}
842+
831843
if (attr)
832844
{
833845
var pv = new pxr.UsdGeomPrimvar(attr);
834846
// ElementSize and Interpolation are not animatable, so they do not affect mayVary.
835847
pvBase.elementSize = pv.GetElementSize();
836848
pvBase.SetInterpolationToken(pv.GetInterpolation());
837849

838-
// Indices are a first class attribute and may vary over time.
850+
// Primvars can be indexed and indices are a first class attribute and may vary over time.
839851
var indices = pv.GetIndicesAttr();
840852
if (indices)
841853
{
842854
if (accessMap != null)
843855
{
844856
if (indices.GetVariability() == pxr.SdfVariability.SdfVariabilityVarying
845-
|| indices.ValueMightBeTimeVarying())
857+
&& indices.ValueMightBeTimeVarying())
846858
{
847859
accessMap.Add(memberInfo);
848860
mayVary |= true;

package/com.unity.formats.usd/Editor/Unity.Formats.USD.Editor.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Unity.Formats.USD
2222
[UnityEditor.Callbacks.PostProcessBuild(1)] public static void OnPostprocessBuild(UnityEditor.BuildTarget target, string pathToBuiltProject);
2323
}
2424

25-
[UnityEditor.CustomEditor(typeof(Unity.Formats.USD.UsdLayerStack))] public class UsdLayerStackEditor : UnityEditor.Experimental.AssetImporters.ScriptedImporterEditor
25+
[UnityEditor.CustomEditor(typeof(Unity.Formats.USD.UsdLayerStack))] public class UsdLayerStackEditor : UnityEditor.AssetImporters.ScriptedImporterEditor
2626
{
2727
public UsdLayerStackEditor() {}
2828
public virtual void OnInspectorGUI();

0 commit comments

Comments
 (0)