public Hierarchy(QAnimation _animation) { animation = _animation; int numJoints = animation.jointNames.Count; QJoint walker = animation.hierarchy; int hLen = GetHierarchySize(walker); entries = new List <int>(hLen); Queue <QJoint> remaining = new Queue <QJoint>(); remaining.Enqueue(walker); List <List <int> > pieces = new List <List <int> >(numJoints); for (int i = 0; i < numJoints; i++) { pieces.Add(new List <int>()); } while (remaining.Count > 0) { QJoint joint = remaining.Dequeue(); pieces[joint.index].Add(joint.children.Count); foreach (QJoint child in joint.children) { pieces[joint.index].Add(child.index); remaining.Enqueue(child); } } for (int i = 0; i < numJoints; i++) { List <int> piece = pieces[i]; entries.AddRange(piece); } }
public void OnStart(QGetContent content) { StateOfThePlayer = PlayerState.Moving; //Instantiate(SwordCollision = new SwordAttackCollider()); Health = HealthMax; Instantiate(new PlayerHealth()); //Spawner = GetComponent<PlayerSpawner>("PlayerSpawner"); AttackFrames = Scene.MegaTexture["SwordAttack2"].Split(32, 32); Frames = Scene.MegaTexture["BryanSpriteSheet"].Split(32, 32); HearthSource = Scene.MegaTexture["BryanStuff1"].Split(32, 32)[21]; EmptyHealthSource = Scene.MegaTexture["BryanStuff1"].Split(32, 32)[22]; Sprite = new QSprite(this, Frames[0]); Sprite.Layer = 5f; Transform.Scale = new QVec(4); const float attackTime = 0.1f; Left = new QAnimation(Frames, 0.1f, 12, 16); Right = new QAnimation(Frames, 0.1f, 4, 8); AttackRight = new QAnimation(AttackFrames, attackTime, 1, 5) { Loop = false }; AttackLeft = new QAnimation(AttackFrames, attackTime, 7, 11) { Loop = false }; Current = Right; // Rigibody = QBody.Capsule( // 27 * Sprite.Scale.Y, // (15 * Sprite.Scale.X) / 2f, 20, // (15 * Sprite.Scale.X) / 2f, 20, 1f, // Position, this); Rigibody = World.CreateCapsule(this, 27 * Transform.Scale.Y, (15 * Transform.Scale.X) / 2f, 20, Transform.Position, 0, QBodyType.Dynamic); Rigibody.IsIgnoreCcd = true; Rigibody.FixedRotation = true; Rigibody.Friction = 1f; //Rigibody.OnCollision += OnCollision; World.Gravity = new QVec(0, 20f); Camera.Position = Transform.Position; // = Spawner.Transform.Position; MoveLeft = true; MoveRight = true; TimeInAir = 0; }
public void OnStart(QGetContent content) { var frame = Scene.MegaTexture["slime"].Split(32, 32); SlimeIdle = new QAnimation(frame, 0.5f, 0, 1); Sprite.Origin = new QVec(16); body = World.CreateRectangle(this, 32 * 4, 32 * 4, 1f, Transform.Position, 0); body.AllowSleep = false; }
void Start() { BagelLoader bagel = new BagelLoader(model); animation = bagel.LoadBagel(path); inverseBindXforms = model.bindposes; flockComputer = Resources.Load <ComputeShader>("FlockingComputer6"); jointComputer = Resources.Load <ComputeShader>("SkinningComputer1"); hiero = new Hierarchy(animation); InitializeBuffers(); }
void Start() { path = Application.dataPath + @"\Scripts\Swim_Default.bagel"; BagelLoader bagel = new BagelLoader(model); animation = bagel.LoadBagel(path); inverseBindXforms = model.bindposes; flockComputer = Resources.Load <ComputeShader>("FlockingComputer7"); jointComputer = Resources.Load <ComputeShader>("SkinningComputer1"); hiero = new Hierarchy(animation); InitializeBuffers(); }
void Awake() { computer = (ComputeShader)Resources.Load("FlockingComputer5"); skinner = (ComputeShader)Resources.Load("SkinningInstanceComputer0"); BagelLoader bagel = new BagelLoader(agentMesh); animation = bagel.LoadBagel(path); bindTransforms = agentMesh.bindposes; numJoints = bindTransforms.Length; MakeHierarchy(); MakeKeyFramesAndJointData(); InitializeBuffers(); }
// Use this for initialization void Start() { jointComputer = Resources.Load <ComputeShader>("SkinningComputer0"); modelMat = GetComponent <Renderer>().material; BagelLoader bagel = new BagelLoader(model); animation = bagel.LoadBagel(path); bindTransforms = model.bindposes; numJoints = bindTransforms.Length; MakeHierarchy(); MakeKeyFramesAndJointData(); InitializeBuffers(); }
// Use this for initialization void Start() { jointComputer = Resources.Load <ComputeShader>("SkinningComputer0"); instanceXBuf = new ComputeBuffer(inXforms.Length, sizeof(float) * 16); BagelLoader bagel = new BagelLoader(model); animation = bagel.LoadBagel(path); bindTransforms = model.bindposes; numJoints = bindTransforms.Length; MakeHierarchy(); MakeKeyFramesAndJointData(); InitializeBuffers(); }
public override void OnStart(QGetContent content) { Health = MaxHealth; Frames = Scene.MegaTexture["BryanStuff1"].Split(32, 32); bs = GetComponent <BatSpawner>(spawnerId); p = GetComponent <Player>("Player"); Sprite = new QSprite(this, Frames[28]); Transform.Scale = new QVec(4); Sprite.Origin = new QVec(16); BatFlap = new QAnimation(Frames, 0.1f, 28, 30); spawnerPosition = Transform.Position = bs.Transform.Position; body = World.CreateRectangle(this, 13 * Transform.Scale.X, 13 * Transform.Scale.Y, 1f, Transform.Position, 0); body.IgnoreGravity = true; body.FixedRotation = true; body.LinearDamping = 10f; }
public override void OnStart(QGetContent get) { spawnerPosition = Transform.Position; Health = MaxHealth; Frames = Scene.Atlas["BryanStuff1"].Split(32, 32); player = GetBehavior <Player>("Player"); Sprite = new QSprite(this, Frames[28]); Sprite.Scale = new QVec(4); Sprite.Effect = QRenderEffects.FlipVertically; Sprite.Source = Frames[30]; BatFlap = new QAnimation(Frames, 0.1f, 28, 30); body = Physics.CreateRectangle(this, Sprite.Width / 3f, Sprite.Height / 3f, 5); body.IgnoreGravity = true; body.FixedRotation = true; body.LinearDamping = 10f; }
// Use this for initialization void Start() { mat = GetComponent <Renderer>().material; BagelLoader bagelLoader = new BagelLoader(model); animation = bagelLoader.LoadBagel(path); tDat = new TransformData[animation.jointNames.Count]; bonePlaceholders = new GameObject[tDat.Length]; QJoint hierarchy = animation.hierarchy; bonePlaceholders[0] = GameObject.CreatePrimitive(PrimitiveType.Cube); GenerateChildren(hierarchy); boneXForms = new Matrix4x4[animation.jointNames.Count]; debugs = new Matrix4x4[boneXForms.Length]; xFormBuf = new ComputeBuffer(boneXForms.Length, sizeof(float) * 16); var wghts = model.boneWeights; boneIdxBuf = new ComputeBuffer(wghts.Length, sizeof(float) * 4); boneWeightBuf = new ComputeBuffer(wghts.Length, sizeof(float) * 4); Vector4[] boneIndices = new Vector4[wghts.Length]; Vector4[] boneWeights = new Vector4[wghts.Length]; for (int i = 0; i < wghts.Length; i++) { BoneWeight w = wghts[i]; boneIndices[i] = new Vector4(w.boneIndex0, w.boneIndex1, w.boneIndex2, w.boneIndex3); boneWeights[i] = new Vector4(w.weight0, w.weight1, w.weight2, w.weight3); } boneIdxBuf.SetData(boneIndices); boneWeightBuf.SetData(boneWeights); mat.SetBuffer("boneIndices", boneIdxBuf); mat.SetBuffer("weights", boneWeightBuf); }
public void OnGUI() { clip = EditorGUILayout.ObjectField("Clip", clip, typeof(AnimationClip), false) as AnimationClip; mesh = EditorGUILayout.ObjectField("Model", mesh, typeof(Mesh), false) as Mesh; if (GUILayout.Button("Encode Animation Curves")) { if (clip != null) { Dictionary <string, List <string> > hierarchedBindings = new Dictionary <string, List <string> >(); List <string> encodings = new List <string>(); foreach (var binding in AnimationUtility.GetCurveBindings(clip)) { if (!hierarchedBindings.ContainsKey(binding.path)) { List <string> bindFrames = new List <string>(); hierarchedBindings.Add(binding.path, bindFrames); } AnimationCurve curve = AnimationUtility.GetEditorCurve(clip, binding); string thisJointField = string.Format("#_#{0}##{1}", binding.propertyName, curve.keys.Length); hierarchedBindings[binding.path].Add(thisJointField); foreach (Keyframe key in curve.keys) { string thisKeyFrame = string.Format("{0}*#*{1}*#*{2}*#*{3}", key.inTangent, key.value, key.outTangent, key.time); hierarchedBindings[binding.path].Add(thisKeyFrame); } } encodings.Add(clip.length.ToString()); var bindingEnum = hierarchedBindings.Keys.GetEnumerator(); while (bindingEnum.MoveNext()) { if (encodings.Count > 1) { encodings.Add(string.Format("&$*{0}", bindingEnum.Current)); } else { encodings.Add(bindingEnum.Current); } var keyframes = hierarchedBindings[bindingEnum.Current]; foreach (string frame in keyframes) { encodings.Add(frame); } } string path = Application.dataPath + @"\Scripts\" + clip.name + ".bagel"; System.IO.File.WriteAllLines(path, encodings.ToArray()); BagelLoader bagel = new BagelLoader(mesh); QAnimation myAnim = bagel.LoadBagel(path); for (int i = 0; i < 5; i++) { TransformData sample = myAnim.GetTransformAt(0, myAnim.length / 5 * i); Debug.Log(string.Format("Position: {0} \nRotation: {1} \nScale: {2}", sample.position.ToString(), sample.rotation.ToString(), sample.scale.ToString())); } var th = myAnim.GetType().TypeHandle; /*unsafe * { * long size = *(*(long**)&th + 1); * Debug.Log(size); * }*/ } } }