Skip to content

Commit

Permalink
Add support for up to 4 texcoords
Browse files Browse the repository at this point in the history
Also, don't warn about texcoord2 coming in from Tilt Brush glTF.
More recent versions of Tilt Brush allow putting stroke timestamp
data into texcoord2.

Change-Id: Id000b0151176f0e4ab2a0cca17eb37ba24f6604c
  • Loading branch information
dubois committed Aug 30, 2019
1 parent 5dd660d commit 5b385bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions UnitySDK/Assets/TiltBrush/Scripts/BrushDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum Semantic {
XyIsUvZIsDistance,
UnitlessVector,
XyIsUv,
Timestamp,
}

public Material Material { get { return m_Material; } }
Expand Down
2 changes: 1 addition & 1 deletion UnitySDK/Assets/TiltBrush/Scripts/Gltf/GltfSchemaCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public class MeshPrecursor {
public Vector3[] normals;
public Color[] colors;
public Vector4[] tangents;
public Array[] uvSets = new Array[2];
public Array[] uvSets = new Array[4];
public int[] triangles;
}

Expand Down
30 changes: 19 additions & 11 deletions UnitySDK/Assets/TiltBrush/Scripts/Gltf/ImportGltf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@ private static void StoreDataInMesh(
ImportState state,
BrushDescriptor desc, string semantic, Array data,
MeshPrecursor mesh) {
int txcChannel;
switch (semantic) {
case "POSITION":
ChangeBasisAndApplyScale(data, Semantic.Position, state.scaleFactor, state.unityFromGltf);
Expand Down Expand Up @@ -872,20 +873,24 @@ private static void StoreDataInMesh(
data, Semantic.UnitlessVector, state.scaleFactor, state.unityFromGltf);
mesh.tangents = (Vector4[]) data;
break;
case "TEXCOORD_0": {
var ptSemantic = GetTexcoordSemantic(state, desc, 0);
case "TEXCOORD_0":
txcChannel = 0;
goto GenericTexcoord;
case "TEXCOORD_1":
txcChannel = 1;
goto GenericTexcoord;
case "TEXCOORD_2":
txcChannel = 2;
goto GenericTexcoord;
case "TEXCOORD_3":
txcChannel = 3;
goto GenericTexcoord;
GenericTexcoord:
var ptSemantic = GetTexcoordSemantic(state, desc, txcChannel);
ChangeBasisAndApplyScale(data, ptSemantic, state.scaleFactor, state.unityFromGltf);
ChangeUvBasis(data, ptSemantic);
mesh.uvSets[0] = data;
mesh.uvSets[txcChannel] = data;
break;
}
case "TEXCOORD_1": {
var ptSemantic = GetTexcoordSemantic(state, desc, 1);
ChangeBasisAndApplyScale(data, ptSemantic, state.scaleFactor, state.unityFromGltf);
ChangeUvBasis(data, ptSemantic);
mesh.uvSets[1] = data;
break;
}
case "VERTEXID":
// This was an attempt to get vertex id in webgl, but it didn't work out.
// The data is not fully hooked-up in the gltf, and it doesn't make its way to THREE.
Expand Down Expand Up @@ -992,6 +997,9 @@ static Semantic GetTexcoordSemantic(ImportState state, BrushDescriptor desc, int
return desc.m_uv0Semantic;
} else if (uvChannel == 1) {
return desc.m_uv1Semantic;
} else if (uvChannel == 2) {
// All brushes use texcoord2 as (optional) timestamp data
return Semantic.Timestamp;
} else {
Debug.LogWarningFormat("Unexpected TB texcoord: {0}", uvChannel);
return Semantic.Unspecified;
Expand Down

0 comments on commit 5b385bc

Please sign in to comment.