Пример #1
0
        protected void processEntity(XmlElement XMLNode, SceneNode pParent)
        {
            // Process attributes
            String name     = getAttrib(XMLNode, "name");
            String meshFile = getAttrib(XMLNode, "meshFile");

            bool bstatic = getAttribBool(XMLNode, "static", false);

            if (bstatic)
            {
                StaticObjects.Add(name);
            }
            else
            {
                DynamicObjects.Add(name);
            }

            bool  bvisible           = getAttribBool(XMLNode, "visible", true);
            bool  bcastshadows       = getAttribBool(XMLNode, "castShadows", true);
            float brenderingDistance = getAttribReal(XMLNode, "renderingDistance", 0);

            // Create the entity
            Entity pEntity = null;

            try
            {
                MeshPtr mesh = MeshManager.Singleton.Load(meshFile, m_sGroupName);
                ushort  src, dest;
                mesh.SuggestTangentVectorBuildParams(VertexElementSemantic.VES_TANGENT, out src, out dest);
                mesh.BuildTangentVectors(VertexElementSemantic.VES_TANGENT, src, dest);

                pEntity                   = mSceneMgr.CreateEntity("SCENE_OBJECT_" + name + "_" + Guid.NewGuid().ToString(), meshFile);
                pEntity.Visible           = bvisible;
                pEntity.CastShadows       = bcastshadows;
                pEntity.RenderingDistance = brenderingDistance;
                pEntity.QueryFlags        = 1 << 0;

                XmlElement pElement;
                // Process subentities (?)
                pElement = (XmlElement)XMLNode.SelectSingleNode("subentities");
                if (pElement != null)
                {
                    pElement = (XmlElement)pElement.FirstChild;
                    while (pElement != null)
                    {
                        string mat = getAttrib(pElement, "materialName");
                        pEntity.SetMaterialName(mat);
                        pElement = (XmlElement)pElement.NextSibling;
                    }
                }

                pParent.AttachObject(pEntity);
            }
            catch (Exception e)
            {
                LogManager.Singleton.LogMessage("[DotSceneLoader] Error loading an entity!" + e.Message);
            }
        }
Пример #2
0
        private void createSphere(string strName, float r, SceneManager sceneMgr, int nRings = 16, int nSegments = 16)
        {
            ManualObject manual = sceneMgr.CreateManualObject(strName);

            manual.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            float  fDeltaRingAngle = (Mogre.Math.PI / nRings);
            float  fDeltaSegAngle  = (2 * Mogre.Math.PI / nSegments);
            ushort wVerticeIndex   = 0;

            // Generate the group of rings for the sphere
            for (int ring = 0; ring <= nRings; ring++)
            {
                float r0 = r * Mogre.Math.Sin(ring * fDeltaRingAngle);
                float y0 = r * Mogre.Math.Cos(ring * fDeltaRingAngle);

                // Generate the group of segments for the current ring
                for (int seg = 0; seg <= nSegments; seg++)
                {
                    float x0 = r0 * Mogre.Math.Sin(seg * fDeltaSegAngle);
                    float z0 = r0 * Mogre.Math.Cos(seg * fDeltaSegAngle);

                    // Add one vertex to the strip which makes up the sphere
                    manual.Position(x0, y0, z0);
                    manual.Normal(new Mogre.Vector3(x0, y0, z0).NormalisedCopy);
                    manual.TextureCoord((float)seg / (float)nSegments, (float)ring / (float)nRings);

                    if (ring != nRings)
                    {
                        // each vertex (except the last) has six indicies pointing to it
                        manual.Index((uint)(wVerticeIndex + nSegments + 1));
                        manual.Index(wVerticeIndex);
                        manual.Index((uint)(wVerticeIndex + nSegments));
                        manual.Index((uint)(wVerticeIndex + nSegments + 1));
                        manual.Index((uint)(wVerticeIndex + 1));
                        manual.Index(wVerticeIndex);
                        wVerticeIndex++;
                    }
                }
                ;  // end for seg
            } // end for ring
            manual.End();
            MeshPtr mesh = manual.ConvertToMesh(strName);

            mesh._setBounds(new AxisAlignedBox(new Mogre.Vector3(-r, -r, -r), new Mogre.Vector3(r, r, r)), false);

            mesh._setBoundingSphereRadius(r);
            ushort src, dest;

            if (!mesh.SuggestTangentVectorBuildParams(VertexElementSemantic.VES_TANGENT, out src, out dest))
            {
                mesh.BuildTangentVectors(VertexElementSemantic.VES_TANGENT, src, dest);
            }
        }
