Example #1
0
        }   // end of PartInfo c'tor

        public PartInfo(PartInfo copy)
        {
            this.overlayTexture = copy.overlayTexture;
            this.diffuseColor   = copy.diffuseColor;
            this.alpha          = copy.alpha;
            this.emissiveColor  = copy.emissiveColor;
            this.specularColor  = copy.specularColor;
            this.specularPower  = copy.specularPower;
            this.diffuseTexture = copy.diffuseTexture;
        }
Example #2
0
 private void RecurseBonesAndCreateRenderObjs(Model model, ModelBone bone)
 {
     foreach (ModelBone childbone in bone.Children)
     {
         ModelMesh mesh = ModelHelper.FindMatchingMeshForBone(model, childbone);
         if (mesh != null)
         {
             List <PartInfo> meshInfoList = new List <PartInfo>();
             foreach (ModelMeshPart part in mesh.MeshParts)
             {
                 PartInfo partInfo = new PartInfo();
                 partInfo.InitFromPart(part);
                 meshInfoList.Add(partInfo);
                 // create a bounding box from the mesh?
             }
             MeshRenderObj renderobj = new MeshRenderObj(mesh, meshInfoList);
             listMeshRenderObj.Add(renderobj);
         }
         RecurseBonesAndCreateRenderObjs(model, childbone);
     }
 }
Example #3
0
        public void Render(Camera camera, Matrix transform, List <PartInfo> listPartsReplacement)
        {
            Effect         effect = Editor.Effect;
            GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

            List <PartInfo> listParts = listPartInfo;

            if (listPartsReplacement != null)
            {
                listParts = listPartsReplacement;
            }
            Matrix viewProjMatrix = camera.ViewMatrix * camera.ProjectionMatrix;

            Matrix worldMatrix = meshTransform * transform;

            Matrix worldViewProjMatrix = worldMatrix * viewProjMatrix;

            effect.Parameters["WorldViewProjMatrix"].SetValue(worldViewProjMatrix);
            effect.Parameters["WorldMatrix"].SetValue(worldMatrix);

            //
            //FillMode tempFillMode = device.RenderState.FillMode;

            //device.RasterizerState = UI2D.Shared.RasterStateWireframe;

            for (int indexMeshPart = 0; indexMeshPart < mesh.MeshParts.Count; indexMeshPart++)
            {
                ModelMeshPart part = (ModelMeshPart)mesh.MeshParts[indexMeshPart];

                device.Indices = part.IndexBuffer;
                device.SetVertexBuffer(part.VertexBuffer);

                // Apply part info params.
                PartInfo partInfo = listParts[indexMeshPart];

                if (partInfo.DiffuseTexture != null)
                {
                    // TODO This is just a hack to keep things from breaking.  The real issue
                    // here is that we need to rebuild the ReflexHandle line number cache
                    // textures when the device is lost and at this time I'm not real sure
                    // how to get there from here...
                    // mattmac: need to test if overlaytexture exists                    bool staleTextures = partInfo.OverlayTexture.GraphicsDevice.IsDisposed || partInfo.OverlayTexture.IsDisposed;
                    bool noOverlay = partInfo.OverlayTexture == null ||
                                     partInfo.OverlayTexture.GraphicsDevice.IsDisposed ||
                                     partInfo.OverlayTexture.IsDisposed;

                    if (noOverlay)
                    {
                        effect.Parameters["OverlayTexture"].SetValue(partInfo.DiffuseTexture);      // Foreground texture.
                        effect.CurrentTechnique = effect.Techniques["OneTextureColorPass"];
                    }
                    else
                    {
                        effect.Parameters["OverlayTexture"].SetValue(partInfo.OverlayTexture);      // Foreground texture, ie the icon itself.
                        effect.Parameters["DiffuseTexture"].SetValue(partInfo.DiffuseTexture);      // Background texture, soft glow.

                        effect.CurrentTechnique = effect.Techniques["TwoTextureColorPass"];
                    }
                }
                else
                {
                    if (partInfo.OverlayTexture == null)
                    {
                        effect.CurrentTechnique = effect.Techniques["NoTextureColorPass"];
                    }
                    else
                    {
                        effect.Parameters["OverlayTexture"].SetValue(partInfo.OverlayTexture);      // Foreground texture.
                        effect.CurrentTechnique = effect.Techniques["OneTextureColorPass"];
                    }
                }

                effect.Parameters["DiffuseColor"].SetValue(partInfo.DiffuseColor);
                effect.Parameters["SpecularColor"].SetValue(partInfo.SpecularColor);
                effect.Parameters["EmissiveColor"].SetValue(partInfo.EmissiveColor);
                effect.Parameters["SpecularPower"].SetValue(partInfo.SpecularPower);

                effect.CurrentTechnique.Passes[0].Apply();

                for (int indexPass = 0; indexPass < effect.CurrentTechnique.Passes.Count; indexPass++)
                {
                    EffectPass pass = (EffectPass)effect.CurrentTechnique.Passes[indexPass];
                    pass.Apply();
                    device.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                                 part.VertexOffset,
                                                 0,
                                                 part.NumVertices,
                                                 part.StartIndex,
                                                 part.PrimitiveCount);
                }
            }
            //device.RenderState.FillMode = tempFillMode;
        }