dotScene Loader in C#

BenJ

26-04-2007 23:13:16

Hello,
I have ported the C++ dotScene loader in C#, it works perfectly (from http://www.ogre3d.org/wiki/index.php/New_DotScene_Loader) :
using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Xml;
using System.Drawing;
using Mogre;
using System.Globalization;

namespace USaga
{
class nodeProperty
{
public String nodeName;
public String propertyNm;
public String valueName;
public String typeName;

public nodeProperty(String node, String propertyName, String value, String type)
{
nodeName = node;
propertyNm = propertyName;
valueName = value;
typeName = type;
}
};

class DotSceneLoader
{
public DotSceneLoader()
{
}

~DotSceneLoader()
{
}

public void parseDotScene(String SceneName, String groupName, SceneManager yourSceneMgr)
{
parseDotScene(SceneName, groupName, yourSceneMgr, null, "");
}

public void parseDotScene(String SceneName, String groupName, SceneManager yourSceneMgr, SceneNode pAttachNode)
{
parseDotScene(SceneName, groupName, yourSceneMgr, pAttachNode, "");
}

public void parseDotScene(String SceneName, String groupName, SceneManager yourSceneMgr, SceneNode pAttachNode, String sPrependNode)
{
// set up shared object values
m_sGroupName = groupName;
mSceneMgr = yourSceneMgr;
m_sPrependNode = sPrependNode;
staticObjects.Remove(0);
dynamicObjects.Remove(0);

XmlDocument XMLDoc = null;
XmlElement XMLRoot;

DataStreamPtr pStream = 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" ) {
LogManager.Singleton.LogMessage( "[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);
}

public String getProperty(String ndNm, String prop)
{
for ( int i = 0 ; i < nodeProperties.Count; i++ )
{
nodeProperty node = (nodeProperty)nodeProperties[i];
if (node.nodeName == ndNm && node.propertyNm == prop)
{
return node.valueName;
}
}

return "";
}

public ArrayList nodeProperties = new ArrayList(); //nodeProperty
public ArrayList staticObjects = new ArrayList(); //String
public ArrayList dynamicObjects = new ArrayList(); //String

protected void processScene(XmlElement XMLRoot)
{
// Process the scene parameters
String version = getAttrib(XMLRoot, "formatVersion", "unknown");

String message = "[DotSceneLoader] Parsing dotScene file with version " + version;
if (XMLRoot.GetAttribute("ID").Length > 0)
message += ", id " + XMLRoot.GetAttribute("ID");
if (XMLRoot.GetAttribute("sceneManager").Length > 0)
message += ", scene manager " + XMLRoot.GetAttribute("sceneManager");
if (XMLRoot.GetAttribute("minOgreVersion").Length > 0)
message += ", min. Ogre version " + XMLRoot.GetAttribute("minOgreVersion");
if (XMLRoot.GetAttribute("author").Length > 0)
message += ", author " + XMLRoot.GetAttribute("author");

LogManager.Singleton.LogMessage(message);

XmlElement pElement;

// Process nodes (?)
pElement = (XmlElement)XMLRoot.SelectSingleNode("nodes");
if(pElement != null)
processNodes(pElement);

// Process externals (?)
pElement = (XmlElement)XMLRoot.SelectSingleNode("externals");
if (pElement != null)
processExternals(pElement);

// Process environment (?)
pElement = (XmlElement)XMLRoot.SelectSingleNode("environment");
if (pElement != null)
processEnvironment(pElement);

// Process terrain (?)
pElement = (XmlElement)XMLRoot.SelectSingleNode("terrain");
if (pElement != null)
processTerrain(pElement);

// Process userDataReference (?)
pElement = (XmlElement)XMLRoot.SelectSingleNode("userDataReference");
if (pElement != null)
processUserDataReference(pElement);

// Process octree (?)
pElement = (XmlElement)XMLRoot.SelectSingleNode("octree");
if (pElement != null)
processOctree(pElement);

// Process light (?)
pElement = (XmlElement)XMLRoot.SelectSingleNode("light");
if (pElement != null)
processLight(pElement);

// Process camera (?)
pElement = (XmlElement)XMLRoot.SelectSingleNode("camera");
if (pElement != null)
processCamera(pElement);
}

protected void processNodes(XmlElement XMLNode)
{
XmlElement pElement;

// Process node (*)
pElement = (XmlElement)XMLNode.SelectSingleNode("node");
while (pElement != null)
{
processNode(pElement);
pElement = (XmlElement)pElement.NextSibling;
}

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

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

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

protected void processExternals(XmlElement XMLNode)
{

}

protected void processEnvironment(XmlElement XMLNode)
{
XmlElement pElement;

// Process fog (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("fog");
if (pElement != null)
processFog(pElement);

// Process skyBox (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("skyBox");
if (pElement != null)
processSkyBox(pElement);

// Process skyDome (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("skyDome");
if (pElement != null)
processSkyDome(pElement);

// Process skyPlane (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("skyPlane");
if (pElement != null)
processSkyPlane(pElement);

// Process clipping (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("clipping");
if (pElement != null)
processClipping(pElement);

// Process colourAmbient (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("colourAmbient");
if (pElement != null)
mSceneMgr.AmbientLight = parseColour(pElement);

// Process colourBackground (?)
//! @todo Set the background colour of all viewports (RenderWindow has to be provided then)
pElement = (XmlElement)XMLNode.SelectSingleNode("colourBackground");
if (pElement != null)
;//mSceneMgr->set(parseColour(pElement));

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

protected void processTerrain(XmlElement XMLNode)
{

}

protected void processUserDataReference(XmlElement XMLNode)
{

}

protected void processUserDataReference(XmlElement XMLNode, SceneNode pParent)
{

}

protected void processUserDataReference(XmlElement XMLNode, Entity pEntity)
{
String str = XMLNode.GetAttribute("id");
//pEntity.setUserAny();
}

protected void processOctree(XmlElement XMLNode)
{

}

protected void processLight(XmlElement XMLNode)
{
processLight(XMLNode, null);
}

protected void processLight(XmlElement XMLNode, SceneNode pParent)
{
// Process attributes
String name = getAttrib(XMLNode, "name");
String id = getAttrib(XMLNode, "id");

// 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 == "spot")
pLight.Type = Light.LightTypes.LT_SPOTLIGHT;
else if (sValue == "radPoint")
pLight.Type = Light.LightTypes.LT_POINT;

pLight.Visible = getAttribBool(XMLNode, "visible", true);
pLight.CastShadows = getAttribBool(XMLNode, "castShadows", true);

XmlElement pElement;

// Process position (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("position");
if (pElement != null)
pLight.Position = parseVector3(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);

// Process userDataReference (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("userDataReference");
//if (pElement != null)
//processUserDataReference(pElement, (SceneNode)pLight);
}

protected void processCamera(XmlElement XMLNode)
{

}

protected void processCamera(XmlElement XMLNode, SceneNode pParent)
{

}

protected void processNode(XmlElement XMLNode)
{
processNode(XMLNode, null);
}

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
String id = getAttrib(XMLNode, "id");
bool isTarget = getAttribBool(XMLNode, "isTarget");

XmlElement pElement;

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

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

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

// Process lookTarget (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("lookTarget");
if (pElement != null)
processLookTarget(pElement, pNode);

// Process trackTarget (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("trackTarget");
if (pElement != null)
processTrackTarget(pElement, pNode);

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

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

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

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

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

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

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

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

protected void processLookTarget(XmlElement XMLNode, SceneNode pParent)
{

}

protected void processTrackTarget(XmlElement XMLNode, SceneNode pParent)
{

}

protected void processEntity(XmlElement XMLNode, SceneNode pParent)
{
// Process attributes
String name = getAttrib(XMLNode, "name");
String id = getAttrib(XMLNode, "id");
String meshFile = getAttrib(XMLNode, "meshFile");
String materialFile = getAttrib(XMLNode, "materialFile");
bool isStatic = getAttribBool(XMLNode, "static", false);;
bool castShadows = getAttribBool(XMLNode, "castShadows", true);

// TEMP: Maintain a list of static and dynamic objects
if(isStatic)
staticObjects.Add(name);
else
dynamicObjects.Add(name);

XmlElement pElement;

// Process vertexBuffer (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("vertexBuffer");
if(pElement != null)
;//processVertexBuffer(pElement);

// Process indexBuffer (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("indexBuffer");
if (pElement != null)
;//processIndexBuffer(pElement);

// 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(name, meshFile);
pEntity.CastShadows = castShadows;
pParent.AttachObject(pEntity);

if(materialFile.Length != 0)
pEntity.SetMaterialName(materialFile);
}
catch(Exception e)
{
LogManager.Singleton.LogMessage("[DotSceneLoader] Error loading an entity!"+e.Message);
}

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

protected void processParticleSystem(XmlElement XMLNode, SceneNode pParent)
{
// Process attributes
String name = getAttrib(XMLNode, "name");
String id = getAttrib(XMLNode, "id");
String file = getAttrib(XMLNode, "file");

// Create the particle system
try
{
ParticleSystem pParticles = mSceneMgr.CreateParticleSystem(name, file);
pParent.AttachObject(pParticles);
}
catch(Exception e)
{
LogManager.Singleton.LogMessage("[DotSceneLoader] Error creating a particle system!"+e.Message);
}
}

protected void processBillboardSet(XmlElement XMLNode, SceneNode pParent)
{

}

protected void processPlane(XmlElement XMLNode, SceneNode pParent)
{

}

protected void processFog(XmlElement XMLNode)
{
// Process attributes
float expDensity = getAttribReal(XMLNode, "expDensity", 0.001f);
float linearStart = getAttribReal(XMLNode, "linearStart", 0.0f);
float linearEnd = getAttribReal(XMLNode, "linearEnd", 1.0f);

FogMode mode = FogMode.FOG_NONE;
String sMode = getAttrib(XMLNode, "mode");
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, expDensity, linearStart, linearEnd);
}

protected void processSkyBox(XmlElement XMLNode)
{
// Process attributes
String material = getAttrib(XMLNode, "material");
float distance = getAttribReal(XMLNode, "distance", 5000);
bool drawFirst = getAttribBool(XMLNode, "drawFirst", true);

XmlElement pElement;

// Process rotation (?)
Quaternion rotation = Quaternion.IDENTITY;
pElement = (XmlElement)XMLNode.SelectSingleNode("rotation");
if(pElement != null)
rotation = parseQuaternion(pElement);

// Setup the sky box
mSceneMgr.SetSkyBox(true, material, distance, drawFirst, rotation, m_sGroupName);
}

protected void processSkyDome(XmlElement XMLNode)
{
// Process attributes
String material = XMLNode.GetAttribute("material");
float curvature = getAttribReal(XMLNode, "curvature", 10);
float tiling = getAttribReal(XMLNode, "tiling", 8);
float distance = getAttribReal(XMLNode, "distance", 4000);
bool drawFirst = getAttribBool(XMLNode, "drawFirst", true);

XmlElement pElement;

// Process rotation (?)
Quaternion rotation = Quaternion.IDENTITY;
pElement = (XmlElement)XMLNode.SelectSingleNode("rotation");
if (pElement != null)
rotation = parseQuaternion(pElement);

// Setup the sky dome
mSceneMgr.SetSkyDome(true, material, curvature, tiling, distance, drawFirst, rotation, 16, 16, -1, m_sGroupName);
}

protected void processSkyPlane(XmlElement XMLNode)
{
// Process attributes
String material = getAttrib(XMLNode, "material");
float planeX = getAttribReal(XMLNode, "planeX", 0);
float planeY = getAttribReal(XMLNode, "planeY", -1);
float planeZ = getAttribReal(XMLNode, "planeX", 0);
float planeD = getAttribReal(XMLNode, "planeD", 5000);
float scale = getAttribReal(XMLNode, "scale", 1000);
float bow = getAttribReal(XMLNode, "bow", 0);
float tiling = getAttribReal(XMLNode, "tiling", 10);
bool drawFirst = getAttribBool(XMLNode, "drawFirst", true);

// Setup the sky plane
Plane plane = new Plane();
plane.normal = new Vector3(planeX, planeY, planeZ);
plane.d = planeD;
mSceneMgr.SetSkyPlane(true, plane, material, scale, tiling, drawFirst, bow, 1, 1, m_sGroupName);
}

protected void processClipping(XmlElement XMLNode)
{
//! @todo Implement this

// Process attributes
float fNear = getAttribReal(XMLNode, "near", 0);
float fFar = getAttribReal(XMLNode, "far", 1);
}

protected void processLightRange(XmlElement XMLNode, 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 processLightAttenuation(XmlElement XMLNode, 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 String getAttrib(XmlElement XMLNode, String attrib)
{
return getAttrib(XMLNode, attrib, "");
}

protected String getAttrib(XmlElement XMLNode, String attrib, String defaultValue)
{
if (XMLNode.GetAttribute(attrib) != null)
return XMLNode.GetAttribute(attrib);
else
return defaultValue;
}

protected float getAttribReal(XmlElement XMLNode, String parameter)
{
return getAttribReal(XMLNode, parameter, 0.0f);
}

protected float getAttribReal(XmlElement XMLNode, String attrib, float defaultValue)
{
if(XMLNode.GetAttribute(attrib) != null)
return ParseFloat(XMLNode.GetAttribute(attrib));
else
return defaultValue;
}

protected bool getAttribBool(XmlElement XMLNode, String parameter)
{
return getAttribBool(XMLNode, parameter, false);
}

protected bool getAttribBool(XmlElement XMLNode, String attrib, bool defaultValue)
{
if (XMLNode.GetAttribute(attrib) == null)
return defaultValue;

if (XMLNode.GetAttribute(attrib) == "true")
return true;

return false;
}

protected Vector3 parseVector3(XmlElement XMLNode)
{

return new Vector3(
ParseFloat(XMLNode.GetAttribute("x")),
ParseFloat(XMLNode.GetAttribute("y")),
ParseFloat(XMLNode.GetAttribute("z"))
);
}

protected float ParseFloat(String s)
{
NumberFormatInfo provider = new NumberFormatInfo();
provider.NumberDecimalSeparator = ".";
return float.Parse(s, provider);
}

protected Quaternion parseQuaternion(XmlElement XMLNode)
{
//! @todo Fix this shit!

Quaternion orientation = new Quaternion();

if(XMLNode.GetAttribute("qx") != null)
{
orientation.x = ParseFloat(XMLNode.GetAttribute("qx"));
orientation.y = ParseFloat(XMLNode.GetAttribute("qy"));
orientation.z = ParseFloat(XMLNode.GetAttribute("qz"));
orientation.w = ParseFloat(XMLNode.GetAttribute("qw"));
}
else if (XMLNode.GetAttribute("axisX") != null)
{
Vector3 axis;
axis.x = ParseFloat(XMLNode.GetAttribute("axisX"));
axis.y = ParseFloat(XMLNode.GetAttribute("axisY"));
axis.z = ParseFloat(XMLNode.GetAttribute("axisZ"));
float angle = float.Parse(XMLNode.GetAttribute("angle"));
orientation = new Quaternion(angle, axis);
}
else if (XMLNode.GetAttribute("angleX") != null)
{
Vector3 axis;
axis.x = ParseFloat(XMLNode.GetAttribute("angleX"));
axis.y = ParseFloat(XMLNode.GetAttribute("angleY"));
axis.z = ParseFloat(XMLNode.GetAttribute("angleZ"));
//orientation.FromAxes(&axis);
//orientation.F
}

return orientation;
}

protected ColourValue parseColour(XmlElement XMLNode)
{
return new ColourValue(
ParseFloat(XMLNode.GetAttribute("r")),
ParseFloat(XMLNode.GetAttribute("g")),
ParseFloat(XMLNode.GetAttribute("b")),
XMLNode.GetAttribute("a") != null ? ParseFloat(XMLNode.GetAttribute("a")) : 1
);
}

protected SceneManager mSceneMgr;
protected SceneNode mAttachNode;
protected String m_sGroupName;
protected String m_sPrependNode;
}
}

smernesto

26-04-2007 23:39:52

Great, Maybe we can test it and later upload it to the wiki.

I think we can use the C# conventions, Begin Class and Methods with a Upper-case letter.

And maybe use .Net exceptions.

iso8859-1

04-04-2008 13:30:39

I have some questions about this loader (I used the version from the wiki).

First - there is a bug in parsing the lights. The line should be

XMLNode.GetAttribute("a") != "" ? ParseFloat(XMLNode.GetAttribute("a")) : 1); since GetAttribute seems to return an empty string instead of a null reference.

Second - if I try to load a scene, the screen remains black, but the scenemanager roote node shows the correct amount of children. What are possible reasons? I set the camera manually since it is not parsed (yet) and there are enough lights.

Third - what is the groupName parameter in the parseDotScene function

ProfesorX

04-04-2008 18:46:35

Third - what is the groupName parameter in the parseDotScene function

Is the name of the Resource Group you want to load/open.

Beauty

24-09-2008 02:11:14

In the original C++ code of New DotScene Loader was an update at 2007-08-19. This is not integrated to this Mogre code.

If BenJ or somebody else made an update of the Mogre port, please update the wiki page.
www.ogre3d.org/wiki/index.php/MOGRE_dotSceneLoader

Beauty

24-09-2008 02:24:00

I copied a part of the introduction from original C++ page.
Can somebody add a short description for what this class is useful?
If I understood right: with this class you can load scenes from Blender format. But I'm not shure.

smiley80

15-11-2008 20:48:00

I've updated the DotScene Loader so that it loads the output of the latest Blender export script correctly:
dotSceneLoader.zip

Because of my changes DotScene files produced by other programs might not be loaded properly.

Beauty

16-11-2008 05:06:27

Nice that you give us your update :)
Is this update equal to the update of 2007-08-19 in wiki page New DotScene Loader or did you do it independent from it?

smiley80

16-11-2008 13:23:42

Not exactly.

I've added the camera import code.
But removed the parts which are not used by the Blender exporter at the moment.

hedphelym

14-12-2008 18:01:52

Hi,

I've got this one to compile, and added it as an reference,
but i do not know exactly how to use this one.

Sorry for my basic question, but i think it would be great to have a simple "how to use" in the Wiki also. To let people like me understand how to get started with it :)

Beauty

15-12-2008 12:00:14


First - there is a bug in parsing the lights. The line should be

XMLNode.GetAttribute("a") != "" ? ParseFloat(XMLNode.GetAttribute("a")) : 1);
since GetAttribute seems to return an empty string instead of a null reference.

