Add Plane object parsing to ObjectParser
This commit is contained in:
parent
d37b82b116
commit
964b6a5751
2 changed files with 78 additions and 2 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
#include "objectBox.hh"
|
#include "objectBox.hh"
|
||||||
|
#include "objectPlane.hh"
|
||||||
#include "object_sphere.h"
|
#include "object_sphere.h"
|
||||||
#include "yaml/objectParser.hh"
|
#include "yaml/objectParser.hh"
|
||||||
#include "yaml/vectorParser.hh"
|
#include "yaml/vectorParser.hh"
|
||||||
|
@ -33,6 +34,9 @@ ObjectParser::ObjectParser(Scene& scene,
|
||||||
if (tag == "!Object.Box") {
|
if (tag == "!Object.Box") {
|
||||||
mType = Type::Box;
|
mType = Type::Box;
|
||||||
mObject.reset(new Box());
|
mObject.reset(new Box());
|
||||||
|
} else if (tag == "!Object.Plane") {
|
||||||
|
mType = Type::Plane;
|
||||||
|
mObject.reset(new Plane());
|
||||||
} else if (tag == "!Object.Sphere") {
|
} else if (tag == "!Object.Sphere") {
|
||||||
mType = Type::Sphere;
|
mType = Type::Sphere;
|
||||||
mObject.reset(new Sphere());
|
mObject.reset(new Sphere());
|
||||||
|
@ -66,6 +70,11 @@ ObjectParser::HandleKeyEvent(const std::string& key)
|
||||||
{"far", FarSection}
|
{"far", FarSection}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const std::map<std::string, Section> sPlaneSections = {
|
||||||
|
{"normal", NormalSection},
|
||||||
|
{"distance", DistanceSection}
|
||||||
|
};
|
||||||
|
|
||||||
if (sCommonSections.count(key) > 0) {
|
if (sCommonSections.count(key) > 0) {
|
||||||
mSection = sCommonSections.at(key);
|
mSection = sCommonSections.at(key);
|
||||||
return;
|
return;
|
||||||
|
@ -77,6 +86,12 @@ ObjectParser::HandleKeyEvent(const std::string& key)
|
||||||
} else {
|
} else {
|
||||||
mSection = NoSection;
|
mSection = NoSection;
|
||||||
}
|
}
|
||||||
|
} else if (mType == Type::Plane) {
|
||||||
|
if (sPlaneSections.count(key) > 0) {
|
||||||
|
mSection = sPlaneSections.at(key);
|
||||||
|
} else {
|
||||||
|
mSection = NoSection;
|
||||||
|
}
|
||||||
} else if (mType == Type::Sphere) {
|
} else if (mType == Type::Sphere) {
|
||||||
if (sSphereSections.count(key) > 0) {
|
if (sSphereSections.count(key) > 0) {
|
||||||
mSection = sSphereSections.at(key);
|
mSection = sSphereSections.at(key);
|
||||||
|
@ -96,18 +111,31 @@ ObjectParser::HandleValueEvent(yaml_event_t& event)
|
||||||
case ColorSection:
|
case ColorSection:
|
||||||
HandleColorEvent(event);
|
HandleColorEvent(event);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* Spheres */
|
||||||
case OriginSection:
|
case OriginSection:
|
||||||
HandleOriginEvent(event);
|
HandleOriginEvent(event);
|
||||||
break;
|
break;
|
||||||
case RadiusSection:
|
case RadiusSection:
|
||||||
HandleRadiusEvent(event);
|
HandleRadiusEvent(event);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* Boxes */
|
||||||
case NearSection:
|
case NearSection:
|
||||||
HandleNearEvent(event);
|
HandleNearEvent(event);
|
||||||
break;
|
break;
|
||||||
case FarSection:
|
case FarSection:
|
||||||
HandleFarEvent(event);
|
HandleFarEvent(event);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* Planes */
|
||||||
|
case NormalSection:
|
||||||
|
HandleNormalEvent(event);
|
||||||
|
break;
|
||||||
|
case DistanceSection:
|
||||||
|
HandleDistanceEvent(event);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
break;
|
break;
|
||||||
|
@ -211,4 +239,44 @@ ObjectParser::HandleFarEvent(yaml_event_t& event)
|
||||||
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone));
|
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ObjectParser::HandleNormalEvent(yaml_event_t& event)
|
||||||
|
{
|
||||||
|
if (event.type != YAML_SEQUENCE_START_EVENT) {
|
||||||
|
/* TODO: Clean this up. */
|
||||||
|
assert(event.type != YAML_SEQUENCE_START_EVENT);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto onDone = [this](Vector3 normal) {
|
||||||
|
std::dynamic_pointer_cast<Plane>(mObject)->SetNormal(normal);
|
||||||
|
mSection = NoSection;
|
||||||
|
SetShouldExpectKey(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ObjectParser::HandleDistanceEvent(yaml_event_t& event)
|
||||||
|
{
|
||||||
|
if (event.type != YAML_SCALAR_EVENT) {
|
||||||
|
/* TODO: Clean this up. */
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Double distance;
|
||||||
|
std::string scalar((char *)event.data.scalar.value,
|
||||||
|
event.data.scalar.length);
|
||||||
|
if (!ParseScalar<Double>(scalar, distance)) {
|
||||||
|
/* TODO: Clean this up. */
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
std::dynamic_pointer_cast<Plane>(mObject)->SetDistance(distance);
|
||||||
|
mSection = NoSection;
|
||||||
|
SetShouldExpectKey(true);
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace yaml */
|
} /* namespace yaml */
|
||||||
|
|
|
@ -29,7 +29,8 @@ protected:
|
||||||
private:
|
private:
|
||||||
enum class Type {
|
enum class Type {
|
||||||
Box,
|
Box,
|
||||||
Sphere
|
Plane,
|
||||||
|
Sphere,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Section {
|
enum Section {
|
||||||
|
@ -42,7 +43,11 @@ private:
|
||||||
|
|
||||||
/* Box sections */
|
/* Box sections */
|
||||||
NearSection,
|
NearSection,
|
||||||
FarSection
|
FarSection,
|
||||||
|
|
||||||
|
/* Plane sections */
|
||||||
|
NormalSection,
|
||||||
|
DistanceSection,
|
||||||
};
|
};
|
||||||
|
|
||||||
void HandleColorEvent(yaml_event_t& event);
|
void HandleColorEvent(yaml_event_t& event);
|
||||||
|
@ -53,6 +58,9 @@ private:
|
||||||
void HandleNearEvent(yaml_event_t& event);
|
void HandleNearEvent(yaml_event_t& event);
|
||||||
void HandleFarEvent(yaml_event_t& event);
|
void HandleFarEvent(yaml_event_t& event);
|
||||||
|
|
||||||
|
void HandleNormalEvent(yaml_event_t& event);
|
||||||
|
void HandleDistanceEvent(yaml_event_t& event);
|
||||||
|
|
||||||
charles::Object::Ptr mObject;
|
charles::Object::Ptr mObject;
|
||||||
Type mType;
|
Type mType;
|
||||||
Section mSection;
|
Section mSection;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue