Skip to content

Commit

Permalink
Merge branch 'dev' into light_schema
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyskeys authored and chenmiwei committed Oct 8, 2021
2 parents 08f95cd + 596fc81 commit 3af5bcb
Show file tree
Hide file tree
Showing 37 changed files with 1,967 additions and 844 deletions.
4 changes: 2 additions & 2 deletions .yamato/upm-ci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
test_editors:
- version: trunk
- version: 2021.1
- version: 2021.2
- version: 2020.3
- version: 2019.4
test_platforms:
- name: win
type: Unity::VM
image: package-ci/win10:v1.15.0
image: package-ci/win10:stable
flavor: b1.large
- name: mac
type: Unity::VM::osx
Expand Down
10 changes: 10 additions & 0 deletions package/com.unity.formats.usd/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changes in usd-unitysdk for Unity

## [3.0.0-exp.2] - 2021-09-29
### Features
- All interpolation types are now properly supported for Mesh standard attributes (normals, tangents, uvs, colors).

### Bug Fixes
- Fixed the import of facevarying UVs which showed seams on Meshes.
- Fixed an import bug causing abstract primitives to be loaded as Game Objects.
- Fixed the broken Alembic Import.
- Fixed a crash caused by writing to an invalid USD primitive.

## [3.0.0-exp.1] - 2021-06-15
### Features
- New Import/Export API. See the ImportHelpers and ExportHelpers class (#237).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public class GprimSample : BoundableSample
// writing color, however the cost of recombining these in C# is too great (time/memory), so
// instead, they are fused during serialization in C++.
[VertexData, FusedDisplayColor]
public Color[] colors;
public Primvar<Color[]> colors = new Primvar<Color[]>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public class MeshSampleBase : PointBasedSample
public int[] faceVertexIndices;
public Vector3[] points;
public Vector3[] normals;
[VertexData]
public Vector4[] tangents;
[VertexData] public Vector4[] tangents;

// Regarding UVs: this feels like a very specific solution for "default primvar data", which
// is fine, but this type of data may be specific to a given pipeline, though here it is
Expand All @@ -37,21 +36,12 @@ public class MeshSampleBase : PointBasedSample
/// When not explicitly specified by the shader, "st" should be considered the default uv set.
/// </summary>
/// <remarks>
/// UV object types should be Vector{2,3,4}[], List of Vector{2,3,4}, or null.
/// UV object types should be Vector{2,3}[], List of Vector{2,3}, or null.
/// </remarks>
[VertexData] public object st;

/// <summary>
/// When primvars:st:indices are specified, the st texture coordinates are indexed like
/// vertex positions.
/// </summary>
[UsdNamespace("primvars:st")]
public int[] indices;

// These are Unity friendly UV sets.
[VertexData] public object uv;
[VertexData] public object uv2;
[VertexData] public object uv3;
[VertexData] public object uv4;
public Primvar<object> st = new Primvar<object>();
public Primvar<object> uv = new Primvar<object>();
public Primvar<object> uv2 = new Primvar<object>();
public Primvar<object> uv3 = new Primvar<object>();
public Primvar<object> uv4 = new Primvar<object>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace USD.NET.Unity

[USD.NET.UsdSchema(@"UsdGeomGprim")] public class GprimSample : USD.NET.Unity.BoundableSample
{
[USD.NET.FusedDisplayColor] [USD.NET.VertexData] public UnityEngine.Color[] colors;
[USD.NET.FusedDisplayColor] [USD.NET.VertexData] public USD.NET.Primvar<UnityEngine.Color[]> colors;
public GprimSample() {}
}

Expand Down Expand Up @@ -164,15 +164,14 @@ namespace USD.NET.Unity
[USD.NET.UsdSchema(@"Mesh")] public class MeshSampleBase : USD.NET.Unity.PointBasedSample
{
public int[] faceVertexIndices;
[USD.NET.UsdNamespace(@"primvars:st")] public int[] indices;
public UnityEngine.Vector3[] normals;
public UnityEngine.Vector3[] points;
[USD.NET.VertexData] public object st;
public USD.NET.Primvar<object> st;
[USD.NET.VertexData] public UnityEngine.Vector4[] tangents;
[USD.NET.VertexData] public object uv;
[USD.NET.VertexData] public object uv2;
[USD.NET.VertexData] public object uv3;
[USD.NET.VertexData] public object uv4;
public USD.NET.Primvar<object> uv;
public USD.NET.Primvar<object> uv2;
public USD.NET.Primvar<object> uv3;
public USD.NET.Primvar<object> uv4;
public MeshSampleBase() {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14782,6 +14782,8 @@ namespace USD.NET
public class Primvar<T> : USD.NET.PrimvarBase, USD.NET.ValueAccessor
{
public T value;
public bool IsArray { get; }
public int Length { get; }
public Primvar() {}
public virtual object GetValue();
public virtual System.Type GetValueType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ public Type GetValueType()
return typeof(T);
}

public bool IsArray => typeof(T).IsArray;

public int Length => (IsArray && value != null) ? (value as Array).Length : 0;

// Furture work: support IdTargets. See "ID Attribute API" here:
// http://graphics.pixar.com/usd/docs/api/class_usd_geom_primvar.html
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,38 +710,55 @@ public void Read<T>(SdfPath path, System.Reflection.PropertyInfo propInfo, ref T
memberValue = (T)o;
}

static readonly HashSet<System.Reflection.MemberInfo> m_empty = new HashSet<System.Reflection.MemberInfo>();
private void ReadInternal<T>(SdfPath path,
void ReadInternal<T>(SdfPath path,
T sample,
UsdTimeCode timeCode) where T : SampleBase
{
var prim = GetUsdPrim(path);
if (!prim) { return; }

var accessMap = AccessMask;
bool? mayVary = false;
HashSet<System.Reflection.MemberInfo> dynamicMembers = null;

// mayVary is nullable and has an accumulation semantic:
// null = members have already been checked for animation
// false = no dynamic members found
// true = at least one member has been found dynamic
bool? mayVary = false;

// When reading animation data, the access map optimizes which prim members need to be read
if (accessMap != null)
{
lock (m_stageLock) {
if (!accessMap.Included.TryGetValue(path, out dynamicMembers)
&& IsPopulatingAccessMask)
var populatingAccessMask = IsPopulatingAccessMask;
lock (m_stageLock)
{
// Check which attributes of the prim are dynamic
var primFound = accessMap.Included.TryGetValue(path, out dynamicMembers);

// Populating the access map happens when reading the first frame of animation
// so if the prim is not already in the map add it and everything will be deserialized
if (!primFound && populatingAccessMask)
{
dynamicMembers = new HashSet<System.Reflection.MemberInfo>();
accessMap.Included.Add(path, dynamicMembers);
}
}

if (!IsPopulatingAccessMask)
// If we are not populating the access map it means it's been done already so only dynamic members should be deserialized
if (!populatingAccessMask)
{
// If there are no dynamic members, then no need to call deserialize
if (dynamicMembers == null)
return;

// Notify the deserialization service that only dynamic members should be read
mayVary = null;
dynamicMembers = dynamicMembers ?? m_empty;
}
}

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

// If no members are varying, remove the prim from the access map.
lock (m_stageLock) {
if (accessMap != null && mayVary != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using pxr;

namespace USD.NET
{
Expand Down Expand Up @@ -591,8 +592,8 @@ bool ReadAttr(string attrName, Type csType, ref object csValue, pxr.UsdTimeCode
{
bool isNewPrimvar = csValue != null
&& csType.IsGenericType
&& csType.GetGenericTypeDefinition() == typeof(Primvar<>);
bool isPrimvar = Reflect.IsPrimvar(memberInfo) || isNewPrimvar;
&& csType.GetGenericTypeDefinition() == typeof(Primvar<>); // This is true for Primvar type only
bool isPrimvar = Reflect.IsPrimvar(memberInfo) || isNewPrimvar; // This is true for VertexData + Primvar type...
string ns = IntrinsicTypeConverter.JoinNamespace(usdNamespace,
Reflect.GetNamespace(memberInfo));

Expand Down Expand Up @@ -827,22 +828,33 @@ bool ReadAttr(string attrName, Type csType, ref object csValue, pxr.UsdTimeCode
// If this is a Primvar<T>, read the associated primvar metadata and indices.
if (pvBase != null)
{
var attr = prim.GetAttribute(sdfAttrName);
UsdAttribute attr = null;
if (Reflect.IsFusedDisplayColor(memberInfo))
{
var gprim = new pxr.UsdGeomGprim(prim);
if (gprim)
attr = gprim.GetDisplayColorAttr();
}
else
{
attr = prim.GetAttribute(sdfAttrName);
}

if (attr)
{
var pv = new pxr.UsdGeomPrimvar(attr);
// ElementSize and Interpolation are not animatable, so they do not affect mayVary.
pvBase.elementSize = pv.GetElementSize();
pvBase.SetInterpolationToken(pv.GetInterpolation());

// Indices are a first class attribute and may vary over time.
// Primvars can be indexed and indices are a first class attribute and may vary over time.
var indices = pv.GetIndicesAttr();
if (indices)
{
if (accessMap != null)
{
if (indices.GetVariability() == pxr.SdfVariability.SdfVariabilityVarying
|| indices.ValueMightBeTimeVarying())
&& indices.ValueMightBeTimeVarying())
{
accessMap.Add(memberInfo);
mayVary |= true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Unity.Formats.USD
[UnityEditor.Callbacks.PostProcessBuild(1)] public static void OnPostprocessBuild(UnityEditor.BuildTarget target, string pathToBuiltProject);
}

[UnityEditor.CustomEditor(typeof(Unity.Formats.USD.UsdLayerStack))] public class UsdLayerStackEditor : UnityEditor.Experimental.AssetImporters.ScriptedImporterEditor
[UnityEditor.CustomEditor(typeof(Unity.Formats.USD.UsdLayerStack))] public class UsdLayerStackEditor : UnityEditor.AssetImporters.ScriptedImporterEditor
{
public UsdLayerStackEditor() {}
public virtual void OnInspectorGUI();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,6 @@ public string usdFullPath
[Tooltip("Import policy for primvars:tangent")]
public ImportMode m_tangents;

[Tooltip("Import policy for primvars:st")]
public ImportMode m_st;

// Obselete, will be removed in the future.
[HideInInspector] public ImportMode m_texcoord1;
[HideInInspector] public ImportMode m_texcoord2;
[HideInInspector] public ImportMode m_texcoord3;

// ----------------------------------------------------------------------------------------- //
// Lightmap UV Unwrapping.
// ----------------------------------------------------------------------------------------- //
Expand Down Expand Up @@ -168,6 +160,7 @@ public string usdFullPath
#if false
[Header("Export Settings")]
public bool m_exportCameras = true;
public bool m_exportLights = true;
public bool m_exportMeshes = true;
public bool m_exportSkinning = true;
public bool m_exportTransforms = true;
Expand Down Expand Up @@ -278,10 +271,6 @@ public void OptionsToState(SceneImportOptions options)
m_color = options.meshOptions.color;
m_normals = options.meshOptions.normals;
m_tangents = options.meshOptions.tangents;
m_st = options.meshOptions.texcoord0;
m_texcoord1 = options.meshOptions.texcoord1;
m_texcoord2 = options.meshOptions.texcoord2;
m_texcoord3 = options.meshOptions.texcoord3;
m_generateLightmapUVs = options.meshOptions.generateLightmapUVs;

m_unwrapAngleError = options.meshOptions.unwrapAngleError;
Expand Down Expand Up @@ -331,10 +320,6 @@ public void StateToOptions(ref SceneImportOptions options)
options.meshOptions.color = m_color;
options.meshOptions.normals = m_normals;
options.meshOptions.tangents = m_tangents;
options.meshOptions.texcoord0 = m_st;
options.meshOptions.texcoord1 = m_texcoord1;
options.meshOptions.texcoord2 = m_texcoord2;
options.meshOptions.texcoord3 = m_texcoord3;
options.meshOptions.generateLightmapUVs = m_generateLightmapUVs;

options.meshOptions.unwrapAngleError = m_unwrapAngleError;
Expand Down Expand Up @@ -373,7 +358,7 @@ public Scene GetScene()
{
InitUsd.Initialize();

if (m_lastScene == null || m_lastScene.Stage == null || SceneFileChanged())
if (m_lastScene?.Stage == null || SceneFileChanged())
{
pxr.UsdStage stage = null;
if (string.IsNullOrEmpty(usdFullPath))
Expand Down Expand Up @@ -769,11 +754,6 @@ public static void PrepOptionsForTimeChange(ref SceneImportOptions options)

// Note that tangent and Normals must be updated when the mesh deforms.
options.importHierarchy = false;

options.meshOptions.texcoord0 = ImportMode.Ignore;
options.meshOptions.texcoord1 = ImportMode.Ignore;
options.meshOptions.texcoord2 = ImportMode.Ignore;
options.meshOptions.texcoord3 = ImportMode.Ignore;
}

/// <summary>
Expand Down
Loading

0 comments on commit 3af5bcb

Please sign in to comment.