Here in the forum the line is:
XMLNode.GetAttribute("a") != null ? ParseFloat(XMLNode.GetAttribute("a")) : 1

In the wiki it's:
XMLNode.GetAttribute("a") != string.Empty ? ParseFloat(XMLNode.GetAttribute("a")) : 1

Which of the 3 possibilities we should choose?


By the way - I compared the code.
Independent to the line above the code of here (first post) is equal to that one in the wiki.

Maybe we should update the code in the wiki by that one of smiley80 (Posted: Sat 15 Nov 2008) ?
www.ogre3d.org/wiki/index.php/MOGRE_dotSceneLoader

smiley80

15-12-2008 12:46:31


Which of the 3 possibilities we should choose?


XmlElement.GetAttribute never returns null.

so:
!= string.Empty
!= ""
or
!string.IsNullOrEmpty

hedphelym

26-12-2008 11:45:47

Is this one working now?
Can some of you please post a quick reply on how to get this one to work?

thank you.

smiley80

26-12-2008 19:30:12

Assuming you have already exported the scene and all meshes from Blender.


Helper.DotSceneLoader dsl = new Helper.DotSceneLoader();
SceneNode roomNode = sceneMgr.RootSceneNode.CreateChildSceneNode(new Vector3(0, 0, 0));
dsl.ParseDotScene("room1.scene", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, sceneMgr, roomNode);


"room1.scene" is the name of the dotscene file.
"ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME" is the name of the group the dotscene file and the meshes are loaded in.
"sceneMgr" is your SceneManager.
"roomNode" is the SceneNode your scene gets attended to.

hedphelym

26-12-2008 20:28:09

hmm, I must be missing something..

I've started a new project (DLL),
then i reference the project into my mogre project.

I then have this code in the Mogre project:
No errors on compiling, no missing files,
but the scene does just turn out black..

Any help is greatly appreciated.


using System;
using System.Collections.Generic;
using System.Windows.Forms;
using MogreFramework;
using Mogre;

namespace Tutorial02
{
static class Program
{
[STAThread]
static void Main()
{
try
{
MyOgreWindow win = new MyOgreWindow();
new SceneCreator(win);

win.Go();
}
catch (System.Runtime.InteropServices.SEHException)
{
if (OgreException.IsThrown)
MessageBox.Show(OgreException.LastException.FullDescription, "An Ogre exception has occurred!");
else
throw;

}
}
}

class MyOgreWindow : OgreWindow
{
}

class SceneCreator
{
public SceneCreator(OgreWindow win)
{
win.SceneCreating += new OgreWindow.SceneEventHandler(SceneCreating);
}

void SceneCreating(OgreWindow win)
{

SceneManager mgr = win.SceneManager;

USaga.DotSceneLoader dsl = new USaga.DotSceneLoader();
SceneNode roomNode = mgr.RootSceneNode.CreateChildSceneNode(new Vector3(0, 0, 0));
//DotSceneLoader.ParseDotScene("room1.scene", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, mgr, roomNode);
//DotSceneLoader.parseDotScene("D:\\mogre workfolder\\Exported scenes\\test scene\\test.scene", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, mgr, roomNode);
dsl.parseDotScene("D:\\mogre workfolder\\Exported scenes\\test scene\\test.scene", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, mgr, roomNode);
win.Camera.SetPosition(1000, 1000, 1000);

win.Camera.LookAt(new Vector3(0,0,0));
Light light;
light = mgr.CreateLight("Light1");
light.Type = Light.LightTypes.LT_POINT;
light.Position = new Vector3(0, 150, 250);


}
}
}


Beauty

27-12-2008 14:28:46

win.Camera.SetPosition(1000, 1000, 1000)
Maybe the camera and light is to far away? (especially for small objects)

hedphelym

27-12-2008 15:10:35

hmm, still same thing.
i tried with "100" "10" and "1".

Should i upload the whole scene with all code in a zip?

Beauty

27-12-2008 16:35:05

I never tried dotScene, but it sounds nice.

In your code is no render loop. Are you shure it's rendering?
For a generally rendering test you can put a simple mesh to the scene (e.g. the ninja of the tutorials). If you can't see it too, than it's not a problem of the loader.

hedphelym

27-12-2008 17:59:20

I started from scratch now,
added the code from this tutorial : http://www.ogre3d.org/wiki/index.php/Mogre_Basic_Tutorial_1_Source
Ninja's shows, and everything is fine.

Then i add the ParseXML code etc, below the "create ninja's".
same problem, it just turns out the be a black screen, without ninja's.

Tried all i can think of, re-exported scene, scaled down\up, same problem..

Beauty

27-12-2008 18:35:48

Maybe someone else can give us a working scene file?
Then you can try this and we know if there is a problem with your scene file or with the loader.

smiley80

27-12-2008 18:37:30

Did you export the meshes?

If yes, check your ogre.log file for exceptions.

hedphelym

27-12-2008 18:46:58

Ofcource i exported the meshes :)
I use the Ogremax Tools to export.

The content in the folder i export to is:

Box01.mesh
test.material
test.scene


I did open the scene with the ogremax scene viewer, it all looks good there,
but not in "my" app.

*EDIT*

Log says:

19:47:40: [DotSceneLoader] Parsing dotScene file with version 1.0, min. Ogre version 1.4, author OgreMax Scene Exporter by Derek Nedelman (www.ogremax.com)
19:47:40: Mesh: Loading Box01.mesh.

smiley80

27-12-2008 18:55:19

So you're using 3ds Max?

I've only tested the loader with scripts exported from Blender.
Could you please upload the scene? (best would be a most complex scene)

hedphelym

27-12-2008 19:03:45

Here is one with two boxes and a plane.
box on top is linked to box at the bottom,
Shadows are enabled.
one animation track is enabled with a 100f animation.

I do not have anything more advanced here right now (I do have tons of scenes at work).

The info for the plugin i use for 3dsmax is here:
http://www.ogremax.com/

Download here:
[attachment=0]test scene.zip[/attachment]

smiley80

28-12-2008 08:48:53

Quick update:
http://ueberlicht.googlepages.com/dotSceneLoader.zip

Rotation and planes should now be imported correctly.
The box meshes are quiet huge, so you have to zoom out a lot or change the scale to see them.

The camera fov seems to be radian in 3ds, in Blender it's degree... :x

hedphelym

28-12-2008 11:00:54

Thank you for the help and effort you put in to it.
It does work now! :)

I can now see my scene ;)


Is it a good idea to "split" the wiki page for this sceneloader?
and make one page for max, and one for Blender.

Because i had no idea what so ever what app it worked in,
i just assumed it worked. since there is a .scene exporter for 3dsmax.

hedphelym

28-12-2008 11:27:25

There is some problems still,
I'll show in these screenshots:

The Scene is here opened in the ogremax viewer (which shows the scene as in max):
[attachment=1]ogremax.jpg[/attachment]


This is how it looks in "my" app:
[attachment=0]mogre.jpg[/attachment]

Beauty

28-12-2008 18:19:54

In the wiki I added the new code and added much description content.
If somebody extend the code, please update it in the wiki.
http://www.ogre3d.org/wiki/index.php/MO ... ceneLoader

Beauty

29-12-2008 18:02:00

I've [...] removed the parts which are not used by the Blender exporter at the moment.
Can you try the old version? Maybe the reason is something removed.
The old version you get here:
http://www.ogre3d.org/wiki/index.php?ti ... ldid=17015

For updates you can look to the current code of C++ New DotScene Loader where more features are implemented.

-----------------------------------------------------------------------------------------------------------

I saw that in the new source code is no version info.
In my eyes this is important. Smiley80, can you add it?

The info of the old code was was:
// this is a port of ==New DotScene Loader== (version: December 2006)
// ported by BenJ
//
// 08-10-09 Fixed GetAttribute comparisons to use string.Empty instead of null by Violet.

smiley80

29-12-2008 19:42:16

Next try:
http://ueberlicht.googlepages.com/DotSceneLoader.zip

The zip contains two files:

-DotSceneLoaderBlender.cs
Imports all the exported stuff from Blender

-DotSceneLoader.cs
The original class from BenJ plus the camera(incomplete for OgreMax users) and plane import code.
Should import the basics. To get all the OgreMax stuff working, somebody has to port their import code (mainly 'OgreMaxScene.cpp') to C#...

Beauty

30-12-2008 19:48:05

I got an idea.
Maybe the objects (Ninja + loaded scene) are inside, but the light falls to a side where it's not visible from the cam view. The cam only look to dark parts of objects.
Try to put more lights to different positions and/or set a negative Z value to the SceneNode of the loaded scene.

Smiley, can you upload a simple dotScene file?
Then hedphelym can check if his simple test program generally works.
(And also I can use it for some first tests with the scene loader)

hedphelym

30-12-2008 22:05:49

first thing to check, i think is to make sure that the x y z is correct in between ogre->3dsmax.
The objects is in the scene, just some of them being out of place.

It might be different from what xyz is in blender..

I can upload scene (i'm not at home at this time, so i cannot upload right now)

hedphelym

01-01-2009 19:13:54

In 3dsmax, when viewed in front viewport.

X = Right
Y = "Into the screen"
Z = Up

^
|
Z
Y X--->

Is it equal in Ogre? If not, does the importer know this and fix it accordingly?

Beauty

01-01-2009 20:21:25

If you look from the camera than
X axis is to right
Y axis it to top
Z axis it into your face
(quick check by right hand rule)

This is common in computer graphics.
Maybe 3ds max is related to reality coordinates with x/y for the plane and z for the height.

smiley80

01-01-2009 21:29:40

In 3dsmax, when viewed in front viewport.

X = Right
Y = "Into the screen"
Z = Up

^
|
Z
Y X--->

Is it equal in Ogre? If not, does the importer know this and fix it accordingly?


It's the same in Blender, but there's an option in the exporter to change it into (x, z, -y).

OgreMax has this option too: http://www.ogremax.com/Documents/OgreMa ... neral.html
It also saves this as an attribute of the root node (upAxis="y" or upAxis="z").

hedphelym

02-01-2009 10:10:13

I'm not able to get the newest code attached above to work..
it all seems fine in the LOG, but I cannot get any objects in the viewport.
tried all kinds of objects and scales.

A sample scene would be nice for debug purposes, any chance that any one of you could upload one that I can open in mine?

smiley80

02-01-2009 10:42:20

http://ueberlicht.googlepages.com/scene.zip
Simple one cube + one lamp scene exported from Blender.
Imports correctly with the Blender loader; the light isn't imported with the other loader.


USaga.DotSceneLoader dsl = new USaga.DotSceneLoader();
roomNode = sceneMgr.RootSceneNode.CreateChildSceneNode(new Vector3(50, -50, -10));
dsl.parseDotScene("scene.scene", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, sceneMgr, roomNode);

this.camera.SetPosition(60, -40, 00);
this.camera.LookAt(50, -50, -10);

hedphelym

02-01-2009 12:22:36

It's all just a black screen here..

I uploaded the whole project here:
http://www.stigatle.net/uploads/source.zip

If it's just me that is doing this stuff wrong, then let me know,

hedphelym

28-01-2009 11:52:57

Still stuck on this..

If anyone of you had time to check my source, then see what's wrong, it would be greatly apprecitated.

Beauty

28-01-2009 13:23:19

Does the MOGRE dotSceneLoader support User Data?
I would like to add a notice to the wiki.

smiley80

28-01-2009 13:54:07


If anyone of you had time to check my source, then see what's wrong, it would be greatly apprecitated.

It seems that the loader code doesn't treat child nodes correctly. I think at the weekend I have time to look into porting the OgreMax importer code...

Does the MOGRE dotSceneLoader support User Data?
I would like to add a notice to the wiki.

The 'standard' loader reads a 'userDataReference' node.
The blender loader reads a 'userData' node and 4 named properties (static, visible, castShadows and renderingDistance).

hedphelym

16-02-2009 12:52:28


If anyone of you had time to check my source, then see what's wrong, it would be greatly apprecitated.

It seems that the loader code doesn't treat child nodes correctly. I think at the weekend I have time to look into porting the OgreMax importer code...

Did you have time to look at this? :)

smiley80

16-02-2009 14:27:10

Yeah, but it will take some additional time to finish it (5 days ).
Edit: Or longer...

smiley80

22-02-2009 03:21:55

