splat added to working dir
This commit is contained in:
16
jp.keijiro.splat-vfx/Editor/SplatDataInspector.cs
Normal file
16
jp.keijiro.splat-vfx/Editor/SplatDataInspector.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace SplatVfx.Editor {
|
||||
|
||||
[CustomEditor(typeof(SplatData))]
|
||||
public sealed class SplatDataInspector : UnityEditor.Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var count = ((SplatData)target).SplatCount;
|
||||
EditorGUILayout.LabelField("Splat Count", $"{count:N0}");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace SplatVfx.Editor
|
||||
11
jp.keijiro.splat-vfx/Editor/SplatDataInspector.cs.meta
generated
Normal file
11
jp.keijiro.splat-vfx/Editor/SplatDataInspector.cs.meta
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90300afbf61b2ac46906aa1e19eedddc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
122
jp.keijiro.splat-vfx/Editor/SplatImporter.cs
Normal file
122
jp.keijiro.splat-vfx/Editor/SplatImporter.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using Unity.Burst;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.VFX;
|
||||
using UnityEngine.VFX.Utility;
|
||||
using UnityEditor;
|
||||
using UnityEditor.AssetImporters;
|
||||
using UnityEditor.Experimental;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SplatVfx.Editor {
|
||||
|
||||
[ScriptedImporter(1, "splat"), BurstCompile]
|
||||
public sealed class SplatImporter : ScriptedImporter
|
||||
{
|
||||
#region ScriptedImporter implementation
|
||||
|
||||
public override void OnImportAsset(AssetImportContext context)
|
||||
{
|
||||
var data = ImportAsSplatData(context.assetPath);
|
||||
var prefab = CreatePrefab(data);
|
||||
context.AddObjectToAsset("prefab", prefab);
|
||||
context.AddObjectToAsset("data", data);
|
||||
context.SetMainObject(prefab);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Prefab construction
|
||||
|
||||
const string DefaultVfxPath = "Packages/jp.keijiro.splat-vfx/VFX/Splat.vfx";
|
||||
|
||||
GameObject CreatePrefab(SplatData data)
|
||||
{
|
||||
var go = new GameObject();
|
||||
|
||||
var vfx = go.AddComponent<VisualEffect>();
|
||||
vfx.visualEffectAsset = EditorResources.Load<VisualEffectAsset>(DefaultVfxPath);
|
||||
|
||||
var binderBase = go.AddComponent<VFXPropertyBinder>();
|
||||
var binder = binderBase.AddPropertyBinder<VFXSplatDataBinder>();
|
||||
binder.SplatData = data;
|
||||
|
||||
return go;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Reader implementation
|
||||
|
||||
SplatData ImportAsSplatData(string path)
|
||||
{
|
||||
var data = ScriptableObject.CreateInstance<SplatData>();
|
||||
data.name = Path.GetFileNameWithoutExtension(path);
|
||||
|
||||
var arrays = LoadDataArrays(path);
|
||||
data.PositionArray = arrays.position;
|
||||
data.AxisArray = arrays.axis;
|
||||
data.ColorArray = arrays.color;
|
||||
data.ReleaseGpuResources();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
#pragma warning disable CS0649
|
||||
|
||||
struct ReadData
|
||||
{
|
||||
public float px, py, pz;
|
||||
public float sx, sy, sz;
|
||||
public byte r, g, b, a;
|
||||
public byte rw, rx, ry, rz;
|
||||
}
|
||||
|
||||
#pragma warning restore CS0649
|
||||
|
||||
(Vector3[] position, Vector3[] axis, Color[] color)
|
||||
LoadDataArrays(string path)
|
||||
{
|
||||
var bytes = (Span<byte>)File.ReadAllBytes(path);
|
||||
var count = bytes.Length / 32;
|
||||
|
||||
var source = MemoryMarshal.Cast<byte, ReadData>(bytes);
|
||||
|
||||
var position = new Vector3[count];
|
||||
var axis = new Vector3[count * 3];
|
||||
var color = new Color[count];
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
ParseReadData(source[i],
|
||||
out position[i],
|
||||
out axis[i * 3],
|
||||
out axis[i * 3 + 1],
|
||||
out axis[i * 3 + 2],
|
||||
out color[i]);
|
||||
|
||||
return (position, axis, color);
|
||||
}
|
||||
|
||||
[BurstCompile]
|
||||
void ParseReadData(in ReadData src,
|
||||
out Vector3 position,
|
||||
out Vector3 axis1,
|
||||
out Vector3 axis2,
|
||||
out Vector3 axis3,
|
||||
out Color color)
|
||||
{
|
||||
var rv = (math.float4(src.rx, src.ry, src.rz, src.rw) - 128) / 128;
|
||||
var q = math.quaternion(-rv.x, -rv.y, rv.z, rv.w);
|
||||
position = math.float3(src.px, src.py, -src.pz);
|
||||
axis1 = math.mul(q, math.float3(src.sx, 0, 0));
|
||||
axis2 = math.mul(q, math.float3(0, src.sy, 0));
|
||||
axis3 = math.mul(q, math.float3(0, 0, src.sz));
|
||||
color = (Vector4)math.float4(src.r, src.g, src.b, src.a) / 255;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
} // namespace SplatVfx.Editor
|
||||
11
jp.keijiro.splat-vfx/Editor/SplatImporter.cs.meta
generated
Normal file
11
jp.keijiro.splat-vfx/Editor/SplatImporter.cs.meta
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a7f5d2fd17129a42904e57ffbcf8a67
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
jp.keijiro.splat-vfx/Editor/SplatVfx.Editor.asmdef
Normal file
21
jp.keijiro.splat-vfx/Editor/SplatVfx.Editor.asmdef
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "SplatVfx.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:57d6a1ae39d606347b1307f1eadefe70",
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b",
|
||||
"GUID:2665a8d13d1b3f18800f46e256720795",
|
||||
"GUID:d04eb9c554ad44ceab303cecf0c0cf82"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
jp.keijiro.splat-vfx/Editor/SplatVfx.Editor.asmdef.meta
generated
Normal file
7
jp.keijiro.splat-vfx/Editor/SplatVfx.Editor.asmdef.meta
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9e984872a36ed840845202c3d099efc
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user