Exemple #1
0
    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();
    }
Exemple #3
0
    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();
    }
    // 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);
                 * }*/
            }
        }
    }