...finished. Okay, more than 5 days...

I have only tested it with your test scene, which seems to get imported correctly (you may have to zoom out).
But it might contain some bugs, has lots of ugly code and it doesn't import OgreMax models.

Usage:
Helper.DotSceneLoaderOgreMax dsl = new Helper.DotSceneLoaderOgreMax();
SceneNode roomNode = sceneMgr.RootSceneNode.CreateChildSceneNode(new Vector3(50, -50, -10));
dsl.Load("test.scene", this.window, this.sceneMgr, roomNode, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);

iNuts

11-05-2009 19:35:01

I am using the latest DotSceneLoaderOgreMax to load a scene i exported from 3dsmax, and it works quite good except for the fact that some of the meshes appear white. it looks like they get over exposed, like if they have a huge specular component or something..i just can't figure out what's wrong.
I load the scene in ogremaxviewer, and everything looks ok, i've looked at ogremaxscene code (the class ogremaxviewer uses to load the scene), and couldn't figure out what is being done there that i don't do in my program, so maybe someone could help me out..

i attached a pic (inuts vs ogremax.JPG) showing the scene loaded in ogremaxviewer on the left side (there is an object with some flipped normals, that's ok, and half of the objects are grey, that's also ok), and in my program on the right side..the lighting is completely different, and i don't understand why.
i have created no default light, as i show in the other attachment (inuts_wrong.JPG) , where i reduced light intensity.
here it is clear that there is some kind of problem with those three meshes..

some extra info: all objects except those three meshes were created by me directly in 3dsmax. the 3 strange objects were downloaded from the internet. at first i thought it could be some kind of problem with normals definition or something like that, but as is works well in ogremaxviewer, i guess it's something missing in my code..
does ogremaxviewer process the loaded meshes somehow?

some interesting thing i noticed, is that the lighting in ogremaxviewer seems much more "consistent" and smooth. in my viewer, there are dark objects and bright objects, all mixed up, while in ogremaxviewer they really look like they are being lit by the same light.. if you notice carefully, the "iNuts" text object get lighter from ogremaxviewer to my viewer, while the strange dark box standing in front of the text does the opposit, it gets darker from ogremaxviewer to mine. it really looks as if there is some kind of exposure control, although i don't know if we can mess around with that using mogre =)

i can also add that i have tried marking ogremax exporter to generate tangents, binormais and even edge lists, and none of that resolved my problem..

hedphelym

11-05-2009 19:47:26

Hi,
do they have a material assigned?

iNuts

11-05-2009 21:36:38

of course they have a material assigned...
there are multiple materials assigned to different subentities in each mesh, but i have already tried assigning for example the same grass material i am using on the ground, to each full mesh, and it looks exactly the same. the problema isn't the materials, it's the geometry. i just dont know why. what can make an object appear completly white, when its material has no emissive component, and all the light are amitting a black color?

i shall remind you of the situation:
in this image i activated the skybox, so the objects are not reflecting the environment.
there are 2 point lights, both with diffuse color set do black (rgb 0,0,0)
the material currently assigned to the white objects is the same material that is assigned to the ground
no material has any emissive component

any idea?

Beauty

18-05-2009 14:46:10

Are the material files and the linked picture files in the right directories (resources.cfg) ?
Also look to the ogre.log file. Maybe this tells a helping warning (like material not found).

And you can get some material information of the .xml / .mesh files by using MeshMagick
http://www.ogre3d.org/wiki/index.php/MeshMagick
meshmagick info myObject.mesh
Maybe the OgreXmlConverter shows more information. (Look for the right option to show it.)
http://www.ogre3d.org/wiki/index.php/OgreXmlConverter

mstoyke

25-05-2009 23:17:11

This screenshot reminds me of an effect that I've seen some time ago. I exported a dotscene file and when my game was parsing it there was a problem with localized float parsing for color values. My parser expected "," instead of "." as decimal point, so 0.5 was parsed as 5 which was way too high for a color value range of 0.0 to 1.0. Any value other than 0.0 was clamped to the max. of 1.0, so I had a lot of white objects in front of a black background.

Beauty

26-05-2009 00:01:20

Good idea. Such a problem I had just a few weeks ago.

The solution was to set the english culture.
I don't know how to apply to the whole application, but here is how to do for parsing:

Convert.ToSingle(myValue, new System.Globalization.CultureInfo("en-US"));

or for a better overview (especially for many calls) you can define it before:

System.Globalization.CultureInfo en = new System.Globalization.CultureInfo("en-US");

convertedValue = Convert.ToSingle(myValue, en);


It would be good to add the culture setting to the all converting lines of the Loader library.
Otherwhise people of some countries will get into strange looking troubles.

smiley80

26-05-2009 00:25:32

The loader uses:
float.Parse([...], CultureInfo.InvariantCulture);

