Added Model component to schema

This commit is contained in:
sippeangelo
2015-12-08 18:21:24 +01:00
parent 9fbea18330
commit 1e1ce4e127
7 changed files with 55 additions and 51 deletions
+9 -51
View File
@@ -21,7 +21,6 @@ private:
{
ComponentWrapperFactory f;
f = ComponentWrapperFactory("Test");
f.AddProperty("TestInteger", 1337);
f.AddProperty("TestFloat", 13.37f);
@@ -31,18 +30,6 @@ private:
f = ComponentWrapperFactory("Debug");
f.AddProperty("Name", std::string("Unnamed"));
RegisterComponent(f);
//f = ComponentWrapperFactory("Transform");
//f.AddProperty("Position", glm::vec3(0.f, 0.f, 0.f));
//f.AddProperty("Orientation", glm::quat());
//f.AddProperty("Scale", glm::vec3(1.f, 1.f, 1.f));
//RegisterComponent(f);
f = ComponentWrapperFactory("Model");
f.AddProperty("Resource", std::string());
f.AddProperty("Color", glm::vec4(1.f, 1.f, 1.f, 1.f));
f.AddProperty("Visible", true);
RegisterComponent(f);
}
void createTestEntities()
@@ -50,56 +37,27 @@ private:
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
ResourceManager::Load<EntityXMLFile>("Schema/Entities/Test.xml")->PopulateWorld(this);
World& world = *this;
// Create an entity
EntityID e = world.CreateEntity();
// Attach a Transform component
world.AttachComponent(e, "Transform");
// Fetch the component based on EntityID and component type
ComponentWrapper transform = world.GetComponent(e, "Transform");
// Set the fields of the Transform component
transform["Position"] = glm::vec3(0.f, 0.f, 0.f);
transform["Scale"] = glm::vec3(1.f, 1.f, 1.f);
// Move on the X axis by fetching field as reference
((glm::vec3&)transform["Position"]).x += 10.f;
// Shrink by a factor of 100
((glm::vec3&)transform["Scale"]) /= 100.f;
// Loop through all Transform components and print them
for (auto& transform : world.GetComponents("Transform")) {
glm::vec3 pos = transform["Position"];
std::cout << "Position: " << pos.x << " " << pos.y << " " << pos.z << std::endl;
glm::vec3 scale = transform["Scale"];
std::cout << "Scale: " << scale.x << " " << scale.y << " " << scale.z << std::endl;
}
//Create some test widgets
{
EntityID entityScaleWidget = world.CreateEntity();
ComponentWrapper transform = world.AttachComponent(entityScaleWidget, "Transform");
EntityID entityScaleWidget = CreateEntity();
ComponentWrapper transform = AttachComponent(entityScaleWidget, "Transform");
transform["Position"] = glm::vec3(-1.5f, 0.f, 0.f);
ComponentWrapper model = world.AttachComponent(entityScaleWidget, "Model");
ComponentWrapper model = AttachComponent(entityScaleWidget, "Model");
model["Resource"] = "Models/ScaleWidget.obj";
}
{
EntityID entityRotationWidget = world.CreateEntity();
ComponentWrapper transform = world.AttachComponent(entityRotationWidget, "Transform");
EntityID entityRotationWidget = CreateEntity();
ComponentWrapper transform = AttachComponent(entityRotationWidget, "Transform");
transform["Position"] = glm::vec3(1.5f, 0.f, 0.f);
ComponentWrapper model = world.AttachComponent(entityRotationWidget, "Model");
ComponentWrapper model = AttachComponent(entityRotationWidget, "Model");
model["Resource"] = "Models/RotationWidget.obj";
}
{
EntityID entityDummyScene = world.CreateEntity();
ComponentWrapper transform = world.AttachComponent(entityDummyScene, "Transform");
EntityID entityDummyScene = CreateEntity();
ComponentWrapper transform = AttachComponent(entityDummyScene, "Transform");
transform["Position"] = glm::vec3(0, 0.f, 0.f);
ComponentWrapper model = world.AttachComponent(entityDummyScene, "Model");
ComponentWrapper model = AttachComponent(entityDummyScene, "Model");
model["Resource"] = "Models/DummyScene.obj";
}
}
};
+1
View File
@@ -2,5 +2,6 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="components" elementFormDefault="qualified">
<xs:include schemaLocation="Components/Transform.xsd"/>
<xs:include schemaLocation="Components/Model.xsd"/>
<xs:include schemaLocation="Components/Test.xsd"/>
</xs:schema>
+5
View File
@@ -0,0 +1,5 @@
<c:Model>
<Resource></Resource>
<Color R="1" G="1" B="1" A="1"/>
<Visible>true</Visible>
</c:Model>
+24
View File
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="Model">
<xs:annotation>
<xs:documentation>A visible model loaded from disk</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="Resource" type="t:string" minOccurs="0">
<xs:annotation><xs:documentation>Model file</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="Color" type="t:Color" minOccurs="0">
<xs:annotation><xs:documentation>Color tint</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="Visible" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Wether the model is visible or not</xs:documentation></xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
+4
View File
@@ -3,6 +3,10 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="types" elementFormDefault="qualified">
<xs:include schemaLocation="Types/Quaternion.xsd"/>
<xs:include schemaLocation="Types/Vector.xsd"/>
<xs:include schemaLocation="Types/Color.xsd"/>
<xs:simpleType name="bool">
<xs:restriction base="xs:boolean"></xs:restriction>
</xs:simpleType>
<xs:simpleType name="int">
<xs:restriction base="xs:integer"></xs:restriction>
</xs:simpleType>
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="types" elementFormDefault="qualified">
<xs:complexType name="Color">
<xs:attribute name="R" type="xs:decimal" default="0.0"/>
<xs:attribute name="G" type="xs:decimal" default="0.0"/>
<xs:attribute name="B" type="xs:decimal" default="0.0"/>
<xs:attribute name="A" type="xs:decimal" default="1.0"/>
</xs:complexType>
</xs:schema>
+2
View File
@@ -330,11 +330,13 @@ void EntityXMLFile::parseEntityGraph()
std::size_t EntityXMLFile::getTypeStride(std::string typeName)
{
std::map<std::string, size_t> typeStrides{
{ "bool", sizeof(bool) },
{ "int", sizeof(int) },
{ "double", sizeof(double) },
{ "string", sizeof(std::string) },
{ "Vector", sizeof(glm::vec3) },
{ "Quaternion", sizeof(glm::quat) },
{ "Color", sizeof(glm::vec4) }
};
auto it = typeStrides.find(typeName);