Add animation stub and effect stub for skin.
This commit is contained in:
5
Assets/Cryville/Crtr/Components/SkinAnimation.cs
Normal file
5
Assets/Cryville/Crtr/Components/SkinAnimation.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
namespace Cryville.Crtr.Components {
|
||||||
|
public class SkinAnimation : SkinComponent {
|
||||||
|
protected override void OnDestroy() { }
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Cryville/Crtr/Components/SkinAnimation.cs.meta
Normal file
11
Assets/Cryville/Crtr/Components/SkinAnimation.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 80318e36af5412345871bdbf80d49ef2
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -18,6 +18,7 @@ namespace Cryville.Crtr {
|
|||||||
|
|
||||||
public static void LoadDefault() {
|
public static void LoadDefault() {
|
||||||
if (loaded) return;
|
if (loaded) return;
|
||||||
|
Components.Add("anim", typeof(SkinAnimation));
|
||||||
Components.Add("image", typeof(SpritePlane));
|
Components.Add("image", typeof(SpritePlane));
|
||||||
Components.Add("mesh", typeof(MeshBase));
|
Components.Add("mesh", typeof(MeshBase));
|
||||||
Components.Add("polysec", typeof(PolygonSGO));
|
Components.Add("polysec", typeof(PolygonSGO));
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ namespace Cryville.Crtr {
|
|||||||
buf[0] = _cb() ? (byte)1 : (byte)0;
|
buf[0] = _cb() ? (byte)1 : (byte)0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static readonly PropSrc Error = new Arbitrary(PdtInternalType.Error, new byte[0]);
|
||||||
public class Float : FixedBuffer {
|
public class Float : FixedBuffer {
|
||||||
readonly Func<float> _cb;
|
readonly Func<float> _cb;
|
||||||
public Float(Func<float> cb) : base(PdtInternalType.Number, 4) { _cb = cb; }
|
public Float(Func<float> cb) : base(PdtInternalType.Number, 4) { _cb = cb; }
|
||||||
|
|||||||
@@ -32,8 +32,28 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Binder(typeof(PdtBinder))]
|
[Binder(typeof(PdtBinder))]
|
||||||
public class PdtSkin : SkinElement {
|
public class PdtSkin {
|
||||||
public Dictionary<Identifier, EffectDefinition> effects = new Dictionary<Identifier, EffectDefinition>();
|
public Dictionary<Identifier, AnimationSpan> animations
|
||||||
|
= new Dictionary<Identifier, AnimationSpan>();
|
||||||
|
public Dictionary<Identifier, EffectDefinition> effects
|
||||||
|
= new Dictionary<Identifier, EffectDefinition>();
|
||||||
|
public SkinElement elements;
|
||||||
|
|
||||||
|
public void Optimize(PdtEvaluator etor) {
|
||||||
|
foreach (var animation in animations.Values) {
|
||||||
|
animation.Optimize(etor);
|
||||||
|
}
|
||||||
|
foreach (var effect in effects.Values) {
|
||||||
|
etor.ContextCascadeInsert();
|
||||||
|
if (effect.args != null) foreach (var i in effect.args) {
|
||||||
|
etor.ContextCascadeUpdate(i.Key, PropSrc.Error);
|
||||||
|
}
|
||||||
|
etor.Optimize(effect.duration);
|
||||||
|
effect.elements.Optimize(etor);
|
||||||
|
etor.ContextCascadeDiscard();
|
||||||
|
}
|
||||||
|
elements.Optimize(etor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SkinElement {
|
public class SkinElement {
|
||||||
@@ -69,9 +89,25 @@ namespace Cryville.Crtr {
|
|||||||
public class EffectDefinition {
|
public class EffectDefinition {
|
||||||
public Identifier[] args;
|
public Identifier[] args;
|
||||||
public PdtExpression duration;
|
public PdtExpression duration;
|
||||||
|
public SkinElement elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AnimationSpan {
|
||||||
[ElementList]
|
[ElementList]
|
||||||
public Dictionary<SkinSelectors, SkinElement> elements
|
public Dictionary<Clip, AnimationSpan> spans
|
||||||
= new Dictionary<SkinSelectors, SkinElement>();
|
= new Dictionary<Clip, AnimationSpan>();
|
||||||
|
|
||||||
|
[PropertyList]
|
||||||
|
public Dictionary<SkinPropertyKey, PdtExpression> properties
|
||||||
|
= new Dictionary<SkinPropertyKey, PdtExpression>();
|
||||||
|
|
||||||
|
public void Optimize(PdtEvaluator etor) {
|
||||||
|
foreach (var p in properties.Values) {
|
||||||
|
etor.Optimize(p);
|
||||||
|
}
|
||||||
|
foreach (var e in spans.Values) {
|
||||||
|
e.Optimize(etor);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,14 @@ namespace Cryville.Crtr {
|
|||||||
readonly HashSet<string> a = new HashSet<string>();
|
readonly HashSet<string> a = new HashSet<string>();
|
||||||
readonly List<string> k = new List<string>(2);
|
readonly List<string> k = new List<string>(2);
|
||||||
protected override object InterpretKey(Type type) {
|
protected override object InterpretKey(Type type) {
|
||||||
if (!typeof(SkinElement).IsAssignableFrom(type)) {
|
if (typeof(SkinElement).IsAssignableFrom(type))
|
||||||
|
return InterpretSkinElementKey();
|
||||||
|
else if (typeof(AnimationSpan).IsAssignableFrom(type))
|
||||||
|
return InterpretAnimationSpanKey();
|
||||||
|
else
|
||||||
return base.InterpretKey(type);
|
return base.InterpretKey(type);
|
||||||
}
|
}
|
||||||
|
object InterpretSkinElementKey() {
|
||||||
s.Clear(); a.Clear(); k.Clear();
|
s.Clear(); a.Clear(); k.Clear();
|
||||||
bool invalidKeyFlag = false, compKeyFlag = false;
|
bool invalidKeyFlag = false, compKeyFlag = false;
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -103,6 +108,59 @@ namespace Cryville.Crtr {
|
|||||||
if (Position == pp) throw new FormatException("Invalid selector or key format");
|
if (Position == pp) throw new FormatException("Invalid selector or key format");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
object InterpretAnimationSpanKey() {
|
||||||
|
if ((ct & 0x0040) != 0 || cc == ',') {
|
||||||
|
float start = 0, end = 1;
|
||||||
|
if (cc != ',') {
|
||||||
|
start = float.Parse(GetNumber());
|
||||||
|
ws(); if (cc != ',') throw new FormatException("Invalid span format");
|
||||||
|
}
|
||||||
|
GetChar(); ws();
|
||||||
|
if (cc != '{') end = float.Parse(GetNumber());
|
||||||
|
ws();
|
||||||
|
if (cc != '{') throw new FormatException("Invalid span format");
|
||||||
|
return new Clip(start, end);
|
||||||
|
}
|
||||||
|
k.Clear();
|
||||||
|
while (true) {
|
||||||
|
int pp = Position;
|
||||||
|
switch (cc) {
|
||||||
|
case '.':
|
||||||
|
GetChar();
|
||||||
|
if (k.Count != 1)
|
||||||
|
throw new FormatException("Invalid key format");
|
||||||
|
k.Add(GetIdentifier());
|
||||||
|
break;
|
||||||
|
case ';':
|
||||||
|
case ':':
|
||||||
|
switch (k.Count) {
|
||||||
|
case 1:
|
||||||
|
return new SkinPropertyKey.SetProperty {
|
||||||
|
Component = typeof(TransformInterface),
|
||||||
|
Name = IdentifierManager.SharedInstance.Request(k[0])
|
||||||
|
};
|
||||||
|
case 2:
|
||||||
|
return new SkinPropertyKey.SetProperty {
|
||||||
|
Component = GetComponentByName(k[0]),
|
||||||
|
Name = IdentifierManager.SharedInstance.Request(k[1])
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
throw new FormatException("Unknown error"); // Unreachable
|
||||||
|
}
|
||||||
|
case '{':
|
||||||
|
throw new FormatException("Invalid token");
|
||||||
|
case '}':
|
||||||
|
throw new FormatException("Invalid token");
|
||||||
|
default:
|
||||||
|
if (k.Count != 0)
|
||||||
|
throw new FormatException("Invalid key format");
|
||||||
|
k.Add(GetIdentifier());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ws();
|
||||||
|
if (Position == pp) throw new FormatException("Invalid selector or key format");
|
||||||
|
}
|
||||||
|
}
|
||||||
static Type GetComponentByName(string name) {
|
static Type GetComponentByName(string name) {
|
||||||
Type result;
|
Type result;
|
||||||
if (GenericResources.Components.TryGetValue(name, out result)) return result;
|
if (GenericResources.Components.TryGetValue(name, out result)) return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user