InvariantCulture uses points as decimal separators (it's pretty much the same as English).

koirat

04-09-2009 18:11:01

First of all good job with the exporter loader and Mogre version for it.
What i have to say is that it is not parsing xml comments correctly since XmlComment is not of type XmlElement, I have commented whole node <node>.....</node> in my scene.xml file and i got an exception.

I changed processNodes function into following and it kind of solved the problem:


protected void processNodes(XmlElement XMLNode)
{
XmlElement pElement;

// Process node (*)
pElement = (XmlElement)XMLNode.SelectSingleNode("node");
while (pElement != null)
{
processNode(pElement, null);
XmlNode nextNode = pElement.NextSibling;
pElement = nextNode as XmlElement;
while(pElement==null && nextNode!=null)
{
nextNode = nextNode.NextSibling;
pElement = nextNode as XmlElement;
}
}

}


I do not know if this is only Mogre dotSceneLoader specific problem.

hedphelym

06-10-2009 15:02:33

I have the same problem as mentioned earlier, textures does not show, just a white mesh..
(I use ogremax, the new version). and export the maps along with the scene etc.

hedphelym

11-10-2009 16:36:07

Is there anyone here that can confirm that it works with 3dsmax and it's textures?

As you can see in the ogremax window, it works there, but not when it's inside mogre (using .net sceneloader).

nataz

14-10-2009 21:09:30

I can... err can you look into the ogre.log, there should be messages about missing textures or not supported textures, Plus did you initialize the resource groups after scene load? Thats how I do it:

SceneLoader = new oFusionLoader(SceneManager, RenderWindow);
SceneLoader.Initialize(p);
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();
SceneLoader.CreateScene(SceneManager.RootSceneNode);

nataz

14-10-2009 21:11:08

BTW: I updated the class a bit... i got rid of all that try catch blocks, they are not needed and it is a very bad coding style imho:

class oFusionLoader
{
//For culture independent code
private NumberFormatInfo numberFormat = new NumberFormatInfo();

private const int SceneSkyPlane = 1;
private const int SceneSkyBox = 2;
private const int SceneSkyDome = 3;

// Created objects
private List<Camera> mCameras = new List<Camera>();
private List<Light> mLights = new List<Light>();
private List<Entity> mEntities = new List<Entity>();

// Callback interface (Changed to Events)
public delegate void LoadedSceneObjectEventHandler(Object objectCreated, XmlElement xmlElement);
public event LoadedSceneObjectEventHandler OnCameraCreate;
public event LoadedSceneObjectEventHandler OnNodeCreate;
public event LoadedSceneObjectEventHandler OnLightCreate;
public event LoadedSceneObjectEventHandler OnEntityCreate;
//virtual void OnHelperCreated(Ogre::SceneNode* pHelper, XmlElement pHelperDesc) {};
//virtual void OnShapeLoaded(const Ogre::SimpleSpline& spline)
//virtual bool OnStaticGeometryCreated(Ogre::StaticGeometry* pStatic, const NodeList& nodeList)

// Scene manager
private SceneManager mSceneMgr;
private RenderWindow mWindow;

// Scene XML document
private XmlDocument mXMLDoc;

public oFusionLoader(SceneManager pSceneMgr, RenderWindow win)
{
numberFormat.CurrencyDecimalSeparator = ".";
mSceneMgr = pSceneMgr;

if (win != null)
mWindow = win;
else
mWindow = Mogre.Root.Singleton.AutoCreatedWindow;
}

// Init overloads - use either of them
public bool Initialize(string pszXMLFile)
{
LogManager.Singleton.LogMessage("********************************");
LogManager.Singleton.LogMessage("** oScene Loader Lib **");
LogManager.Singleton.LogMessage("********************************");

string msg = "oSceneLoader: Loading '";
msg += pszXMLFile;
msg += "' file";
LogManager.Singleton.LogMessage(msg);

// Create new XML document
mXMLDoc = new XmlDocument();

//DataStreamPtr pStream = ResourceGroupManager.Singleton.OpenResource(pszXMLFile);

//?Tengo Dudas aca
//if (!(pStream.Size() > 0))
//{
// throw new System.IO.InvalidDataException("oSceneLoader: Empty scene file");
//}

string pBuf = File.ReadAllText(pszXMLFile);

//string pBuf = pStream.AsString;
//pStream = null;

try
{
mXMLDoc.LoadXml(pBuf);
}
catch (XmlException ex)
{
mXMLDoc = null;
throw ex;
}


XmlElement locations = (XmlElement)mXMLDoc.DocumentElement.SelectSingleNode("locations");

if (locations != null)
{

//FileInfoListPtr fileInfo = ResourceGroupManager.Singleton.FindResourceFileInfo(ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, pszXMLFile);

//sring strPath = fileInfo[0].archive.Name;

string strPath = new FileInfo(pszXMLFile).DirectoryName;

strPath = StandardisePath(strPath); //In C++ StringUtil::standardisePath

foreach (XmlElement pLocationElem in locations.ChildNodes)
{
// Ogre could cast an exception, in which case we just try to
// continue reading the other location paths
try
{
string pszName = pLocationElem.GetAttribute("path");
string strDir = strPath + pszName;

string grp = Guid.NewGuid().ToString();
ResourceGroupManager.Singleton.AddResourceLocation(strDir, "FileSystem", grp);

}
catch
{
}
}
}



return true;
}

// Declare all resources used in the scene
public void DeclareResources()
{
if (mXMLDoc != null)
{

XmlElement rootElem = mXMLDoc.DocumentElement;

try
{
// Get mesh filename from entities
XmlElement pMeshNode = (XmlElement)rootElem.SelectSingleNode("entities");
if (pMeshNode != null)
{
// Iterate all meshes, creating them.
foreach (XmlElement pMeshElem in pMeshNode.ChildNodes)
{
//Verify the Element is an entity element.
if (pMeshElem.Name != "entity")
continue;

// Declare mesh resource
string pszFileName = pMeshElem.GetAttribute("filename");
ResourceGroupManager.Singleton.DeclareResource(pszFileName, "Mesh");
}
}
}
catch
{
}

}
}

// Create scene, optionally attaching it to a parent node
public bool CreateScene(SceneNode pParent)
{
if (mXMLDoc != null)
{
string msg = "oSceneLoader: Creating scene on '";
msg += pParent != null ? pParent.Name : "Root";
msg += "' node";
LogManager.Singleton.LogMessage(msg);

bool bHandled = false;

XmlElement rootElem = mXMLDoc.DocumentElement;

if (mSceneMgr == null)
{
if (rootElem.SelectSingleNode("sceneManager") != null)
pParent = CreateSceneManager(rootElem, ref bHandled);
else
mSceneMgr = Root.Singleton.CreateSceneManager(SceneType.ST_GENERIC);
}

if (pParent == null)
pParent = mSceneMgr.RootSceneNode.CreateChildSceneNode();

System.Diagnostics.Debug.Assert(pParent != null);

XmlElement list;

try
{
// Entities
list = (XmlElement)rootElem.SelectSingleNode("entities");
if (list != null)
CreateEntities(list, pParent);
}
catch (Exception ex)
{
LogManager.Singleton.LogMessage("Error while loading entities");

throw new Exception("oSceneLoader: Error while loading entities. " + ex.Message);
}

try
{
// lights
list = (XmlElement)rootElem.SelectSingleNode("lights");
if (list != null)
CreateLights(list, pParent);
}
catch (Exception ex)
{
LogManager.Singleton.LogMessage("Error while loading lights");

throw new Exception("oSceneLoader: Error while loading lights. " + ex.Message);

}

if (!bHandled)
{
try
{
// cameras
list = (XmlElement)rootElem.SelectSingleNode("cameras");
if (list != null)
CreateCameras(list, pParent);
}
catch (Exception ex)
{
LogManager.Singleton.LogMessage("Error while loading cameras");

throw new Exception("oSceneLoader: Error while loading cameras. " + ex.Message);
}
}

/*
try {
// helpers
list = rootElem.SelectSingleNode("helpers");
if(list)
createHelpers(list, pParent);
} catch(...)
{
LogManager.Singleton.LogMessage("Error while loading helpers");

OGRE_EXCEPT(Exception::ERR_RT_ASSERTION_FAILED,
"oSceneLoader: Error while loading helpers",
"OSMScene::createScene");
}

try {
// shapes
list = rootElem.SelectSingleNode("shapes");
if(list)
createShapes(list);
} catch(...)
{
LogManager.Singleton.LogMessage("Error while loading shapes");

OGRE_EXCEPT(Exception::ERR_RT_ASSERTION_FAILED,
"oSceneLoader: Error while loading shapes",
"OSMScene::createScene");
}

try {
// External skeletal animation files
list = rootElem.SelectSingleNode("skeletal_animations");
if(list)
{
SkeletonHandles skelHandles;
loadAnimations(list, skelHandles);
}
}catch(...)
{
LogManager.Singleton.LogMessage("Error while loading external animations");

OGRE_EXCEPT(Exception::ERR_RT_ASSERTION_FAILED,
"oSceneLoader: Error while loading external animations",
"OSMScene::createScene");
}
*/

// Set scene properties
SetSceneProperties(rootElem);

// Static Geometry
list = (XmlElement)rootElem.SelectSingleNode("staticGeometry");
if (list != null)
CreateStaticGeometry(list);

LogManager.Singleton.LogMessage("********************************");
LogManager.Singleton.LogMessage("** oSceneLoader: Scene loaded **");
LogManager.Singleton.LogMessage("********************************");

return true;
}

return false;


}

// Get list of cameras in this scene
public List<Camera> CameraList
{
get { return mCameras; }
}

// Get list of lights in this scene
public List<Light> LightList
{
get { return mLights; }
}

// Get list of entities in this scene
public List<Entity> EntityList
{
get { return mEntities; }
}

public SceneManager SceneMgr
{
get { return mSceneMgr; }
}

private SceneNode CreateNode(XmlElement pElem, SceneNode pSceneRoot)
{
SceneNode pNode = null;

// Try to find the parent node
string pszName = pElem.GetAttribute("name");
if (pszName == string.Empty) return null;

// Check if this node has a parent
string pszParent = pElem.GetAttribute("parent");
if (pszParent == string.Empty)
{
// Check if the scene node has already been created by a child
DisableLogManager();

if (mSceneMgr.HasSceneNode(pszName))
pNode = mSceneMgr.GetSceneNode(pszName);
else
pNode = pSceneRoot.CreateChildSceneNode(pszName);

EnableLogManager();

}
else
{
SceneNode pParent = null;
DisableLogManager();

if (mSceneMgr.HasSceneNode(pszParent))
pParent = mSceneMgr.GetSceneNode(pszParent);
else
pParent = pSceneRoot.CreateChildSceneNode(pszParent);

if (mSceneMgr.HasSceneNode(pszName))
{
pNode = mSceneMgr.GetSceneNode(pszName);

// Get old parent (probably scene root)
SceneNode pOldParent = pNode.ParentSceneNode;

// Remove this node
pOldParent.RemoveChild(pNode);

// Insert us as child on the "real" parent
pParent.AddChild(pNode);
}
else
pNode = pParent.CreateChildSceneNode(pszName);
EnableLogManager();
}

// Position
XmlElement posElem = (XmlElement)pElem.SelectSingleNode("position");
if (posElem != null)
{
Vector3 pos = new Vector3();
pos.x = float.Parse(posElem.GetAttribute("x"), numberFormat);
pos.y = float.Parse(posElem.GetAttribute("y"), numberFormat);
pos.z = float.Parse(posElem.GetAttribute("z"), numberFormat);
pNode.Position = pos;
}

// Rotation
XmlElement rotElem = (XmlElement)pElem.SelectSingleNode("rotation");
if (rotElem != null)
{
pNode.SetOrientation(
float.Parse(rotElem.GetAttribute("w"), numberFormat),
float.Parse(rotElem.GetAttribute("x"), numberFormat),
float.Parse(rotElem.GetAttribute("y"), numberFormat),
float.Parse(rotElem.GetAttribute("z"), numberFormat));

}

// Scale
XmlElement scaleElem = (XmlElement)pElem.SelectSingleNode("scale");
if (scaleElem != null)
{
Vector3 scale;
scale.x = float.Parse(scaleElem.GetAttribute("x"), numberFormat);
scale.y = float.Parse(scaleElem.GetAttribute("y"), numberFormat);
scale.z = float.Parse(scaleElem.GetAttribute("z"), numberFormat);
pNode.SetScale(scale);
}

// Notify
if (OnNodeCreate != null)
OnNodeCreate(pNode, pElem);

// Animation
XmlElement animList = (XmlElement)pElem.SelectSingleNode("animations");
if (animList != null)
{
//
foreach (XmlElement animElem in animList.ChildNodes)
{
if (animElem.Name != "animation")
continue;

// Get name of animation
string pszName1 = animElem.GetAttribute("name");

Animation pAnim = null;
DisableLogManager();

if(mSceneMgr.HasAnimation(pszName1))
pAnim = mSceneMgr.GetAnimation(pszName1);
EnableLogManager();

// If this animation has not been created yet, we create it
if (pAnim == null)
{
float fLength = float.Parse(animElem.GetAttribute("length"), numberFormat);
pAnim = mSceneMgr.CreateAnimation(pszName1, fLength);
pAnim.SetInterpolationMode(Animation.InterpolationMode.IM_LINEAR);
}

// Create animation track for this node
NodeAnimationTrack pTrack = pAnim.CreateNodeTrack((ushort)(pAnim.NumNodeTracks + 1), pNode);

// Iterate all keyframes for this node
foreach (XmlElement pKeyframeElem in animElem.ChildNodes)
{
if (pKeyframeElem.Name != "keyframe")
continue;

float fTime = float.Parse(pKeyframeElem.GetAttribute("time"), numberFormat);
TransformKeyFrame pKeyFrame = pTrack.CreateNodeKeyFrame(fTime);

// Position
XmlElement posElem1 = (XmlElement)pKeyframeElem.SelectSingleNode("position");
if (posElem1 != null)
{
Vector3 trans = new Vector3();
trans.x = float.Parse(posElem1.GetAttribute("x"), numberFormat);
trans.y = float.Parse(posElem1.GetAttribute("y"), numberFormat);
trans.z = float.Parse(posElem1.GetAttribute("z"), numberFormat);
pKeyFrame.Translate = trans;
}

// Rotation
XmlElement rotElem1 = (XmlElement)pKeyframeElem.SelectSingleNode("rotation");
if (rotElem1 != null)
{
Quaternion qRot = new Quaternion();
qRot.x = float.Parse(rotElem1.GetAttribute("x"), numberFormat);
qRot.y = float.Parse(rotElem1.GetAttribute("y"), numberFormat);
qRot.z = float.Parse(rotElem1.GetAttribute("z"), numberFormat);
qRot.w = float.Parse(rotElem1.GetAttribute("w"), numberFormat);
pKeyFrame.Rotation = qRot;
}

// Scale
XmlElement scaleElem1 = (XmlElement)pKeyframeElem.SelectSingleNode("scale");
if (scaleElem1 != null)
{
Vector3 scale = new Vector3();
scale.x = float.Parse(scaleElem1.GetAttribute("x"), numberFormat);
scale.y = float.Parse(scaleElem1.GetAttribute("y"), numberFormat);
scale.z = float.Parse(scaleElem1.GetAttribute("z"), numberFormat);
pKeyFrame.Scale = scale;
}
}
}
}

return pNode;
}

// Create SceneManager
private SceneNode CreateSceneManager(XmlElement sceneProp, ref bool bHandled)
{
System.Diagnostics.Debug.Assert(sceneProp != null);

// Scene manager
XmlElement sceneMgrElem = (XmlElement)sceneProp.SelectSingleNode("sceneManager");
int type = int.Parse(sceneMgrElem.GetAttribute("type"));

SceneType sceneType = (SceneType)(1 << (type - 1));
mSceneMgr = Mogre.Root.Singleton.CreateSceneManager(sceneType);
System.Diagnostics.Debug.Assert(mSceneMgr != null);

SceneNode pSceneRoot = mSceneMgr.RootSceneNode.CreateChildSceneNode();
System.Diagnostics.Debug.Assert(pSceneRoot != null);

// Scene shadows
XmlElement shadowsElem = (XmlElement)sceneProp.SelectSingleNode("shadowTechnique");
if (shadowsElem != null)
{
int type1 = int.Parse(shadowsElem.GetAttribute("type"));
ShadowTechnique shadowType = (ShadowTechnique)type1;

mSceneMgr.ShadowTechnique = shadowType;

ushort tex_size = ushort.Parse(shadowsElem.GetAttribute("tex_size"));
ushort tex_count = ushort.Parse(shadowsElem.GetAttribute("tex_count"));

mSceneMgr.SetShadowTextureSettings(tex_size, tex_count);

// Shadow Color
XmlElement colorElem = (XmlElement)shadowsElem.SelectSingleNode("color");
if (colorElem != null)
{
ColourValue color = new ColourValue();
color.r = float.Parse(colorElem.GetAttribute("r"), numberFormat);
color.g = float.Parse(colorElem.GetAttribute("g"), numberFormat);
color.b = float.Parse(colorElem.GetAttribute("b"), numberFormat);

mSceneMgr.ShadowColour = color;
}
}

// Scene fog
XmlElement fogElem = (XmlElement)sceneProp.SelectSingleNode("fogMode");
if (fogElem != null)
{
int type2 = int.Parse(fogElem.GetAttribute("type"));
FogMode mode = (FogMode)type2;

float density = float.Parse(fogElem.GetAttribute("density"), numberFormat);
float linearStart = float.Parse(fogElem.GetAttribute("linearStart"), numberFormat);
float linearEnd = float.Parse(fogElem.GetAttribute("linearEnd"), numberFormat);

ColourValue color = new ColourValue();

// Fog Color
XmlElement colorElem = (XmlElement)fogElem.SelectSingleNode("color");
if (colorElem != null)
{
color.r = float.Parse(colorElem.GetAttribute("r"), numberFormat);
color.g = float.Parse(colorElem.GetAttribute("g"), numberFormat);
color.b = float.Parse(colorElem.GetAttribute("b"), numberFormat);
}

mSceneMgr.SetFog(mode, color, density, linearStart, linearEnd);
}

// World Geometry
string worldGeometry = sceneMgrElem.GetAttribute("worldGeometry");
if (worldGeometry != string.Empty)
{
// Some scene managers need cameras created before the world geometry
try
{
// cameras
XmlElement list = (XmlElement)sceneProp.SelectSingleNode("cameras");
if (list != null)
CreateCameras(list, pSceneRoot);

if (sceneType == SceneType.ST_EXTERIOR_CLOSE)
{

if (mCameras.Count == 0)
{
throw new System.InvalidOperationException("oSceneLoader: Scene dont contain cameras, Terrain Scene Manager needs a camera to initialize");
}

Camera primaryCamera = mCameras[0];

mWindow.GetViewport(0).Camera = primaryCamera;


//mSceneMgr.SetOption("PrimaryCamera", primaryCamera.NativePtr); //unsafe

}

// cameras created, the main scene loader method should not re-parse the list
bHandled = true;
}
catch
{
}

mSceneMgr.SetWorldGeometry(worldGeometry);
}

return pSceneRoot;
}

// Set Scene Properties
private void SetSceneProperties(XmlElement sceneProp)
{
// Ambient light Color
XmlElement colorElem = (XmlElement)sceneProp.SelectSingleNode("lightColor");
if (colorElem != null)
{
ColourValue color = new ColourValue();
color.r = float.Parse(colorElem.GetAttribute("r"), numberFormat);
color.g = float.Parse(colorElem.GetAttribute("g"), numberFormat);
color.b = float.Parse(colorElem.GetAttribute("b"), numberFormat);

mSceneMgr.AmbientLight = color;
}

// Background Color
colorElem = (XmlElement)sceneProp.SelectSingleNode("bkgcolor");
if (colorElem != null && mWindow != null)
{
int numViewports = mWindow.NumViewports;
if (numViewports > 0)
{
ColourValue color = new ColourValue();
color.r = float.Parse(colorElem.GetAttribute("r"), numberFormat);
color.g = float.Parse(colorElem.GetAttribute("g"), numberFormat);
color.b = float.Parse(colorElem.GetAttribute("b"), numberFormat);

for (ushort i = 0; i < numViewports; ++i)
mWindow.GetViewport(i).BackgroundColour = color;
}
}

// Scene sky
XmlElement skyElem = (XmlElement)sceneProp.SelectSingleNode("skyTechnique");
if (skyElem != null)
{
int type = int.Parse(skyElem.GetAttribute("type"));
string materialName = skyElem.GetAttribute("material");

if (materialName != " ")
{
string drawFirstAttribute = skyElem.GetAttribute("drawFirst");
bool drawFirst = drawFirstAttribute == "yes";
float tiling = float.Parse(skyElem.GetAttribute("tiling"), numberFormat);
float scale = float.Parse(skyElem.GetAttribute("scale"), numberFormat);
float dist = float.Parse(skyElem.GetAttribute("dist"), numberFormat);
float bow = float.Parse(skyElem.GetAttribute("bow"), numberFormat);
int xSegments = int.Parse(skyElem.GetAttribute("xSegments"));
int ySegments = int.Parse(skyElem.GetAttribute("ySegments"));
Quaternion quat = Quaternion.IDENTITY;
Plane plane = new Plane();
plane.d = dist;
plane.normal = -(Vector3.UNIT_Y);

switch (type)
{

case SceneSkyPlane:

mSceneMgr.SetSkyPlane(true, plane, materialName, scale,
tiling, drawFirst, bow, xSegments, ySegments);

mSceneMgr.SetSkyBox(false, "");
mSceneMgr.SetSkyDome(false, "");

break;

case SceneSkyBox:

mSceneMgr.SetSkyBox(true, materialName, dist, drawFirst, quat);
mSceneMgr.SetSkyPlane(false, plane, "");
mSceneMgr.SetSkyDome(false, "");

break;

case SceneSkyDome:

mSceneMgr.SetSkyDome(true, materialName, bow, tiling, dist,
drawFirst, quat, xSegments, ySegments);

mSceneMgr.SetSkyPlane(false, plane, "");
mSceneMgr.SetSkyBox(false, "");

break;

}
}
}
}

// Create all entities in scene
private void CreateEntities(XmlElement pEntityNode, SceneNode pSceneRoot)
{
// Iterate all meshes, creating them.
foreach (XmlElement pMeshElem in pEntityNode.ChildNodes)
{
if (pMeshElem.Name != "entity")
continue;

// Ogre could cast an exception, in which case we just try to
// continue reading the other meshes
try
{
string pszName = pMeshElem.GetAttribute("name");
string pszFileName = pMeshElem.GetAttribute("filename");
/* try
{

if (mSceneMgr.GetEntity(pszName) != null)
mSceneMgr.DestroyEntity(mSceneMgr.GetEntity(pszName));
}
catch { }*/
// try to create the mesh
Entity pEntity;
try
{
pEntity = mSceneMgr.CreateEntity(pszName, pszFileName);
}
catch
{
continue;
}
if (pEntity == null) continue;

// Check if the object should cast shadows
string pszCastShadows = pMeshElem.GetAttribute("CastShadows");
if (pszCastShadows == "no")
pEntity.CastShadows = false;
else
pEntity.CastShadows = true;

// Create node with full information
SceneNode pObjNode = CreateNode(pMeshElem, pSceneRoot);

// Attach the mesh entity to node
pObjNode.AttachObject(pEntity);

// Notify
if (OnEntityCreate != null)
OnEntityCreate(pEntity, pMeshElem);

// Add to entity list
mEntities.Add(pEntity);
}
catch
{
continue;
}
}
}

// Create all Lights in scene
private void CreateLights(XmlElement pLightNode, SceneNode pSceneRoot)
{
// Iterate all Lights, creating them. We do not attach them yet, since
// we need to make sure all potential parent entities have been created.
foreach (XmlElement pLightElem in pLightNode.ChildNodes)
{
if (pLightElem.Name != "light")
continue;

// Ogre could cast an exception, in which case we just try to
// continue reading the other Lights
try
{
string pszName = pLightElem.GetAttribute("name");

Light pLight = mSceneMgr.CreateLight(pszName);
if (pLight == null) continue;

// Figure out which type of light we are using
string pszType = pLightElem.GetAttribute("type");
if (pszType == "omni")
{
pLight.Type = Light.LightTypes.LT_POINT;
}
else if (pszType == "spot")
{
pLight.Type = Light.LightTypes.LT_SPOTLIGHT;
pLight.SetSpotlightRange(
new Radian(new Degree(float.Parse(pLightElem.GetAttribute("hotspot"), numberFormat))),
new Radian(new Degree(float.Parse(pLightElem.GetAttribute("falloff"), numberFormat))));
pLight.SetDirection(0f, 0f, -1f);

}
else if (pszType == "directional")
{
pLight.Type = Light.LightTypes.LT_DIRECTIONAL;
}

// Check if the light should be on
string pszOn = pLightElem.GetAttribute("on");
if (pszOn == "true")
pLight.Visible = true;
else
pLight.Visible = false;

// Check if the object should cast shadows
string pszCastShadows = pLightElem.GetAttribute("CastShadows");
if (pszCastShadows == "no")
pLight.CastShadows = false;
else
pLight.CastShadows = true;

// Diffuse Color
XmlElement colorElem = (XmlElement)pLightElem.SelectSingleNode("color");
if (colorElem != null)
{
pLight.DiffuseColour = new ColourValue(
float.Parse(colorElem.GetAttribute("r"), numberFormat),
float.Parse(colorElem.GetAttribute("g"), numberFormat),
float.Parse(colorElem.GetAttribute("b"), numberFormat));
}

// Specular Color
XmlElement specularElem = (XmlElement)pLightElem.SelectSingleNode("specular");
if (specularElem != null)
{
pLight.SpecularColour = new ColourValue(
float.Parse(specularElem.GetAttribute("r"), numberFormat),
float.Parse(specularElem.GetAttribute("g"), numberFormat),
float.Parse(specularElem.GetAttribute("b"), numberFormat));
}

// Attenuation
XmlElement attenElem = (XmlElement)pLightElem.SelectSingleNode("attenuation");
if (attenElem != null)
{
pLight.SetAttenuation(
float.Parse(attenElem.GetAttribute("range"), numberFormat),
float.Parse(attenElem.GetAttribute("constant"), numberFormat),
float.Parse(attenElem.GetAttribute("linear"), numberFormat),
float.Parse(attenElem.GetAttribute("quadratic"), numberFormat));
}

// Create node with full information
SceneNode pLightNode1 = CreateNode(pLightElem, pSceneRoot);

// Attach the Light entity to node
pLightNode1.AttachObject(pLight);

// Target
XmlElement targetElem = (XmlElement)pLightElem.SelectSingleNode("target");
if (targetElem != null)
{
// Create node with full information
SceneNode pTargetNode = CreateNode(targetElem, pSceneRoot);
pLightNode1.SetAutoTracking(true, pTargetNode);
}

// Notify
if (OnLightCreate != null)
OnLightCreate(pLight, pLightElem);

// Add to light list
mLights.Add(pLight);
}
catch
{
continue;
}
}
}

// Create all Cameras in scene
private void CreateCameras(XmlElement pCameraNode, SceneNode pSceneRoot)
{
// Iterate all Cameras, creating them. We do not attach them yet, since
// we need to make sure all potential parent entities have been created.
foreach (XmlElement pCameraElem in pCameraNode.ChildNodes)
{
if (pCameraElem.Name != "camera")
continue;

// Ogre could cast an exception, in which case we just try to
// continue reading the other Cameras
try
{
string pszName = pCameraElem.GetAttribute("name");

// Create camera
Camera pCamera = mSceneMgr.CreateCamera(pszName);
if (pCamera == null) continue;

// Set Field of View on camera
pCamera.FOVy = new Radian(float.Parse(pCameraElem.GetAttribute("FOV"), numberFormat));
pCamera.NearClipDistance = 5f;
pCamera.FarClipDistance = 1000f;
// Create node with full information
SceneNode pCameraNode1 = CreateNode(pCameraElem, pSceneRoot);

// Attach the Camera entity to node
pCameraNode1.AttachObject(pCamera);
// pCameraNode1.ParentSceneNode = pCameraNode1;
// Target
XmlElement targetElem = (XmlElement)pCameraElem.SelectSingleNode("target");
if (targetElem != null)
{
// Create node with full information
SceneNode pTargetNode = CreateNode(targetElem, pSceneRoot);
// pCameraNode1.SetAutoTracking(true, pTargetNode);
}

if (mWindow == null)
{
throw new InvalidOperationException("oSceneLoader: RenderWindow not valid, If the RenderWindow was not auto created you must add it in the OSMScene object contructor");
}

// If viewport(s) are not present, create a default viewport
if (mWindow.NumViewports == 0)
{
Viewport vp = mWindow.AddViewport(pCamera);

// Alter the camera aspect ratio to match the viewport
pCamera.AspectRatio = (float)vp.ActualWidth / (float)vp.ActualHeight;
}


// Notify
if (OnCameraCreate != null)
OnCameraCreate(pCamera, pCameraElem);

// Add to camera list
mCameras.Add(pCamera);
}
catch
{
continue;
}
}

}

// For CE version, helpers, shapes, static geometry
// and external skeleton animation support is not provided
private void CreateHelpers(XmlElement pHelperNode, SceneNode pSceneRoot)
{

}

private void CreateShapes(XmlElement pShapeNode)
{


}

private void CreateStaticGeometry(XmlElement pStaticGeom)
{

}

//void LoadAnimations(XmlElement animationsNode, SkeletonHandles& handles) {

// Iterate all skeletons, adding animations from ".anim" files
//}

private void EnableLogManager()
{
LogManager.Singleton.SetLogDetail(LoggingLevel.LL_NORMAL);
}
private void DisableLogManager()
{
LogManager.Singleton.SetLogDetail(LoggingLevel.LL_LOW);
}


//This method is used because Mogre doesn´t have a wrapper for the Ogre::StringUtil class
//It was ported from the c++ source of Ogre.
private string StandardisePath(string init)
{
string path = init;

path = path.Replace('\\', '/');
if (path[path.Length - 1] != '/')
path += '/';

return path;
}
}

hedphelym

17-10-2009 16:02:16

Hi again, just wanted to say that it was my own stupid mistake that caused the textures not to show.
I called my "loadscene" function right bfore the "ResourceGroupManager.Singleton.InitialiseAllResourceGroups();".

So everything works great now :)