Пример #3
0
        public override void CreateScene()
        {
            //Check to see if vertex and fragment programs are supported
            if (!Root.Singleton.RenderSystem.Capabilities.HasCapability(Capabilities.RSC_VERTEX_PROGRAM))
            {
                MessageBox.Show("Your graphics card does not support vertex shaders and cannot run this demo.\nDot3Bump.CreateScene");
            }
            else if (!Root.Singleton.RenderSystem.Capabilities.HasCapability(Capabilities.RSC_FRAGMENT_PROGRAM) ||
                     !Root.Singleton.RenderSystem.Capabilities.HasCapability(Capabilities.RSC_DOT3))
            {
                MessageBox.Show("Your graphics card does not support dot3 blending or fragment programs and cannot run this demo.\nDot3Bump.CreatScene");
            }
            else
            {
                //set ambient light
                sceneMgr.AmbientLight = new ColourValue(0f, 0f, 0f);

                mMainNode = sceneMgr.RootSceneNode.CreateChildSceneNode();

                //Load the meshes with nond default HBU options
                for (int mn = 0; mn < NUM_ENTITIES; mn++)
                {
                    MeshPtr pMesh = MeshManager.Singleton.Load(mEntityMeshes[mn],
                                                               ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                                                               HardwareBuffer.Usage.HBU_DYNAMIC_WRITE_ONLY,
                                                               HardwareBuffer.Usage.HBU_STATIC_WRITE_ONLY,
                                                               true,
                                                               true);                  //can still read it
                    ushort src, dest;
                    if (!pMesh.SuggestTangentVectorBuildParams(VertexElementSemantic.VES_TANGENT, out src, out dest))
                    {
                        pMesh.BuildTangentVectors(VertexElementSemantic.VES_TANGENT, src, dest);
                    }

                    //create entity
                    mEntities[mn] = sceneMgr.CreateEntity("Ent" + mn.ToString(), mEntityMeshes[mn]);
                    //attach to main node
                    mMainNode.AttachObject(mEntities[mn]);
                    //make invisible except for index 0
                    if (mn == 0)
                    {
                        mEntities[mn].SetMaterialName(mMaterialNames[mCurrentEntity][mCurrentMaterial]);
                    }
                    else
                    {
                        mEntities[mn].Visible = false;
                    }
                }
                for (int i = 0; i < NUM_LIGHTS; i++)
                {
                    mLightPivots[i] = sceneMgr.RootSceneNode.CreateChildSceneNode();
                    mLightPivots[i].Rotate(mLightRotationAxes[i], mLightRotationAngles[i]);
                    //create a light, use default parameters
                    mLights[i]                = sceneMgr.CreateLight("Light" + i.ToString());
                    mLights[i].Position       = mLightPositions[i];
                    mLights[i].DiffuseColour  = mDiffuseLightColours[i];
                    mLights[i].SpecularColour = mSpecularLightColours[i];
                    mLights[i].Visible        = mLightState[i];
                    //attach light to pivot
                    mLightPivots[i].AttachObject(mLights[i]);
                    //create billboard for the light
                    mLightFlareSets[i] = sceneMgr.CreateBillboardSet("Flare" + i.ToString());
                    mLightFlareSets[i].MaterialName = "Examples/Flare";
                    mLightPivots[i].AttachObject(mLightFlareSets[i]);
                    mLightFlares[i]            = mLightFlareSets[i].CreateBillboard(mLightPositions[i]);
                    mLightFlares[i].Colour     = mDiffuseLightColours[i];
                    mLightFlareSets[i].Visible = true;
                }
                //move the camera to the right and make it look at the mesh
                camera.MoveRelative(new Vector3(50f, 0f, 20f));
                camera.LookAt(0f, 0f, 0f);
                //show overlay
                Overlay Over = OverlayManager.Singleton.GetByName("Example/DP3Overlay");
                mObjectInfo   = OverlayManager.Singleton.GetOverlayElement("Example/DP3/ObjectInfo");
                mMaterialInfo = OverlayManager.Singleton.GetOverlayElement("Example/DP3/MaterialInfo");
                mInfo         = OverlayManager.Singleton.GetOverlayElement("Example/DP3/Info");

                mObjectInfo.Caption   = "Current" + mEntityMeshes[mCurrentEntity];
                mMaterialInfo.Caption = "Current" + mMaterialNames[mCurrentEntity][mCurrentMaterial];
                if (!Root.Singleton.RenderSystem.Capabilities.HasCapability(Capabilities.RSC_FRAGMENT_PROGRAM))
                {
                    mInfo.Caption = "NOTE: Light colours and specular highlights are not supported by your card";
                }
                Over.Show();

                //register key event monitor
            }
        }