Skip to content

Commit

Permalink
AlembicPointsRenderer: handling TRS
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed Apr 26, 2017
1 parent 00dc674 commit c3fabcd
Showing 1 changed file with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Material[] SetupMaterials()
{
m_materialsInternal = null;
}
else if (m_materialsInternal == null)
else if (m_materialsInternal == null || m_materialsInternal.Length == 0)
{
m_materialsInternal = new Material[m_materials.Length];
for (int i = 0; i < m_materials.Length; ++i)
Expand All @@ -135,9 +135,18 @@ public void Flush()
int num_submeshes = System.Math.Min(mesh.subMeshCount, materials.Length);
int layer = gameObject.layer;

var trans = GetComponent<Transform>();
var pos = trans.position;
var rot = trans.rotation;
var scale = trans.lossyScale;
var pscale = scale * m_pointSize;

bool supportsInstancing = SystemInfo.supportsInstancing;
#if UNITY_5_6_OR_NEWER
int pidPointSize = Shader.PropertyToID("_PointSize");
int pidTranslate = Shader.PropertyToID("_Translate");
int pidRotate = Shader.PropertyToID("_Rotate");
int pidScale = Shader.PropertyToID("_Scale");
int pidAlembicPoints = Shader.PropertyToID("_AlembicPoints");
#endif
#if UNITY_5_5_OR_NEWER
Expand Down Expand Up @@ -292,10 +301,12 @@ public void Flush()
// build matrices
for (int ii = 0; ii < n; ++ii)
{
m_matrices[ii].m00 = m_matrices[ii].m11 = m_matrices[ii].m22 = m_pointSize;
m_matrices[ii].m03 = points[ibegin + ii].x;
m_matrices[ii].m13 = points[ibegin + ii].y;
m_matrices[ii].m23 = points[ibegin + ii].z;
var ppos = points[ibegin + ii];
ppos.x *= scale.x;
ppos.y *= scale.y;
ppos.z *= scale.z;
ppos = (rot * ppos) + pos;
m_matrices[ii].SetTRS(ppos, rot, pscale);
}

MaterialPropertyBlock mpb = null;
Expand Down Expand Up @@ -324,12 +335,14 @@ public void Flush()
// not use IDs in this case because it's too expensive...

var matrix = Matrix4x4.identity;
matrix.m00 = matrix.m11 = matrix.m22 = m_pointSize;
for (int ii = 0; ii < num_instances; ++ii)
{
matrix.m03 = points[ii].x;
matrix.m13 = points[ii].y;
matrix.m23 = points[ii].z;
var ppos = points[ii];
ppos.x *= scale.x;
ppos.y *= scale.y;
ppos.z *= scale.z;
ppos = (rot * ppos) + pos;
matrix.SetTRS(ppos, rot, pscale);

// issue drawcalls
for (int si = 0; si < num_submeshes; ++si)
Expand Down

0 comments on commit c3fabcd

Please sign in to comment.