Vectrex

18-10-2009 04:45:12

BTW: I updated the class a bit... i got rid of all that try catch blocks, they are not needed and it is a very bad coding style imho:

That's the oFusion, not .scene loader? I presume it won't work for .scene?

nataz

20-10-2009 10:21:00

damn you are right...

hedphelym

22-10-2009 14:46:42

Quick Question:
How can one parse the objects "custom\User Defined" data on a object?
Let's say I want to fetch custom data from an object on load.

[Edit]:

ogremax exports it as CData, so the dotsceneloader crashes if you apply "user data" to the object.
And another note is that ogremax does not export the userdata on the 3dsmax objects that you have set through
the standard "object properties" dialog in max, you need to use the Ogremax->object properties , then enter them there.

But as mentioned above, it crashes if you do so on load.

koirat

23-01-2010 18:16:40

There is a spotlight bug/error in the mogre dotsceneloader


protected void processLightRange(XmlElement XMLNode, 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);
}


pLight.SetSpotlightRange(new Radian(inner), new Radian(outer), falloff);
This line consider inner and outer to be in radians, where for example Blender exporter returns this values in degrees.

It gave me one hell of a debugging session to find the bug. I change the code to:

pLight.SetSpotlightRange(new Radian((Degree)inner), new Radian((Degree)outer), falloff);


