Compare commits

...

2 Commits

5 changed files with 76 additions and 34 deletions

View File

@@ -54,7 +54,7 @@ class ExportMappingMale:
self.files.append({"name": fobj})
class ExportMappingMaleEdited:
blend_path = "assets/blender/" + "edited-normal-male.blend"
blend_path = "assets/blender/characters/" + "edited-normal-male.blend"
gltf_path = "characters/male/normal-male.gltf"
ogre_scene = "characters/male/vroid-normal-male.scene"
inner_path = "Object"
@@ -68,7 +68,7 @@ class ExportMappingMaleEdited:
self.files.append({"name": fobj})
class ExportMappingMaleClothedEdited:
blend_path = "assets/blender/" + "edited-normal-male.blend"
blend_path = "assets/blender/characters/" + "edited-normal-male.blend"
gltf_path = "characters/male/normal-male.gltf"
ogre_scene = "characters/male/vroid-normal-male.scene"
inner_path = "Object"
@@ -82,7 +82,7 @@ class ExportMappingMaleClothedEdited:
self.files.append({"name": fobj})
class ExportMappingFemaleEdited:
blend_path = "assets/blender/" + "edited-normal-female.blend"
blend_path = "assets/blender/characters/" + "edited-normal-female.blend"
gltf_path = "characters/female/normal-female.gltf"
ogre_scene = "characters/female/vroid-normal-female.scene"
inner_path = "Object"

View File

@@ -328,6 +328,18 @@ public:
if (action == "sit") {
jactionPrereq["is_seated"] = 0;
jactionEffect["is_seated"] = 1;
} else if (action == "use") {
if (props["tags"].find("toilet") !=
props["tags"].end()) {
std::cout << "toilet" << std::endl;
OgreAssert(false, "props: " + props.dump(4));
} else {
std::cout << "use: " << props.dump(4)
<< std::endl;
// OgreAssert(false, "props: " + props.dump(4));
}
} else {
OgreAssert(false, "props: " + props.dump(4));
}
Blackboard actionPrereq({ jactionPrereq });
Blackboard actionEffect({ jactionEffect });

View File

