Skip to content

Commit

Permalink
Fix b/38321023: Hypercolor audio-reactivity
Browse files Browse the repository at this point in the history
Hypercolor texcoord0.z is 10x too large.
The bug will be fixed in TB14; fix data from earlier versions.

Change-Id: Ib37cb9a3c81f7157f11cf42bf8d18352408e58c7
  • Loading branch information
dubois committed Aug 28, 2017
1 parent eac10cc commit 5bf7d01
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions UnitySDK/Assets/TiltBrush/Scripts/Editor/ModelImportSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ Material OnAssignMaterialModel(Material material, Renderer renderer) {
PerformTexcoordCoordinateConversion(desc, mesh, 0);
PerformTexcoordCoordinateConversion(desc, mesh, 1);
}
if (m_Info.tiltBrushVersion.Value.major < 14 &&
desc.m_Guid == new Guid("e8ef32b1-baa8-460a-9c2c-9cf8506794f5")) {
// Pre-TB14, Tilt Brush hadn't set the "Z is distance" semantic and texcoord0.z
// ended up in decimeters
FixupHypercolorTexcoord(desc, mesh);
}

if (desc.m_IsParticle) {
// Would like to do this in OnPreprocessModel, but we don't yet
Expand Down Expand Up @@ -214,6 +220,24 @@ static int GetUvsetSize(BrushDescriptor desc, int uvSet) {
}
}

void FixupHypercolorTexcoord(BrushDescriptor desc, Mesh mesh) {
int uvSet = 0;
var semantic = GetUvsetSemantic(desc, uvSet);
if (semantic != BrushDescriptor.Semantic.ZIsDistance ||
GetUvsetSize(desc, uvSet) != 3) {
LogWarningWithContext("Not hypercolor?");
}

var data = new List<Vector3>();
mesh.GetUVs(uvSet, data);
for (int i = 0; i < data.Count; ++i) {
Vector3 tmp = data[i];
tmp.z *= .1f;
data[i] = tmp;
}
mesh.SetUVs(uvSet, data);
}

void PerformTexcoordCoordinateConversion(BrushDescriptor desc, Mesh mesh, int uvSet) {
var semantic = GetUvsetSemantic(desc, uvSet);
if (semantic == BrushDescriptor.Semantic.Vector ||
Expand Down

0 comments on commit 5bf7d01

Please sign in to comment.