Anybody got an access to wiki ?
I can change it if you tell me how, and previous thing that I have mentioned (bug with comments).

smiley80

24-01-2010 13:00:33

Well spotted. I've corrected it in the wiki.

You can only log in to the wiki with your main forum account.

kdr35

14-02-2011 12:43:18

Hi,

I am using Mogre and Ogitor to design scene. I designed a scene with Ogitor then export as .scene file. When I load the scene with MOGRE dotSceneLoader , everything(threes, houses etc) are loaded successfully but I dont see terrain. I also asked the problem from Ogitor Forum . What may be relevant to dotScene Loader or Ogitor exported file? I posted below screenshot of sceen to define problem.




Thanks for helps...

Kwang1imsa

05-03-2011 05:22:17

I'm getting an error with:
MeshPtr ptr = MeshManager.Singleton.CreatePlane(name, m_sGroupName, pPlane, width, height, xSegments, ySegments, normals, numTexCoordSets, uTile, vTile, upVector);
Error 13 The best overloaded method match for 'Mogre.MeshManager.CreatePlane(string, string, Mogre.Plane, float, float, int, int, bool, ushort, float, float, Mogre.Vector3)' has some invalid arguments

MrChris

06-03-2011 15:30:38

I found that ther is an issue with the types declared in the process plane function. Here is my modified loader. I also added some functions for processing some of the environment variables such as Skyboxes.




