コード例 #1
0
        }         // Model(setModelName)

        #endregion

        #region Load
        public void Load()
        {
            if (xnaModel == null)
            {
                xnaModel = BaseGame.Content.Load <XnaModel>(
                    @"Content\" + name);

                // Go through all meshes in the model
                //obs: foreach (ModelMesh mesh in xnaModel.Meshes)
                //obs: for (int meshNum = 0; meshNum < xnaModel.Meshes.Count; meshNum++)
                //{
                ModelMesh mesh = xnaModel.Meshes[0];
                meshPart = mesh.MeshParts[0];
                string meshName = mesh.Name;
                // Only support one effect
                Effect effect = mesh.Effects[0];

                // And for each effect this mesh uses (usually just 1, multimaterials
                // are nice in 3ds max, but not efficiently for rendering stuff).
                //obs: foreach (Effect effect in mesh.Effects)
                //obs: for (int effectNum = 0; effectNum < mesh.Effects.Count; effectNum++)
                //{
                //Effect effect = mesh.Effects[effectNum];
                // Get technique from meshName
                int techniqueIndex = -1;
                if (meshName.Length > 0)
                {
                    try
                    {
                        //Log.Write("meshName="+meshName);
                        string techniqueNumberString = meshName.Substring(
                            meshName.Length - 1, 1);
#if !XBOX360
                        // Faster and does not throw an exception!
                        int.TryParse(techniqueNumberString, out techniqueIndex);
#else
                        techniqueIndex = Convert.ToInt32(techniqueNumberString);
#endif
                        //Log.Write("techniqueIndex="+techniqueIndex);
                    }             // try
                    catch { }     // ignore if that failed
                }                 // if (meshName.Length)

                // No technique found or invalid?
                if (techniqueIndex < 0 ||
                    techniqueIndex >= effect.Techniques.Count ||
                    // Or if this is an asteroid (use faster diffuse technique!)
                    StringHelper.BeginsWith(name, "asteroid"))
                {
                    // Try to use last technique
                    techniqueIndex = effect.Techniques.Count - 1;
                }                 // if (techniqueIndex)

                // If the technique ends with 20, but we can't do ps20,
                // use the technique before that (which doesn't use ps20)
                if (BaseGame.CanUsePS20 == false &&
                    effect.Techniques[techniqueIndex].Name.EndsWith("20"))
                {
                    techniqueIndex--;
                }

                // Set current technique for rendering below
                effect.CurrentTechnique = effect.Techniques[techniqueIndex];
                //} // foreach (effect)

                // Add all mesh parts!
                //obs: for (int partNum = 0; partNum < mesh.MeshParts.Count; partNum++)
                //{
                //obs: ModelMeshPart part = mesh.MeshParts[partNum];

                // The model mesh part is not really used, we just extract the
                // index and vertex buffers and all the render data.
                // Material settings are build from the effect settings.
                // Also add this to our own dictionary for rendering.
                renderableMesh = BaseGame.MeshRenderManager.Add(
                    mesh.VertexBuffer, mesh.IndexBuffer, meshPart, effect);
                //} // for (partNum)
                //} // foreach (mesh)
            }     // if
        }         // Load()
コード例 #2
0
        public void Load()
        {
            if (xnaModel == null)
            {
                xnaModel = BaseGame.Content.Load<XnaModel>(
                    @"Content\" + name);

                // Go through all meshes in the model
                //obs: foreach (ModelMesh mesh in xnaModel.Meshes)
                //obs: for (int meshNum = 0; meshNum < xnaModel.Meshes.Count; meshNum++)
                //{
                ModelMesh mesh = xnaModel.Meshes[0];
                meshPart = mesh.MeshParts[0];
                string meshName = mesh.Name;
                // Only support one effect
                Effect effect = mesh.Effects[0];

                // And for each effect this mesh uses (usually just 1, multimaterials
                // are nice in 3ds max, but not efficiently for rendering stuff).
                //obs: foreach (Effect effect in mesh.Effects)
                //obs: for (int effectNum = 0; effectNum < mesh.Effects.Count; effectNum++)
                //{
                //Effect effect = mesh.Effects[effectNum];
                // Get technique from meshName
                int techniqueIndex = -1;
                if (meshName.Length > 0)
                {
                    try
                    {
                        //Log.Write("meshName="+meshName);
                        string techniqueNumberString = meshName.Substring(
                            meshName.Length - 1, 1);
            #if !XBOX360
                        // Faster and does not throw an exception!
                        int.TryParse(techniqueNumberString, out techniqueIndex);
            #else
                    techniqueIndex = Convert.ToInt32(techniqueNumberString);
            #endif
                        //Log.Write("techniqueIndex="+techniqueIndex);
                    } // try
                    catch { } // ignore if that failed
                } // if (meshName.Length)

                // No technique found or invalid?
                if (techniqueIndex < 0 ||
                    techniqueIndex >= effect.Techniques.Count ||
                    // Or if this is an asteroid (use faster diffuse technique!)
                    StringHelper.BeginsWith(name, "asteroid"))
                {
                    // Try to use last technique
                    techniqueIndex = effect.Techniques.Count - 1;
                } // if (techniqueIndex)

                // If the technique ends with 20, but we can't do ps20,
                // use the technique before that (which doesn't use ps20)
                if (BaseGame.CanUsePS20 == false &&
                    effect.Techniques[techniqueIndex].Name.EndsWith("20"))
                    techniqueIndex--;

                // Set current technique for rendering below
                effect.CurrentTechnique = effect.Techniques[techniqueIndex];
                //} // foreach (effect)

                // Add all mesh parts!
                //obs: for (int partNum = 0; partNum < mesh.MeshParts.Count; partNum++)
                //{
                //obs: ModelMeshPart part = mesh.MeshParts[partNum];

                // The model mesh part is not really used, we just extract the
                // index and vertex buffers and all the render data.
                // Material settings are build from the effect settings.
                // Also add this to our own dictionary for rendering.
                renderableMesh = BaseGame.MeshRenderManager.Add(
                    mesh.VertexBuffer, mesh.IndexBuffer, meshPart, effect);
                //} // for (partNum)
                //} // foreach (mesh)
            } // if
        }