Beispiel #1
0
        protected override void DrawPrimitive(eLevelofDetail lod, UWB_DrawHelper drawHelper)
        {
            UWB_XNAGraphicsDevice graphics = UWB_XNAGraphicsDevice.m_TheAPI;

            try
            {
                mesh = graphics.mResources.Load <Model>(filename);
                DrawMesh(true, this.mFlatColor, drawHelper);
            }
            catch (Exception e)
            {
                UWBGL_XNA_Lib.UWB_Utility.echoToStatusArea((e.Message));
            }
        }
Beispiel #2
0
        protected override void DrawPrimitive(eLevelofDetail lod, UWB_DrawHelper draw_helper)
        {
            UWB_XNAGraphicsDevice graphics      = UWB_XNAGraphicsDevice.m_TheAPI;
            UWB_XNAPrimitiveMesh  pCylinderMesh = new UWB_XNAPrimitiveMesh("cylinder");
            UWB_XNAPrimitiveMesh  pConeMesh     = new UWB_XNAPrimitiveMesh("cone");

            if (pCylinderMesh != null && pConeMesh != null)
            {
                pCylinderMesh.Material = Material;
                pConeMesh.Material     = Material;
                draw_helper.pushModelTransform();
                {
                    // Need to add support for finding the bounding box of a mesh
                    // the Z value is hard coded until then
                    //UWB_BoundingBox box = (pCylinderMesh.getBoundingVolume(draw_helper.getLod()) as UWB_BoundingBox);
                    UWB_XFormInfo cylinder_xform = new UWB_XFormInfo();
                    cylinder_xform.SetScale(new Vector3(0.025f, 0.025f, 0.2666666666f));
                    cylinder_xform.UpdateRotationYByDegree(-90.0f);
                    cylinder_xform.SetTranslation(new Vector3(0.4f, 0.0f, 0.0f));
                    cylinder_xform.setupModelStack(draw_helper);
                    try
                    {
                        pCylinderMesh.setMesh(graphics.mResources.Load <Model>("cylinder"));
                        pCylinderMesh.DrawMesh(true, mFlatColor, draw_helper);
                    }
                    catch (Exception e) { UWBGL_XNA_Lib.UWB_Utility.echoToStatusArea((e.Message)); }
                    //pCylinderMesh.DrawMesh(false, mFlatColor,draw_helper);
                }
                draw_helper.popModelTransform();

                draw_helper.pushModelTransform();
                {
                    //const UWB_BoundingBox box = pConeMesh.getBoundingBox();
                    UWB_XFormInfo cone_xform = new UWB_XFormInfo();
                    cone_xform.SetScale(new Vector3(0.08f, 0.08f, 0.1f));
                    cone_xform.UpdateRotationYByDegree(-90.0f);
                    cone_xform.SetTranslation(new Vector3(0.85f, 0.0f, 0.0f));
                    cone_xform.setupModelStack(draw_helper);
                    try
                    {
                        pConeMesh.setMesh(graphics.mResources.Load <Model>("cone"));
                        pConeMesh.DrawMesh(true, mFlatColor, draw_helper);
                    }
                    catch (Exception e) { UWBGL_XNA_Lib.UWB_Utility.echoToStatusArea((e.Message)); }
                    //pConeMesh.DrawMesh(false, mFlatColor, draw_helper);
                }
                draw_helper.popModelTransform();
            }
        }
Beispiel #3
0
        public override UWB_BoundingVolume getBoundingVolume(eLevelofDetail lod)
        {
            UWB_XNAGraphicsDevice graphics = UWB_XNAGraphicsDevice.m_TheAPI;

            try
            {
                mesh = graphics.mResources.Load <Model>(filename);
                return(m_bounds);
            }
            catch (Exception e)
            {
                UWBGL_XNA_Lib.UWB_Utility.echoToStatusArea((e.Message));
                return(null);
            }
        }
Beispiel #4
0
        public virtual void DrawMesh(bool bShowflatColor, Color MaterialColor, UWB_DrawHelper drawHelper)
        {
            UWB_XNAGraphicsDevice graphics = UWB_XNAGraphicsDevice.m_TheAPI;
            GraphicsDevice        device   = UWB_XNAGraphicsDevice.m_TheAPI.GraphicsDevice;

            UWB_XNAEffect effect = UWB_XNAGraphicsDevice.m_TheAPI.LightingEffect;

            SetupDrawAttributes(drawHelper);

            UWB_Material material = this.m_Material;

            //if (bShowflatColor && !m_bTexturingEnabled)
            //{
            //    material = new UWB_Material(Color.Gray.ToVector4(),
            //        Color.Gray.ToVector4(),
            //        Color.Gray.ToVector4(),
            //        Color.White.ToVector4(), 1f);

            //    material.Emissive = MaterialColor.ToVector4();
            //}

            /* If texturing is enabled, there are two option... one is that
             * there has been a texture set for the mesh, and another is that
             * the mesh has a texture defined inside the mesh file. In the
             * second case, this only checks the FIRST mesh part and uses the
             * FIRST texture. */

            Texture2D texture = null;

            if (this.m_bTexturingEnabled)
            {
                texture = UWB_XNAGraphicsDevice.m_TheAPI.RetrieveTexture(m_TexFileName);

                BasicEffect meshEffect  = (mesh.Meshes[0].MeshParts[0].Effect as BasicEffect);
                Texture2D   partTexture = meshEffect.Texture;

                // If there is no supplied texture then use the texture and material of the first mesh part
                if (texture == null && partTexture != null)
                {
                    texture           = partTexture;
                    material.Ambient  = new Vector4(meshEffect.AmbientLightColor, meshEffect.Alpha);
                    material.Diffuse  = new Vector4(meshEffect.DiffuseColor, meshEffect.Alpha);
                    material.Emissive = new Vector4(meshEffect.EmissiveColor, meshEffect.Alpha);
                    material.Specular = new Vector4(meshEffect.SpecularColor, meshEffect.Alpha);
                    material.Power    = meshEffect.SpecularPower;
                }
            }

            effect.Material = material;

            if (texture != null)
            {
                effect.Texture        = texture;
                effect.TextureEnabled = true;
            }
            else
            {
                effect.Texture        = texture;
                effect.TextureEnabled = false;
            }


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

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

                    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                    {
                        pass.Apply();

                        device.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                                     mp.VertexOffset, 0,
                                                     mp.NumVertices, mp.StartIndex, mp.PrimitiveCount);
                    }
                }
            }
        }