Looper animation system for asset space *jank design
This commit is contained in:
parent
1d66b7179c
commit
f57b4512af
2 changed files with 78 additions and 65 deletions
|
@ -260,7 +260,7 @@ MonoBehaviour:
|
||||||
type: 3}
|
type: 3}
|
||||||
meshToolEraser: {fileID: -2868880653068191277, guid: dc6240c783ee7974e8811c10e071e0cc,
|
meshToolEraser: {fileID: -2868880653068191277, guid: dc6240c783ee7974e8811c10e071e0cc,
|
||||||
type: 3}
|
type: 3}
|
||||||
scene: 1
|
scene: 0
|
||||||
--- !u!1 &162671503
|
--- !u!1 &162671503
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -14,6 +15,14 @@ public class AssetSpace
|
||||||
public List<string> loadedNames = new List<string>();
|
public List<string> loadedNames = new List<string>();
|
||||||
public Dictionary<string, Asset> assets = new Dictionary<string, Asset>();
|
public Dictionary<string, Asset> assets = new Dictionary<string, Asset>();
|
||||||
|
|
||||||
|
// Animation
|
||||||
|
// Some discrete number of steps (frames)
|
||||||
|
// That are lerped through (one loop)
|
||||||
|
int frames = 24;
|
||||||
|
float loopTimeScale = 6f;
|
||||||
|
|
||||||
|
float loopTime = 0; // 0-1
|
||||||
|
|
||||||
public void Init(PolyVector polyVector)
|
public void Init(PolyVector polyVector)
|
||||||
{
|
{
|
||||||
// Update Mesh Dictionary
|
// Update Mesh Dictionary
|
||||||
|
@ -21,7 +30,7 @@ public class AssetSpace
|
||||||
loadedNames.Clear();
|
loadedNames.Clear();
|
||||||
assets.Clear();
|
assets.Clear();
|
||||||
|
|
||||||
string[] filePaths = Directory.GetFiles(folderPath, "*.pixelgon", SearchOption.TopDirectoryOnly);
|
string[] filePaths = Directory.GetFiles(folderPath, "*.json", SearchOption.TopDirectoryOnly);
|
||||||
for (int i = 0; i < filePaths.Length; i++)
|
for (int i = 0; i < filePaths.Length; i++)
|
||||||
{
|
{
|
||||||
name = Path.GetFileNameWithoutExtension(filePaths[i]);
|
name = Path.GetFileNameWithoutExtension(filePaths[i]);
|
||||||
|
@ -30,8 +39,8 @@ public class AssetSpace
|
||||||
Mesh mesh = new Mesh();
|
Mesh mesh = new Mesh();
|
||||||
mesh = polyVector.ToMesh(pgon.vectors);
|
mesh = polyVector.ToMesh(pgon.vectors);
|
||||||
Asset asset = new Asset();
|
Asset asset = new Asset();
|
||||||
asset.pos = Vector3.zero;
|
asset.pos = Enumerable.Repeat(Vector3.zero, frames).ToArray();
|
||||||
asset.rot = Quaternion.identity;
|
asset.rot = Enumerable.Repeat(Quaternion.identity, frames).ToArray();
|
||||||
asset.mesh = mesh;
|
asset.mesh = mesh;
|
||||||
assets.Add(name, asset);
|
assets.Add(name, asset);
|
||||||
}
|
}
|
||||||
|
@ -40,57 +49,41 @@ public class AssetSpace
|
||||||
}
|
}
|
||||||
|
|
||||||
string held = null;
|
string held = null;
|
||||||
Vector3 grabOffset;
|
|
||||||
// Vector3 oldCursorPos;
|
|
||||||
Quaternion oldOffConRot;
|
Quaternion oldOffConRot;
|
||||||
public void Frame(Input input, Render render)
|
public void Frame(Input input, Render render)
|
||||||
{
|
{
|
||||||
|
// Looper
|
||||||
|
loopTime += Time.deltaTime / loopTimeScale;
|
||||||
|
if (loopTime >= 1) { loopTime = 0; }
|
||||||
|
|
||||||
|
float frameDelta = loopTime * (frames - 1); // 0.1 * 24 = 2.4
|
||||||
|
int currentFrame = Mathf.FloorToInt(frameDelta); // 2.4 -> 2 (for index)
|
||||||
|
frameDelta = frameDelta - currentFrame; // 2.4 - 2 = 0.4 (for lerp delta t)
|
||||||
|
|
||||||
|
|
||||||
Vector3 cursorPos = input.stretchCursor;
|
Vector3 cursorPos = input.stretchCursor;
|
||||||
// instead of a rigid uniform list
|
|
||||||
// make it a space where you can lay things out
|
|
||||||
float closest = 1000f;
|
|
||||||
for (int i = 0; i < loadedNames.Count; i++)
|
|
||||||
{
|
|
||||||
Asset asset = assets[loadedNames[i]];
|
|
||||||
Graphics.DrawMesh(asset.mesh,
|
|
||||||
asset.pos, asset.rot,
|
|
||||||
render.polyVector.matVector, 0
|
|
||||||
);
|
|
||||||
|
|
||||||
if (input.mainCon.trigger.down)
|
|
||||||
{
|
|
||||||
float reachDist = Vector3.Distance(asset.pos, cursorPos);
|
|
||||||
if (reachDist < closest)
|
|
||||||
{
|
|
||||||
held = loadedNames[i];
|
|
||||||
closest = reachDist;
|
|
||||||
grabOffset = asset.pos - cursorPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (input.mainCon.trigger.held)
|
if (input.mainCon.trigger.held)
|
||||||
{
|
{
|
||||||
if (held != null)
|
if (held != null)
|
||||||
{
|
{
|
||||||
if (input.mainCon.one.up)
|
Asset asset = assets[held];
|
||||||
|
|
||||||
|
if (input.mainCon.one.down)
|
||||||
{
|
{
|
||||||
grabOffset = assets[held].pos - cursorPos;
|
// switch to pixelgon scene to edit
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.mainCon.one.held)
|
asset.pos[currentFrame] = cursorPos;
|
||||||
{
|
|
||||||
Quaternion rotDelta = input.offCon.physical.Rot() * Quaternion.Inverse(oldOffConRot);
|
|
||||||
assets[held].rot = rotDelta * assets[held].rot;
|
|
||||||
// assets[held].rot *= Quaternion.LookRotation(cursorPos - assets[held].pos) *
|
|
||||||
// Quaternion.Inverse(Quaternion.LookRotation(oldCursorPos - assets[held].pos));
|
|
||||||
|
|
||||||
}
|
asset.pos[frames - 1] = Vector3.Lerp(asset.pos[0], asset.pos[frames - 2], 0.5f);
|
||||||
else
|
|
||||||
{
|
// Quaternion rotDelta = input.offCon.physical.Rot() * Quaternion.Inverse(oldOffConRot);
|
||||||
assets[held].pos = cursorPos + grabOffset;
|
// assets[held].rot = rotDelta * assets[held].rot;
|
||||||
}
|
|
||||||
|
Graphics.DrawMesh(asset.mesh,
|
||||||
|
cursorPos, asset.rot[currentFrame],
|
||||||
|
render.polyVector.matVector, 0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -98,27 +91,47 @@ public class AssetSpace
|
||||||
held = null;
|
held = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float closest = 1000f;
|
||||||
|
int closestIndex = -1;
|
||||||
|
for (int i = 0; i < loadedNames.Count; i++)
|
||||||
|
{
|
||||||
|
Asset asset = assets[loadedNames[i]];
|
||||||
|
|
||||||
|
Vector3 assetPos = Vector3.Lerp(asset.pos[currentFrame], asset.pos[currentFrame + 1], frameDelta);
|
||||||
|
Quaternion assetRot = Quaternion.Lerp(asset.rot[currentFrame], asset.rot[currentFrame + 1], frameDelta);
|
||||||
|
|
||||||
|
if (loadedNames[i] != held)
|
||||||
|
{
|
||||||
|
Graphics.DrawMesh(asset.mesh,
|
||||||
|
assetPos, assetRot,
|
||||||
|
render.polyVector.matVector, 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
float reachDist = Vector3.Distance(assetPos, cursorPos);
|
||||||
|
if (reachDist < closest)
|
||||||
|
{
|
||||||
|
closest = reachDist;
|
||||||
|
closestIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (closestIndex > -1)
|
||||||
|
{
|
||||||
|
if (input.mainCon.trigger.down)
|
||||||
|
{
|
||||||
|
held = loadedNames[closestIndex];
|
||||||
|
|
||||||
|
Asset asset = assets[held];
|
||||||
|
for (int i = 0; i < asset.pos.Length; i++)
|
||||||
|
{
|
||||||
|
asset.pos[i] = cursorPos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
oldOffConRot = input.offCon.physical.Rot();
|
oldOffConRot = input.offCon.physical.Rot();
|
||||||
// oldCursorPos = cursorPos;
|
|
||||||
|
|
||||||
// where to store persistent position and rotation?
|
|
||||||
// needs to be saved in the .pixelgon file then
|
|
||||||
// can assetspace have its own save file instead?
|
|
||||||
// store the name pos and rotation ++animationPath
|
|
||||||
// Later you can have multiple persistent spaces
|
|
||||||
|
|
||||||
|
|
||||||
// stream lining features *just manually do it in the unity inspector for now
|
|
||||||
// and switch to editing a certain object
|
|
||||||
// buttons in the oriel?
|
|
||||||
|
|
||||||
// set name
|
|
||||||
// asset names (no renaming just save new or over, manually delete the deprecated)
|
|
||||||
// save
|
|
||||||
// load
|
|
||||||
|
|
||||||
// recordable motion paths
|
|
||||||
// control over time
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save(Pixelgon pixelgon)
|
public void Save(Pixelgon pixelgon)
|
||||||
|
@ -184,6 +197,6 @@ public class AssetSpace
|
||||||
public class Asset
|
public class Asset
|
||||||
{
|
{
|
||||||
public Mesh mesh;
|
public Mesh mesh;
|
||||||
public Vector3 pos;
|
public Vector3[] pos;
|
||||||
public Quaternion rot;
|
public Quaternion[] rot;
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue