Exemplo n.º 1
0
        public void ParseDotScene(String SceneName, String groupName, SceneManager yourSceneMgr, SceneNode pAttachNode, String sPrependNode)
        {
            //Mogre.Root root = new Mogre.Root();
            if (groupName == null)
                groupName = "General";// Mogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME;

            // set up shared object values
            m_sGroupName = groupName;
            mSceneMgr = yourSceneMgr;
            m_sPrependNode = sPrependNode;
            this.StaticObjects = new List<string>();
            this.DynamicObjects = new List<string>();

            XmlDocument XMLDoc = null;
            XmlElement XMLRoot;

            System.IO.StreamReader sreader = System.IO.File.OpenText(SceneName);
            string data = sreader.ReadToEnd();

            //Mogre.StringVectorPtr vectorPtr = Mogre.ResourceGroupManager.Singleton.ListResourceNames(Mogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
            //for (int i = 0; i < vectorPtr.Count; i++)
            //{
            //    m_log.Info("res: " + vectorPtr[i]);
            //}
            string path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
            if(path.StartsWith("file:\\"))
            {
                path = path.Replace("file:\\", "");
            }
            //Mogre.ResourceGroupManager.Singleton.AddResourceLocation(path,"FileSystem", "General");
            //Mogre.DataStreamPtr pStream = Mogre.ResourceGroupManager.Singleton.OpenResource(SceneName, groupName);

            //String data = pStream.AsString;
            // Open the .scene File
            XMLDoc = new XmlDocument();
            XMLDoc.LoadXml(data);
            //pStream.Close();

            // Validate the File
            XMLRoot = XMLDoc.DocumentElement;
            if (XMLRoot.Name != "scene")
            {
                m_log.Error("[DotSceneLoader] Error: Invalid .scene File. Missing <scene>");
                return;
            }

            // figure out where to attach any nodes we create
            mAttachNode = pAttachNode;
            if (mAttachNode == null)
                mAttachNode = mSceneMgr.RootSceneNode;

            // Process the scene
            processScene(XMLRoot);
        }
Exemplo n.º 2
0
 protected void processUserDataReference(XmlElement XMLNode, SceneNode pNode)
 {
     // TODO
 }
Exemplo n.º 3
0
        protected void processPlane(XmlElement XMLNode, SceneNode pParent)
        {
            string name = getAttrib(XMLNode, "name");
            float distance = getAttribReal(XMLNode, "distance");
            float width = getAttribReal(XMLNode, "width");
            float height = getAttribReal(XMLNode, "height");

            int xSegments = (int)getAttribReal(XMLNode, "xSegments");
            int ySegments = (int)getAttribReal(XMLNode, "ySegments");
            int numTexCoordSets = (int)getAttribReal(XMLNode, "numTexCoordSets");
            float uTile = getAttribReal(XMLNode, "uTile");
            float vTile = getAttribReal(XMLNode, "vTile");
            string material = getAttrib(XMLNode, "material");
            bool normals = getAttribBool(XMLNode, "normals");
            bool movablePlane = getAttribBool(XMLNode, "movablePlane");
            bool castShadows = getAttribBool(XMLNode, "castShadows");
            bool receiveShadows = getAttribBool(XMLNode, "receiveShadows");

            //Mogre.Vector3 normal = Mogre.Vector3.ZERO;
            //XmlElement pElement = (XmlElement)XMLNode.SelectSingleNode("normal");
            //if (pElement != null)
            //    normal = omvVector3AsMogreVector3(parseVector3(pElement));

            //Mogre.Vector3 upVector = Mogre.Vector3.UNIT_Y;
            //pElement = (XmlElement)XMLNode.SelectSingleNode("upVector");
            //if (pElement != null)
            //    upVector = omvVector3AsMogreVector3(parseVector3(pElement));

            //Mogre.Plane pPlane = new Mogre.Plane(normal, upVector);

            //Entity pEntity = null;
            //try
            //{
            //    Mogre.MeshPtr ptr = Mogre.MeshManager.Singleton.CreatePlane(name, m_sGroupName, pPlane, width, height, xSegments, ySegments, normals, numTexCoordSets, uTile, vTile, upVector);
            //    pEntity = mSceneMgr.CreateEntity(name, name);
            //    pParent.AttachObject(pEntity);
            //}
            //catch (Exception e)
            //{
            //    m_log.Error("[DotSceneLoader] Error loading an entity!" + e.Message);
            //}
        }
Exemplo n.º 4
0
        //no fog at the moment
        //protected void processFog(XmlElement XMLNode)
        //{
        //    // Process attributes
        //    float linearStart = getAttribReal(XMLNode, "linearStart", 0.0f);
        //    float linearEnd = getAttribReal(XMLNode, "linearEnd", 1.0f);
        //    FogMode mode = FogMode.FOG_NONE;
        //    String sMode = getAttrib(XMLNode, "mode");
        //    // only linear atm
        //    if (sMode == "none")
        //        mode = FogMode.FOG_NONE;
        //    else if (sMode == "exp")
        //        mode = FogMode.FOG_EXP;
        //    else if (sMode == "exp2")
        //        mode = FogMode.FOG_EXP2;
        //    else if (sMode == "linear")
        //        mode = FogMode.FOG_LINEAR;
        //    XmlElement pElement;
        //    // Process colourDiffuse (?)
        //    ColourValue colourDiffuse = ColourValue.White;
        //    pElement = (XmlElement)XMLNode.SelectSingleNode("colourDiffuse");
        //    if (pElement != null)
        //        colourDiffuse = parseColour(pElement);
        //    // Setup the fog
        //    mSceneMgr.SetFog(mode, colourDiffuse, 0.001f, linearStart, linearEnd);
        //}
        // no processLight at the moment
        //protected void processLight(XmlElement XMLNode, SceneNode pParent)
        //{
        //    // Process attributes
        //    String name = getAttrib(XMLNode, "name");
        //    // Create the light
        //    Light pLight = mSceneMgr.CreateLight(name);
        //    if (pParent != null)
        //        pParent.AttachObject(pLight);
        //    String sValue = getAttrib(XMLNode, "type");
        //    if (sValue == "point")
        //        pLight.Type = Light.LightTypes.LT_POINT;
        //    else if (sValue == "directional")
        //        pLight.Type = Light.LightTypes.LT_DIRECTIONAL;
        //    else if (sValue == "spotLight")
        //        pLight.Type = Light.LightTypes.LT_SPOTLIGHT;
        //    // only set if Lamp is Spotlight (Blender)
        //    bool castShadow = true;
        //    if (XMLNode.HasAttribute("castShadow"))
        //    {
        //        castShadow = getAttribBool(XMLNode, "castShadow", true);
        //    }
        //    else if (XMLNode.HasAttribute("castShadows"))
        //    {
        //        castShadow = getAttribBool(XMLNode, "castShadows", true);
        //    }
        //    pLight.CastShadows = castShadow;
        //    XmlElement pElement;
        //    // Process normal (?)
        //    pElement = (XmlElement)XMLNode.SelectSingleNode("normal");
        //    if (pElement != null)
        //        pLight.Direction = parseVector3(pElement);
        //    // Process colourDiffuse (?)
        //    pElement = (XmlElement)XMLNode.SelectSingleNode("colourDiffuse");
        //    if (pElement != null)
        //        pLight.DiffuseColour = parseColour(pElement);
        //    // Process colourSpecular (?)
        //    pElement = (XmlElement)XMLNode.SelectSingleNode("colourSpecular");
        //    if (pElement != null)
        //        pLight.SpecularColour = parseColour(pElement);
        //    // Process lightRange (?)
        //    pElement = (XmlElement)XMLNode.SelectSingleNode("lightRange");
        //    if (pElement != null)
        //        processLightRange(pElement, pLight);
        //    // Process lightAttenuation (?)
        //    pElement = (XmlElement)XMLNode.SelectSingleNode("lightAttenuation");
        //    if (pElement != null)
        //        processLightAttenuation(pElement, pLight);
        //}
        //protected void processLightAttenuation(XmlElement XMLNode, Mogre.Light pLight)
        //{
        //    // Process attributes
        //    float range = getAttribReal(XMLNode, "range");
        //    float constant = getAttribReal(XMLNode, "constant");
        //    float linear = getAttribReal(XMLNode, "linear");
        //    float quadratic = getAttribReal(XMLNode, "quadratic");
        //    // Setup the light attenuation
        //    pLight.SetAttenuation(range, constant, linear, quadratic);
        //}
        //protected void processLightRange(XmlElement XMLNode, Mogre.Light pLight)
        //{
        //    // Process attributes
        //    float inner = getAttribReal(XMLNode, "inner");
        //    float outer = getAttribReal(XMLNode, "outer");
        //    float falloff = getAttribReal(XMLNode, "falloff", 1.0f);
        //    // Setup the light range
        //    pLight.SetSpotlightRange(new Radian(inner), new Radian(outer), falloff);
        //}
        protected void processNode(XmlElement XMLNode, SceneNode pParent)
        {
            // Construct the node's name
            String name = m_sPrependNode + getAttrib(XMLNode, "name");

            // Create the scene node
            SceneNode pNode;
            if (name.Length == 0)
            {
                // Let Ogre choose the name
                if (pParent != null)
                    pNode = pParent.CreateChildSceneNode();
                else
                    pNode = mAttachNode.CreateChildSceneNode();
            }
            else
            {
                // Provide the name
                if (pParent != null)
                    pNode = pParent.CreateChildSceneNode(name);
                else
                    pNode = mAttachNode.CreateChildSceneNode(name);
            }

            // Process other attributes
            XmlElement pElement;

            // Process position (?)
            pElement = (XmlElement)XMLNode.SelectSingleNode("position");
            if (pElement != null)
            {
                pNode.Position = parseVector3(pElement);
                pNode.SetInitialState();
            }

            // Process quaternion (?)
            pElement = (XmlElement)XMLNode.SelectSingleNode("quaternion");
            if (pElement != null)
            {
                pNode.Orientation = parseQuaternion(pElement);
                pNode.SetInitialState();
            }

            // Process rotation (?)
            pElement = (XmlElement)XMLNode.SelectSingleNode("rotation");
            if (pElement != null)
            {
                pNode.Orientation = parseRotation(pElement);
                pNode.SetInitialState();
            }

            // Process scale (?)
            pElement = (XmlElement)XMLNode.SelectSingleNode("scale");
            if (pElement != null)
            {
                pNode.Scale = parseVector3(pElement);
                pNode.SetInitialState();
            }

            // Process entity (*)
            pElement = (XmlElement)XMLNode.SelectSingleNode("entity");
            if (pElement != null)
            {
                processEntity(pElement, pNode);
            }

            // Process light (*)
            pElement = (XmlElement)XMLNode.SelectSingleNode("light");
            //if (pElement != null)
            //{
            //    processLight(pElement, pNode);
            //}

            // Process plane (*)
            pElement = (XmlElement)XMLNode.SelectSingleNode("plane");
            while (pElement != null)
            {
                processPlane(pElement, pNode);
                pElement = (XmlElement)pElement.NextSibling;
            }

            // Process camera (*)
            pElement = (XmlElement)XMLNode.SelectSingleNode("camera");
            if (pElement != null)
            {
                processCamera(pElement, pNode);
            }

            // Process userDataReference (?)
            pElement = (XmlElement)XMLNode.SelectSingleNode("userData");
            if (pElement != null)
                processUserDataReference(pElement, pNode);

            // Process childnodes
            pElement = (XmlElement)XMLNode.SelectSingleNode("node");
            while (pElement != null)
            {
                processNode(pElement, pNode);
                pElement = (XmlElement)pElement.NextSibling;
            }
        }