namespace Helper
{
using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.Xml;
using Mogre;

public class DotSceneLoader
{
#region Fields

public List<string> DynamicObjects; //String
public List<string> StaticObjects; //String

protected SceneNode mAttachNode;
protected SceneManager mSceneMgr;
protected String m_sGroupName;
protected String m_sPrependNode;

#endregion Fields

#region Constructors

public DotSceneLoader()
{
}

~DotSceneLoader()
{
}

#endregion Constructors

#region Methods

public void ParseDotScene(String SceneName, String groupName, SceneManager yourSceneMgr)
{
ParseDotScene(SceneName, groupName, yourSceneMgr, null, "");
}

public void ParseDotScene(String SceneName, String groupName, SceneManager yourSceneMgr, SceneNode pAttachNode)
{
ParseDotScene(SceneName, groupName, yourSceneMgr, pAttachNode, "");
}

public void ParseDotScene(String SceneName, String groupName, SceneManager yourSceneMgr, SceneNode pAttachNode, String sPrependNode)
{
// 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;

DataStreamPtr pStream = 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")
{
LogManager.Singleton.LogMessage("[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);
}

protected float ParseFloat(String s)
{
NumberFormatInfo provider = new NumberFormatInfo();
provider.NumberDecimalSeparator = ".";
return float.Parse(s, provider);
}

protected String getAttrib(XmlElement XMLNode, String attrib)
{
return getAttrib(XMLNode, attrib, "");
}

protected String getAttrib(XmlElement XMLNode, String attrib, String defaultValue)
{
if (!string.IsNullOrEmpty(XMLNode.GetAttribute(attrib)))
return XMLNode.GetAttribute(attrib);
else
return defaultValue;
}

protected bool getAttribBool(XmlElement XMLNode, String parameter)
{
return getAttribBool(XMLNode, parameter, false);
}

protected bool getAttribBool(XmlElement XMLNode, String attrib, bool defaultValue)
{
if (string.IsNullOrEmpty(XMLNode.GetAttribute(attrib)))
return defaultValue;

if (XMLNode.GetAttribute(attrib) == "true")
return true;

return false;
}

protected float getAttribReal(XmlElement XMLNode, String parameter)
{
return getAttribReal(XMLNode, parameter, 0.0f);
}

protected float getAttribReal(XmlElement XMLNode, String attrib, float defaultValue)
{
if (!string.IsNullOrEmpty(XMLNode.GetAttribute(attrib)))
return ParseFloat(XMLNode.GetAttribute(attrib));
else
return defaultValue;
}

protected ColourValue parseColour(XmlElement XMLNode)
{
return new ColourValue(
ParseFloat(XMLNode.GetAttribute("r")),
ParseFloat(XMLNode.GetAttribute("g")),
ParseFloat(XMLNode.GetAttribute("b")),
string.IsNullOrEmpty(XMLNode.GetAttribute("a")) == false ? ParseFloat(XMLNode.GetAttribute("a")) : 1
);
}

protected Quaternion parseQuaternion(XmlElement XMLNode)
{
Quaternion orientation = new Quaternion();

orientation.x = ParseFloat(XMLNode.GetAttribute("x"));
orientation.y = ParseFloat(XMLNode.GetAttribute("y"));
orientation.z = ParseFloat(XMLNode.GetAttribute("z"));
orientation.w = ParseFloat(XMLNode.GetAttribute("w"));

return orientation;
}

protected Quaternion parseRotation(XmlElement XMLNode)
{
Quaternion orientation = new Quaternion();

orientation.x = ParseFloat(XMLNode.GetAttribute("qx"));
orientation.y = ParseFloat(XMLNode.GetAttribute("qy"));
orientation.z = ParseFloat(XMLNode.GetAttribute("qz"));
orientation.w = ParseFloat(XMLNode.GetAttribute("qw"));

return orientation;
}

protected Vector3 parseVector3(XmlElement XMLNode)
{
return new Vector3(
ParseFloat(XMLNode.GetAttribute("x")),
ParseFloat(XMLNode.GetAttribute("y")),
ParseFloat(XMLNode.GetAttribute("z"))
);
}

protected void processCamera(XmlElement XMLNode, SceneNode pParent)
{
// Process attributes
String name = getAttrib(XMLNode, "name");



// Create the camera
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 Lookat (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("lookat");
if (pElement != null)
{
pCamera.LookAt (parseVector3(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;
}
}

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(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)
{
LogManager.Singleton.LogMessage("[DotSceneLoader] Error loading an entity!" + e.Message);
}


}

protected void processEnvironment(XmlElement XMLNode)
{
XmlElement pElement;

// Process fog (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("fog");
if (pElement != null)
processFog(pElement);

// Process colourAmbient (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("colourAmbient");
if (pElement != null)
mSceneMgr.AmbientLight = parseColour(pElement);

// Process skyBox (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("skyBox");
if (pElement != null)
processSkyBox(pElement);

// Process skyDome (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("skyDome");
if (pElement != null)
processSkyDome(pElement);

// Process skyPlane (?)
pElement = (XmlElement)XMLNode.SelectSingleNode("skyPlane");
if (pElement != null)
processSkyPlane(pElement);



// Process colourBackground (?)
//! @todo Set the background colour of all viewports (RenderWindow has to be provided then)
// pElement = (XmlElement)XMLNode.SelectSingleNode("colourBackground");
// if (pElement != null)
// ;//mSceneMgr->set(parseColour(pElement));

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


protected void processSkyBox(XmlElement XMLNode)
{
// Process attributes
String material = getAttrib(XMLNode, "material", "BaseWhite");
float distance = getAttribReal(XMLNode, "distance", 6000);
bool drawFirst = getAttribBool(XMLNode, "drawFirst", true);
bool active = getAttribBool(XMLNode, "active", true);
if(!active)
return;

XmlElement pElement;

// Process rotation (?)
Quaternion rotation = Quaternion.IDENTITY;
pElement = (XmlElement)XMLNode.SelectSingleNode("rotation");
if(pElement !=null)
rotation = parseRotation(pElement);

// Setup the sky box
mSceneMgr.SetSkyBox(true, material, distance, drawFirst, rotation, m_sGroupName);
}

protected void processSkyDome(XmlElement XMLNode)
{
// Process attributes
String material = getAttrib(XMLNode, "material", "BaseWhite");
float curvature = getAttribReal(XMLNode, "curvature", 10);
float tiling = getAttribReal(XMLNode, "tiling", 1);
float distance = getAttribReal(XMLNode, "distance", 4000);
bool drawFirst = getAttribBool(XMLNode, "drawFirst", true);
bool active = getAttribBool(XMLNode, "active", true);
if(!active)
return;

XmlElement pElement;

// Process rotation (?)
Quaternion rotation = Quaternion.IDENTITY;
pElement = (XmlElement)XMLNode.SelectSingleNode("rotation");
if (pElement != null)
rotation = parseRotation(pElement);

// Setup the sky dome
mSceneMgr.SetSkyDome(true, material, curvature, tiling, distance, drawFirst, rotation, 16, 16, -1, m_sGroupName);
}

protected void processSkyPlane(XmlElement XMLNode)
{
// Process attributes
String material = getAttrib(XMLNode, "material");
float planeX = getAttribReal(XMLNode, "planeX", 0);
float planeY = getAttribReal(XMLNode, "planeY", -1);
float planeZ = getAttribReal(XMLNode, "planeX", 0);
float planeD = getAttribReal(XMLNode, "planeD", 5000);
float scale = getAttribReal(XMLNode, "scale", 1000);
float bow = getAttribReal(XMLNode, "bow", 0);
float tiling = getAttribReal(XMLNode, "tiling", 10);
bool drawFirst = getAttribBool(XMLNode, "drawFirst", true);

// Setup the sky plane
Plane plane;
plane.normal =new Vector3(planeX, planeY, planeZ);
plane.d = planeD;
mSceneMgr.SetSkyPlane(true, plane, material, scale, tiling, drawFirst, bow, 1, 1, m_sGroupName);
}



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);
}





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, 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, 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((Degree)inner), new Radian((Degree)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.SetScale(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;
}
}

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");
ushort numTexCoordSets = (ushort)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");

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

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

Plane pPlane = new Plane(normal, upVector);

Entity pEntity= null;
try
{
//MeshPtr ptr = MeshManager.Singleton.CreatePlane(name, m_sGroupName, pPlane, width, height, xSegments, ySegments, normals, numTexCoordSets, uTile, vTile, upVector);
MeshPtr ptr = 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)
{
LogManager.Singleton.LogMessage("[DotSceneLoader] Error loading an entity!" + e.Message);
}

}

protected void processNodes(XmlElement XMLNode)
{
XmlElement pElement;

// Process node (*)
pElement = (XmlElement)XMLNode.SelectSingleNode("node");
while (pElement != null)
{
processNode(pElement, null);
XmlNode nextNode = pElement.NextSibling;
pElement = nextNode as XmlElement;
while(pElement==null && nextNode!=null)
{
nextNode = nextNode.NextSibling;
pElement = nextNode as XmlElement;
}
}
}

protected void processScene(XmlElement XMLRoot)
{
// Process the scene parameters
String version = getAttrib(XMLRoot, "formatVersion", "unknown");

String message = "[DotSceneLoader] Parsing dotScene file with version " + version;

LogManager.Singleton.LogMessage(message);

XmlElement pElement;

// Process nodes (?)
pElement = (XmlElement)XMLRoot.SelectSingleNode("nodes");
if (pElement != null)
processNodes(pElement);


// Process terrain (?)
pElement = (XmlElement)XMLRoot.SelectSingleNode("terrain");
if (pElement != null)
{

mSceneMgr.SetWorldGeometry("terrain.cfg");
//processNodes(pElement);

}



// Process environment (?)
pElement = (XmlElement)XMLRoot.SelectSingleNode("environment");
if (pElement != null)
processEnvironment(pElement);
// Process externals (?)
// pElement = (XmlElement)XMLRoot.SelectSingleNode("externals");
// if (pElement != null)
// processExternals(pElement);
}

protected void processUserDataReference(XmlElement XMLNode, SceneNode pNode)
{
// TODO
}

#endregion Methods
}
}


Beauty

06-03-2011 19:54:42

Ogitor uses the new Terrain component of Ogre.
For use of this we need an extra wrapper.
User mstoyke started to write a terrain wrapper. Basically it works, but it's still not finished. You can try it out and post a feedback in the forum topic In Development: Mogre Terrain and Paging. If you have problems, post it there, too.

If it doesn't work with the unfinished terrain wrapper, then I'm sorry and hope this issue will be fixed soon.
(Unfortunately it needs deep knowledge of the C++/CLI wrapper techniques and much free time.)

It seems so that the terrain support is important for you.
So it would be fine when you go to the forum topic Feature requests and wish list. There you can vote for several parts of Mogre, which you prefere. Then we know which parts we should focus for the development.

Beauty

06-03-2011 20:03:58

I found that ther is an issue with the types declared in the process plane function. Here is my modified loader. I also added some functions for processing some of the environment variables such as Skyboxes.

Nice to see you here, MrChris.
It seems so that you are a hidden user of Mogre, because this is your first post.
Thanks for sharing the extended dotNet loader. :D

I would like to add it to the wiki.
Did you remove some parts of the previous functionality?
Do you think your modifications can cause a conflict with dotScene files which are generated by other applications?
Did you discover any problems with your loader?
I suppose there is no problem, but at least I want to ask for that before I replace the current code of the wiki.
With which applications you created the dotScene files, which you loaded?

MrChris

07-03-2011 18:00:26

Beauty - Thanks. I have been hanging out reading posts for almost a year and finally had the time to start me project. I have worked out a few things but will be posting a few questions soon :D especially now that I am trying to get Miyagi working.

The changes I made to the loader are untested against anything except the LFA scene manager for export from Maya.

I ported the environment loader portions from the c++ version and these functions referenced processQuaternarion but the LFA scene manager scene file wrote the data so that the processRotation function needed to be called instead.

Beauty

07-03-2011 19:43:44

Ok, good to know.
It seems so that you didn't modify the C# loader(s). Instead you re-ported a C++ loader. (please give me a link)

Did you try the C# loader of the wiki?
What were the disadvantages?
Why did you port the whole C++ loader instead of modifing the C# loader?

You see, I'm interested in details :wink:


Related to Miyagi:
A few weeks ago I added more important links to its wiki page.
I also heard about Miyagi newcomer problems on last weekend. The boy didn't know how to use Miyagi. (By random I met this Mogre user on the big German IT exhibition CeBIT. The real life talk was nice!)
There are some examples on the Miyagi project website.
Also you get good support by the developer in the Miyagi forum topic.

MrChris

08-03-2011 14:43:23

Ok, good to know.
It seems so that you didn't modify the C# loader(s). Instead you re-ported a C++ loader. (please give me a link)

Did you try the C# loader of the wiki?
What were the disadvantages?
Why did you port the whole C++ loader instead of modifing the C# loader?

You see, I'm interested in details :wink:


I am using the loader found here http://www.ogre3d.org/tikiwiki/MOGRE+dotSceneLoader. It needed some work to load the environment variables. It looks like the one posted at the beginning of this thread is more complete but I will continue to use the one I have since I do not mind tweaking things, it helps in the learning curve.

I only referenced the c++ version of the new loader to reference a few things that were missing and see how they were handled.