Inheritance: IDisposable
Example #1
0
 public aiBone(aiBone other) : this(AssimpPINVOKE.new_aiBone__SWIG_1(aiBone.getCPtr(other)), true)
 {
     if (AssimpPINVOKE.SWIGPendingException.Pending)
     {
         throw AssimpPINVOKE.SWIGPendingException.Retrieve();
     }
 }
        private BoneContent createSkel(aiNode root)
        {
            BoneContent BoneContent = null;

            if (ainodetocontent.ContainsKey(root.mName.Data))
            {
                aiBone b = bones.Find((a) => a.mName.Data == root.mName.Data);
                if (b != null)
                {
                    BoneContent           = new BoneContent();
                    BoneContent.Name      = b.mName.Data;
                    BoneContent.Transform = tomatrix(b.mOffsetMatrix);

                    foreach (var item in root.mChildren)
                    {
                        BoneContent bon = createSkel(item);
                        if (bon != null)
                        {
                            BoneContent.Children.Add(bon);
                        }
                    }
                    return(BoneContent);
                }
            }
            return(null);
        }
Example #3
0
        public aiBone op_set(aiBone other)
        {
            aiBone ret = new aiBone(assimp_swigPINVOKE.aiBone_op_set(swigCPtr, aiBone.getCPtr(other)), false);

            if (assimp_swigPINVOKE.SWIGPendingException.Pending)
            {
                throw assimp_swigPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Example #4
0
        public bool op_equal(aiBone rhs)
        {
            bool ret = assimp_swigPINVOKE.aiBone_op_equal(swigCPtr, aiBone.getCPtr(rhs));

            if (assimp_swigPINVOKE.SWIGPendingException.Pending)
            {
                throw assimp_swigPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
        private NodeContent extractNo(aiNode node)
        {
            NodeContent nodeContent = new NodeContent();

            nodeContent.Name      = node.mName.Data;
            nodeContent.Transform = tomatrix(node.mTransformation);
            ainodetocontent.Add(node.mName.Data, nodeContent);

            wbone.Clear();
            for (int i = 0; i < node.mNumMeshes; i++)
            {
                for (int j = 0; j < scene.mMeshes[(int)node.mMeshes[i]].mNumBones; j++)
                {
                    aiBone b = scene.mMeshes[(int)node.mMeshes[i]].mBones[j];
                    for (int w = 0; w < b.mNumWeights; w++)
                    {
                        aiVertexWeight vw = b.GetmWeights()[w];
                        if (!wbone.ContainsKey((int)vw.mVertexId))
                        {
                            wbone[(int)vw.mVertexId] = new List <KeyValuePair <string, float> >();
                        }
                        wbone[(int)vw.mVertexId].Add(new KeyValuePair <string, float>(b.mName.Data, vw.mWeight));
                    }
                    bones.Add(b);
                }

                log("model " + node.mMeshes[i].ToString());
                MeshContent MeshContent = ExtractMesh(scene.mMeshes[(int)node.mMeshes[i]]);
                MeshHelper.SwapWindingOrder(MeshContent);
                MeshHelper.OptimizeForCache(MeshContent);
                nodeContent.Children.Add(MeshContent);
            }

            foreach (var item in node.mChildren)
            {
                nodeContent.Children.Add(extractNo(item));
            }
            return(nodeContent);
        }
Example #6
0
 internal static HandleRef getCPtr(aiBone obj)
 {
     return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr);
 }
Example #7
0
 public aiBone(aiBone other) : this(AssimpPINVOKE.new_aiBone__SWIG_1(aiBone.getCPtr(other)), true) {
   if (AssimpPINVOKE.SWIGPendingException.Pending) throw AssimpPINVOKE.SWIGPendingException.Retrieve();
 }
Example #8
0
 internal static HandleRef getCPtr(aiBone obj) {
   return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
Example #9
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(aiBone obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
        /// <summary>
        /// The importer's entry point.
        /// Called by the framework when importing a game asset.
        /// </summary>
        /// <param name="filename">Name of a game asset file.</param>
        /// <param name="context">
        /// Contains information for importing a game asset, such as a logger interface.
        /// </param>
        /// <returns>Resulting game asset.</returns>
        public override NodeContent Import(string filename,
                                           ContentImporterContext context)
        {
            // Uncomment the following line to debug:
            //System.Diagnostics.Debugger.Launch();

            importerContext = context;

            // Reset all importer state
            // See field declarations for more information
            rootNode      = new NodeContent();
            meshBuilder   = null;
            this.filename = filename;
            // Model identity is tied to the file it is loaded from
            rootNode.Identity = new ContentIdentity(filename);

            var flags = (ppsteps |
                         aiPostProcessSteps.aiProcess_GenSmoothNormals |    // generate smooth normal vectors if not existing
                         aiPostProcessSteps.aiProcess_SplitLargeMeshes |    // split large, unrenderable meshes into submeshes
                         aiPostProcessSteps.aiProcess_Triangulate |         // triangulate polygons with more than 3 edges
                         aiPostProcessSteps.aiProcess_ConvertToLeftHanded | // convert everything to D3D left handed space
                         aiPostProcessSteps.aiProcess_SortByPType |         // make 'clean' meshes which consist of a single typ of primitives
                         aiPostProcessSteps.aiProcess_FixInfacingNormals |
                         aiPostProcessSteps.aiProcess_FlipWindingOrder |
                         (aiPostProcessSteps)0);

            Importer importer = new Importer();

            scene = importer.ReadFile(filename, flags);
            if (scene != null)
            {
                directory = Path.GetDirectoryName(filename);
            }
            else
            {
                throw new InvalidContentException("Failed to open file: " + filename + ". Either Assimp screwed up or the path is not valid.");
            }


            ///animacoes
            Dictionary <String, AnimationContent> AnimNameToAcontent = new Dictionary <string, AnimationContent>();

            for (int i = 0; i < scene.mNumAnimations; i++)
            {
                AnimationContent AnimationContent = new AnimationContent();
                AnimationContent.Duration = TimeSpan.FromMilliseconds(scene.mAnimations[i].mDuration);
                if (String.IsNullOrEmpty(scene.mAnimations[i].mName.Data))
                {
                    scene.mAnimations[i].mName.Data = "EMPTY";
                }
                AnimationContent.Name = scene.mAnimations[i].mName.Data;

                AnimNameToAcontent.Add(scene.mAnimations[i].mName.Data, AnimationContent);

                for (int j = 0; j < scene.mAnimations[i].mNumChannels; j++)
                {
                    AnimationChannel AnimationChannel;
                    String           boneName = scene.mAnimations[i].mChannels[j].mNodeName.Data;

                    if (AnimationContent.Channels.ContainsKey(boneName))
                    {
                        AnimationChannel = AnimationContent.Channels[boneName];
                    }
                    else
                    {
                        AnimationChannel = new AnimationChannel();
                        AnimationContent.Channels.Add(boneName, AnimationChannel);
                    }

                    Dictionary <double, Vector3>    position = new Dictionary <double, Vector3>();
                    Dictionary <double, Vector3>    scales   = new Dictionary <double, Vector3>();
                    Dictionary <double, Quaternion> rots     = new Dictionary <double, Quaternion>();

                    SortedSet <double> set = new SortedSet <double>();
                    for (int w = 0; w < scene.mAnimations[i].mChannels[j].mNumPositionKeys; w++)
                    {
                        position.Add(scene.mAnimations[i].mChannels[j].mPositionKeys[w].mTime, new Vector3(scene.mAnimations[i].mChannels[j].mPositionKeys[w].mValue.x, scene.mAnimations[i].mChannels[j].mPositionKeys[w].mValue.y, scene.mAnimations[i].mChannels[j].mPositionKeys[w].mValue.z));
                        set.Add(scene.mAnimations[i].mChannels[j].mPositionKeys[w].mTime);
                    }

                    for (int w = 0; w < scene.mAnimations[i].mChannels[j].mNumScalingKeys; w++)
                    {
                        scales.Add(scene.mAnimations[i].mChannels[j].mScalingKeys[w].mTime, new Vector3(scene.mAnimations[i].mChannels[j].mScalingKeys[w].mValue.x, scene.mAnimations[i].mChannels[j].mScalingKeys[w].mValue.y, scene.mAnimations[i].mChannels[j].mScalingKeys[w].mValue.z));
                        set.Add(scene.mAnimations[i].mChannels[j].mScalingKeys[w].mTime);
                    }

                    for (int w = 0; w < scene.mAnimations[i].mChannels[j].mNumRotationKeys; w++)
                    {
                        rots.Add(scene.mAnimations[i].mChannels[j].mRotationKeys[w].mTime, new Quaternion(scene.mAnimations[i].mChannels[j].mRotationKeys[w].mValue.x, scene.mAnimations[i].mChannels[j].mRotationKeys[w].mValue.y, scene.mAnimations[i].mChannels[j].mRotationKeys[w].mValue.z, scene.mAnimations[i].mChannels[j].mRotationKeys[w].mValue.w));
                        set.Add(scene.mAnimations[i].mChannels[j].mRotationKeys[w].mTime);
                    }

                    foreach (var item in set)
                    {
                        Vector3    pos;
                        Vector3    sca;
                        Quaternion rot;

                        if (position.TryGetValue(item, out pos) == false)
                        {
                            pos = Vector3.Zero;
                        }
                        if (rots.TryGetValue(item, out rot) == false)
                        {
                            rot = Quaternion.Identity;
                        }
                        if (scales.TryGetValue(item, out sca) == false)
                        {
                            sca = Vector3.One;
                        }

                        Matrix world = Matrix.CreateScale(sca) * Matrix.CreateFromQuaternion(rot) * Matrix.CreateTranslation(pos);

                        AnimationChannel.Add(new AnimationKeyframe(TimeSpan.FromMilliseconds(item), world));
                    }
                }
            }

            rootNode.Children.Add(extractNo(scene.mRootNode));

            aiNode boneRoot = null;
            aiBone broot    = null;
            int    distance = int.MaxValue;

            ///pega o root manow
            foreach (var item in bones)
            {
                aiNode ainode = scene.mRootNode.FindNode(item.mName);
                aiNode n      = ainode;
                int    d      = 0;
                //find the closest to the root =P
                while (n.mParent != null)
                {
                    d++;
                    n = n.mParent;
                }
                if (d < distance)
                {
                    broot    = item;
                    boneRoot = ainode;
                    distance = d;
                }
            }

            if (broot != null)
            {
                BoneContent BoneContent = new BoneContent();
                BoneContent.Name      = broot.mName.Data;
                BoneContent.Transform = tomatrix(broot.mOffsetMatrix);
                rootNode.Children.Add(BoneContent);

                foreach (var item2 in AnimNameToAcontent)
                {
                    BoneContent.Animations.Add(item2.Key, item2.Value);
                }

                foreach (var item in boneRoot.mChildren)
                {
                    BoneContent.Children.Add(createSkel(boneRoot));
                }

                ClearTree(rootNode);
            }



            return(rootNode);
        }