Exemplo n.º 5
0
 public void ParseDotScene(String SceneName, String groupName, SceneManager yourSceneMgr, SceneNode pAttachNode)
 {
     ParseDotScene(SceneName, groupName, yourSceneMgr, pAttachNode, "");
 }
Exemplo n.º 6
0
        //protected Mogre.Vector3 omvVector3AsMogreVector3(OpenMetaverse.Vector3 vector)
        //{
        //    return new Mogre.Vector3(vector.X, vector.Y, vector.Z);
        //}
        protected void processCamera(XmlElement XMLNode, SceneNode pParent)
        {
            // Process attributes
            String name = getAttrib(XMLNode, "name");

            // Create the light
            //Camera pCamera = mSceneMgr.CreateCamera(name);
            //if (pParent != null)
            //    pParent.AttachObject(pCamera);

            float pFov = getAttribReal(XMLNode, "fov", 45);
            //pCamera.FOVy = new Degree(pFov);

            String sValue = getAttrib(XMLNode, "projectionType", "perspective");
            //if (sValue == "perspective")
            //    pCamera.ProjectionType = ProjectionType.PT_PERSPECTIVE;
            //else if (sValue == "orthographic")
            //    pCamera.ProjectionType = ProjectionType.PT_ORTHOGRAPHIC;

            XmlElement pElement;

            // Process normal (?)
            pElement = (XmlElement)XMLNode.SelectSingleNode("clipping");
            if (pElement != null)
            {
                // Blender
                float nearDist = getAttribReal(pElement, "nearPlaneDist");
                if (nearDist == 0)
                {
                    // 3ds
                    nearDist = getAttribReal(pElement, "near");
                }
                //pCamera.NearClipDistance = nearDist;

                // Blender
                float farDist = getAttribReal(pElement, "farPlaneDist");
                if (farDist == 0)
                {
                    // 3ds
                    farDist = getAttribReal(pElement, "far");
                }
                //pCamera.FarClipDistance = farDist;
            }
        }
