Skip to content

Commit

Permalink
add "Apply Transform" option for AlembicPointsRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed Feb 5, 2018
1 parent 7fc71fb commit ee00f79
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 29 deletions.
Expand Up @@ -40,35 +40,42 @@ public static AssetMoveResult OnWillMoveAsset(string from, string to)
{
if (Path.GetExtension(from.ToLower()) != ".abc")
return AssetMoveResult.DidNotMove;
var streamDestPath = AlembicImporter.MakeShortAssetPath(to);
var streamSourcePath = AlembicImporter.MakeShortAssetPath(from);
AlembicStream.DisconnectStreamsWithPath(streamSourcePath);
AlembicStream.RemapStreamsWithPath(streamSourcePath,streamDestPath);
var streamDstPath = AlembicImporter.MakeShortAssetPath(to);
var streamSrcPath = AlembicImporter.MakeShortAssetPath(from);
AlembicStream.DisconnectStreamsWithPath(streamSrcPath);
AlembicStream.RemapStreamsWithPath(streamSrcPath,streamDstPath);

var destPath = Application.streamingAssetsPath + streamDestPath;
var sourcePath = Application.streamingAssetsPath + streamSourcePath;
var dstPath = Application.streamingAssetsPath + streamDstPath;
var srcPath = Application.streamingAssetsPath + streamSrcPath;

var directoryPath = Path.GetDirectoryName(destPath);
if (File.Exists(destPath))
{
File.SetAttributes(destPath + ".meta", FileAttributes.Normal);
File.Delete(destPath);
}
else if (!Directory.Exists(directoryPath))
try
{
Directory.CreateDirectory(directoryPath);
var directoryPath = Path.GetDirectoryName(dstPath);
if (File.Exists(dstPath))
{
File.SetAttributes(dstPath + ".meta", FileAttributes.Normal);
File.Delete(dstPath);
}
else if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
if (File.Exists(dstPath))
File.SetAttributes(dstPath, FileAttributes.Normal);
File.Move(srcPath, dstPath);
if (File.Exists(dstPath + ".meta"))
{
File.SetAttributes(dstPath + ".meta", FileAttributes.Normal);
File.Move(srcPath + ".meta", dstPath + ".meta");
}

AssetDatabase.Refresh(ImportAssetOptions.Default);
AlembicStream.ReconnectStreamsWithPath(streamDstPath);
}
if (File.Exists(destPath))
File.SetAttributes(destPath, FileAttributes.Normal);
File.Move(sourcePath, destPath);
if (File.Exists(destPath + ".meta"))
catch (System.Exception e)
{
File.SetAttributes(destPath + ".meta", FileAttributes.Normal);
File.Move(sourcePath + ".meta", destPath+ ".meta");
Debug.LogWarning(e);
}
AssetDatabase.Refresh(ImportAssetOptions.Default);
AlembicStream.ReconnectStreamsWithPath(streamDestPath);

return AssetMoveResult.DidNotMove;
}
}
Expand Down
Expand Up @@ -58,6 +58,7 @@ public class AlembicPointsRenderer : MonoBehaviour
[SerializeField] Material[] m_materials;
[SerializeField] Material m_motionVectorMaterial;
[SerializeField] ShadowCastingMode m_castShadows = ShadowCastingMode.On;
[SerializeField] bool m_applyTransform = false;
[SerializeField] bool m_receiveShadows = true;
[SerializeField] bool m_generateMotionVector = true;
[SerializeField] float m_pointSize = 0.2f;
Expand Down Expand Up @@ -198,12 +199,24 @@ public void Flush()
// update materials
if(m_mpb==null)
m_mpb = new MaterialPropertyBlock();
m_mpb.SetVector("_Position", m_position);
m_mpb.SetVector("_PositionOld", m_positionOld);
m_mpb.SetVector("_Rotation", new Vector4(m_rotation.x, m_rotation.y, m_rotation.z, m_rotation.w));
m_mpb.SetVector("_RotationOld", new Vector4(m_rotationOld.x, m_rotationOld.y, m_rotationOld.z, m_rotationOld.w));
m_mpb.SetVector("_Scale", m_scale);
m_mpb.SetVector("_ScaleOld", m_scaleOld);
if (m_applyTransform)
{
m_mpb.SetVector("_Position", m_position);
m_mpb.SetVector("_PositionOld", m_positionOld);
m_mpb.SetVector("_Rotation", new Vector4(m_rotation.x, m_rotation.y, m_rotation.z, m_rotation.w));
m_mpb.SetVector("_RotationOld", new Vector4(m_rotationOld.x, m_rotationOld.y, m_rotationOld.z, m_rotationOld.w));
m_mpb.SetVector("_Scale", m_scale);
m_mpb.SetVector("_ScaleOld", m_scaleOld);
}
else
{
m_mpb.SetVector("_Position", Vector3.zero);
m_mpb.SetVector("_PositionOld", Vector3.zero);
m_mpb.SetVector("_Rotation", new Vector4(0, 0, 0, 1));
m_mpb.SetVector("_RotationOld", new Vector4(0, 0, 0, 1));
m_mpb.SetVector("_Scale", Vector3.one);
m_mpb.SetVector("_ScaleOld", Vector3.one);
}
m_mpb.SetFloat("_PointSize", m_pointSize);
m_mpb.SetBuffer("_AlembicPoints", m_cbPoints);
if (abcHasIDs)
Expand Down

0 comments on commit ee00f79

Please sign in to comment.