@@ -98,7 +98,6 @@ CharacterManagerModule::CharacterManagerModule(flecs::world &ecs)
.interval(1.0f)
.write<CharacterBase>()
.write<CharacterLocation>()
.write<CharacterConf>()
.write<Character>()
.write<LivesIn>()
.each([this](flecs::entity town, TerrainItem &item,

View File

@@ -17,11 +17,54 @@ CharacterModule::CharacterModule(flecs::world &ecs)
ecs.module<CharacterModule>();
ecs.component<Character>();
ecs.component<Player>();
ecs.component<CharacterBase>();
ecs.component<CharacterBase>()
.on_remove([this](flecs::entity e, CharacterBase &ch) {
// FIXME: clean up data
if (characterEntities.find(e) !=
characterEntities.end() ||
characterNodes.find(e) != characterNodes.end()) {
characterEntities.erase(e);
characterNodes.erase(e);
ECS::modified<CharacterModule>();
}
})
.on_add([this](flecs::entity e, CharacterBase &ch) {
if (characterNodes.find(e) == characterNodes.end()) {
OgreAssert(characterModels.find(e) !=
characterModels.end(),
"no model set");
const EngineData &eng = ECS::get<EngineData>();
Ogre::SceneNode *bodyNode =
eng.mScnMgr->getRootSceneNode()
->createChildSceneNode();
Ogre::Entity *bodyEnt =
eng.mScnMgr->createEntity(
characterModels[e]);
characterNodes[e] = bodyNode;
characterEntities[e] = bodyEnt;
ECS::modified<CharacterModule>();
}
OgreAssert(characterOrientations.find(e) !=
characterOrientations.end(),
"Bad orientation/position");
ch.mBodyEnt = characterEntities[e];
ch.mBodyNode = characterNodes[e];
ch.mBodyNode->setOrientation(characterOrientations[e]);
ch.mBodyNode->setPosition(characterPositions[e]);
ch.mBodyNode->attachObject(ch.mBodyEnt);
OgreAssert(ch.mBodyEnt->getSkeleton()->hasBone("Root"),
"No root bone");
ch.mBoneMotion = Ogre::Vector3::ZERO;
ch.mBonePrevMotion = Ogre::Vector3::ZERO;
});
ecs.component<CharacterGravity>();
ecs.component<CharacterLocation>();
ecs.component<CharacterLocation>().on_set(
[this](flecs::entity e, CharacterLocation &loc) {
characterOrientations[e] = loc.orientation;
characterPositions[e] = loc.position;
ECS::modified<CharacterModule>();
});
ecs.component<CharacterBuoyancy>();
ecs.component<CharacterConf>();
ecs.component<CharacterDisablePhysics>();
ecs.component<CharacterUpdatePhysicsState>();
ecs.component<CharacterInActuator>();
@@ -204,24 +247,6 @@ CharacterModule::CharacterModule(flecs::world &ecs)
});
#endif
static int characterCount = 0;
ecs.observer<const EngineData, const CharacterLocation,
const CharacterConf, CharacterBase>(
"SetupCharacterBaseObs")
.event(flecs::OnAdd)
.each([&](flecs::entity e, const EngineData &eng,
const CharacterLocation &loc,
const CharacterConf &conf, CharacterBase &ch) {
ch.mBodyEnt = eng.mScnMgr->createEntity(conf.type);
ch.mBodyNode = eng.mScnMgr->getRootSceneNode()
->createChildSceneNode();
ch.mBodyNode->setOrientation(loc.orientation);
ch.mBodyNode->setPosition(loc.position);
ch.mBodyNode->attachObject(ch.mBodyEnt);
OgreAssert(ch.mBodyEnt->getSkeleton()->hasBone("Root"),
"No root bone");
ch.mBoneMotion = Ogre::Vector3::ZERO;
ch.mBonePrevMotion = Ogre::Vector3::ZERO;
});
ecs.observer<AnimationControl>("SetupAnimationControlObs")
.event(flecs::OnAdd)
.each([](flecs::entity e, AnimationControl &anim) {
@@ -613,14 +638,18 @@ void CharacterModule::createCharacter(flecs::entity e,
{
if (e.has<CharacterBase>() || e.has<AnimationControl>())
return;
if (characterNodes.find(e) != characterNodes.end())
return;
e.set<CharacterLocation>({ rotation, position });
e.set<CharacterConf>({ model });
e.add<CharacterBase>();
e.add<AnimationControl>();
characterOrientations[e] = rotation;
characterPositions[e] = position;
characterModels[e] = model;
e.set<CharacterVelocity>(
{ { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } });
e.add<CharacterGravity>();
e.add<CharacterBuoyancy>();
e.add<Character>();
e.add<CharacterBase>();
e.add<AnimationControl>();
}
}

View File

@@ -19,20 +19,17 @@ struct Female {};
struct CharacterBase {
Ogre::String type;
float mTimer;
Ogre::SceneNode *mBodyNode;
Ogre::Entity *mBodyEnt;
Ogre::Vector3 mBoneMotion;
Ogre::Vector3 mBonePrevMotion;
Ogre::Vector3 mGoalDirection; // actual intended direction in world-space
bool is_submerged;
Ogre::SceneNode *mBodyNode;
Ogre::Entity *mBodyEnt;
bool is_submerged;
};
struct CharacterLocation {
Ogre::Quaternion orientation;
Ogre::Vector3 position;
};
struct CharacterConf {
Ogre::String type;
};
struct CharacterInActuator {
Ogre::String animationState;
Vector3 prevMotion;
@@ -45,6 +42,11 @@ struct CharacterModule {
void createCharacter(flecs::entity e, const Ogre::Vector3 &position,
const Ogre::Quaternion &rotation,
const Ogre::String model);
std::unordered_map<flecs::entity_t, Ogre::SceneNode *> characterNodes;
std::unordered_map<flecs::entity_t, Ogre::Entity *> characterEntities;
std::unordered_map<flecs::entity_t, Ogre::String> characterModels;
std::unordered_map<flecs::entity_t, Ogre::Vector3> characterPositions;
std::unordered_map<flecs::entity_t, Ogre::Quaternion> characterOrientations;
};
}
#endif