Exemplo n.º 7
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
            {
                //Mogre.MeshPtr mesh = Mogre.MeshManager.Singleton.Load(meshFile, m_sGroupName);
                //ushort src, dest;
                //mesh.SuggestTangentVectorBuildParams(Mogre.VertexElementSemantic.VES_TANGENT, out src, out dest);
                //mesh.BuildTangentVectors(Mogre.VertexElementSemantic.VES_TANGENT, src, dest);

                pEntity = mSceneMgr.CreateEntity(name, meshFile);
                pEntity.Visible = bvisible;
                pEntity.CastShadows = bcastshadows;
                pEntity.RenderingDistance = brenderingDistance;

                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)
            {
                m_log.Error("[DotSceneLoader] Error loading an entity! " + e.Message);
            }
        }
Exemplo n.º 8
0
 internal SceneNode CreateChildSceneNode(string name)
 {
     SceneNode newNode = new SceneNode(this, name);
     Children.Add(newNode);
     return newNode;
 }
Exemplo n.º 9
0
 internal SceneNode CreateChildSceneNode()
 {
     SceneNode newNode = new SceneNode(this);
     Children.Add(newNode);
     return newNode;
 }
Exemplo n.º 10
0
 public SceneNode(SceneNode parent, string name)
 {
     m_parent = parent;
     m_name = name;
 }
Exemplo n.º 11
0
 public SceneNode(SceneNode parent)
 {
     m_parent = parent;
 }
Exemplo n.º 12
0
        private void AddObjectsToScene(SceneNode node, Dictionary<string, UUID> materials, string additionalSearchPath)
        {
            // Quaternion for whole scene rotation
            Quaternion sceneRotQuat = Quaternion.CreateFromAxisAngle(new Vector3(0,0,1), ToRadians(m_sceneRotation));

            // Make sure node global transform is refreshed
            node.RefreshDerivedTransform();

            if (node.Entities.Count >= 0) //add this to scene and do stuff
            {
                foreach (Entity ent in node.Entities)
                {
                    //first check that file exists
                    bool usePath = false;
                    string p = System.IO.Path.Combine(additionalSearchPath, ent.MeshName);
                    if (!System.IO.File.Exists(ent.MeshName) && System.IO.File.Exists(p)) { usePath = true; }

                    if (!System.IO.File.Exists(ent.MeshName) && !System.IO.File.Exists(p))
                    {
                        m_log.ErrorFormat("[OGRESCENE]: Could not find mesh file {0}. Skipping", ent.MeshName);
                        continue;
                    }

                    //Load mesh object
                    byte[] data;
                    if (!usePath)
                        data = System.IO.File.ReadAllBytes(ent.MeshName);
                    else
                        data = System.IO.File.ReadAllBytes(p);

                    //Add mesh to asset db
                    AssetBase asset = new AssetBase(UUID.Random(), ent.MeshName, 43, m_scene.RegionInfo.EstateSettings.EstateOwner.ToString());
                    asset.Description = ent.Name;
                    asset.Data = data;
                    m_scene.AssetService.Store(asset);

                    //Read material names
                    List<string> materialNames;
                    string meshLoaderError;
                    RexDotMeshLoader.DotMeshLoader.ReadDotMeshMaterialNames(data, out materialNames, out meshLoaderError);
                    if (meshLoaderError != "")
                    {
                        //probably error in the mesh. this can't be fixed.
                        //setting this to physics engine could have devastating effect.
                        //must skip this object
                        m_log.ErrorFormat("[OGRESCENE]: Error occurred while parsing material names from mesh {0}. Error message {1}", ent.MeshName, meshLoaderError);
                    }

                    //check that postition of the object is inside scene
                    Vector3 objPos = new Vector3(node.DerivedPosition.X, node.DerivedPosition.Y, node.DerivedPosition.Z);
                    if (m_swapAxes == true)
                    {
                        Vector3 temp = new Vector3(objPos);
                        objPos.X = -temp.X;
                        objPos.Y = temp.Z;
                        objPos.Z = temp.Y;
                    }
                    objPos = objPos * sceneRotQuat; // Apply scene rotation
                    objPos = (objPos * m_objectScale) + m_offset; // Apply scale and add offset
                    if (objPos.X >= 0 && objPos.Y >= 0 && objPos.Z >= 0 &&
                        objPos.X <= 256 && objPos.Y <= 256 && objPos.Z <= 256)
                    {
                        if (objPos.Z < 20)
                            m_log.WarnFormat("[OGRESCENE]: Inserting object {1} to height {0}. This object might be under water", objPos.Z, ent.MeshName);

                        //Add object to scene
                        Quaternion rot = new Quaternion(node.DerivedOrientation.X, node.DerivedOrientation.Y, node.DerivedOrientation.Z, node.DerivedOrientation.W);
                        if (m_swapAxes == true)
                        {
                            Vector3 temp = new Vector3(rot.X, rot.Y, rot.Z);
                            rot.X = -temp.X;
                            rot.Y = temp.Z;
                            rot.Z = temp.Y;
                        }
                        else
                        {
                            // Do the rotation adjust as in original importer
                            rot *= new Quaternion(1, 0, 0);
                            rot *= new Quaternion(0, 1, 0);
                        }
                        rot = sceneRotQuat * rot;

                        SceneObjectGroup sceneObject = m_scene.AddNewPrim(m_scene.RegionInfo.EstateSettings.EstateOwner,
                            m_scene.RegionInfo.EstateSettings.EstateOwner, objPos, rot, PrimitiveBaseShape.CreateBox());
                        Vector3 newScale = new Vector3();
                        newScale.X = node.DerivedScale.X * m_objectScale;
                        newScale.Y = node.DerivedScale.Y * m_objectScale;
                        newScale.Z = node.DerivedScale.Z * m_objectScale;
                        if (m_swapAxes == true)
                        {
                            Vector3 temp = new Vector3(newScale);
                            newScale.X = temp.X;
                            newScale.Y = temp.Z;
                            newScale.Z = temp.Y;
                        }
                        sceneObject.RootPart.Scale = newScale;

                        //Add refs to materials, mesh etc.
                        IModrexObjectsProvider rexObjects = m_scene.RequestModuleInterface<IModrexObjectsProvider>();
                        RexObjectProperties robject = rexObjects.GetObject(sceneObject.RootPart.UUID);
                        robject.RexMeshUUID = asset.FullID;
                        robject.RexDrawDistance = ent.RenderingDistance;
                        robject.RexCastShadows = ent.CastShadows;
                        robject.RexDrawType = 1;

                        // Only assign physics mesh if no error
                        if ((meshLoaderError == "") && (m_useCollisionMesh == true))
                        {
                            try
                            {
                                robject.RexCollisionMeshUUID = asset.FullID;
                            }
                            catch (Exception)
                            {
                            }
                        }

                        for (int i = 0; i < materialNames.Count; i++)
                        {
                            UUID materilUUID;
                            if (materials.TryGetValue(materialNames[i], out materilUUID))
                            {
                                robject.RexMaterials.AddMaterial((uint)i, materilUUID);
                            }
                            else
                            {
                                m_log.ErrorFormat("[OGRESCENE]: Could not find material UUID for material {0}. Skipping material", materialNames[i]);
                                continue;
                            }
                        }
                    }
                    else
                    {
                        m_log.ErrorFormat("[OGRESCENE]: Node postion was not inside the scene. Skipping object {0} with position {1}", ent.MeshName, objPos.ToString());
                        continue;
                    }
                }
            }

            if (node.Children.Count >= 0)
            {
                foreach (SceneNode child in node.Children)
                {
                    AddObjectsToScene(child, materials, additionalSearchPath);
                }
            }
        }