Action nodes handling

This commit is contained in:
2026-02-01 23:25:38 +03:00
parent e6efd89bb0
commit 69035351a6
7 changed files with 81 additions and 40 deletions

View File

@@ -1,4 +1,5 @@
import bpy
import mathutils
ACTION_PROPS = ["name", "action", "action_text", "height", "radius", "tags"]
FURNITURE_PROPS = ["name", "furniture_tags"]
@@ -25,8 +26,9 @@ class TEST_OT_LinkAndPlay(bpy.types.Operator):
# 2. Add to scene and create Override
rig_obj = None
for obj in data_to.objects:
offset = mathutils.Matrix.Translation((0, -0.1, 0))
bpy.context.collection.objects.link(obj)
obj.matrix_world = target.matrix_world
obj.matrix_world = target.matrix_world @ offset
if obj.type == 'ARMATURE':
rig_obj = obj
if obj.library:

View File

@@ -116,8 +116,8 @@ def export_root_objects_to_gltf(output_dir):
if "type" in schild:
position["type"] = schild["type"]
position["position_x"] = local_pos[0]
position["position_y"] = local_pos[2]
position["position_z"] = local_pos[1]
position["position_y"] = local_pos[1]
position["position_z"] = local_pos[2]
position["rotation_w"] = local_rot[0]
position["rotation_x"] = local_rot[1]
position["rotation_y"] = local_rot[2]
@@ -137,8 +137,8 @@ def export_root_objects_to_gltf(output_dir):
if "type" in child:
position["type"] = child["type"]
position["position_x"] = local_pos[0]
position["position_y"] = local_pos[2]
position["position_z"] = local_pos[1]
position["position_y"] = local_pos[1]
position["position_z"] = local_pos[2]
position["rotation_w"] = local_rot[0]
position["rotation_x"] = local_rot[1]
position["rotation_y"] = local_rot[2]

Binary file not shown.

View File

@@ -375,9 +375,10 @@ CharacterAIModule::CharacterAIModule(flecs::world &ecs)
});
});
});
#if 1
ecs.system<TownAI, TownNPCs>("PlanAI")
.kind(flecs::OnUpdate)
.interval(1.0f)
.interval(0.5f)
.each([&](flecs::entity town, TownAI &ai,
const TownNPCs &npcs) {
Ogre::Root::getSingleton().getWorkQueue()->addTask(
@@ -393,6 +394,7 @@ CharacterAIModule::CharacterAIModule(flecs::world &ecs)
});
});
});
#endif
}
void CharacterAIModule::createAI(flecs::entity town)
@@ -413,10 +415,14 @@ void CharacterAIModule::buildPlans(flecs::entity town, const TownNPCs &npcs,
if (ai.plans.find(it->first) != ai.plans.end() &&
ai.plans.at(it->first).size() > 0)
continue;
ai.plans[it->first] = {};
const auto &npc = npcs.npcs.at(it->first);
int index = it->first;
ai.plans[index] = {};
for (const auto &goal : ai.goals) {
if (goal.is_reached(bb))
continue;
struct TownAI::Plan plan;
plan.goal = &goal;
#if 0
std::cout << "blackboard: "
<< bb.stats.dump(4)
@@ -477,12 +483,14 @@ void CharacterAIModule::buildPlans(flecs::entity town, const TownNPCs &npcs,
// "planning");
#endif
if (path_length > 0) {
struct TownAI::Plan plan;
plan.goal = &goal;
plan.plan.insert(plan.plan.end(), path.begin(),
path.begin() + path_length);
ai.plans[it->first].push_back(plan);
break;
}
if (path_length > 0)
OgreAssert(false, "plan");
}
}
}

View File

@@ -89,7 +89,8 @@ struct GUIListener : public Ogre::RenderTargetListener {
}
void buttons_panel()
{
ImVec2 size = ImGui::GetMainViewport()->Size;
bool enableDebugRender = ECS::get<EngineData>().enableDbgDraw;
ImVec2 size = ImGui::GetMainViewport()->Size;
float window_width = size.x * 0.2f;
if (window_width > panel_width)
window_width = panel_width;
@@ -115,7 +116,14 @@ struct GUIListener : public Ogre::RenderTargetListener {
if (enableMapEditor)
enableEditor = false;
}
ImGui::Text("Text message...");
if (ImGui::Checkbox("Enable physics debug",
&enableDebugRender)) {
ECS::get_mut<EngineData>().enableDbgDraw =
enableDebugRender;
ECS::modified<EngineData>();
PhysicsModule::setDebugDraw(enableDebugRender);
}
ImGui::Text("Text message...");
ImGui::End();
}
void create_entity_node(const Ogre::String &name, int key)

View File

@@ -452,10 +452,14 @@ out:;
{
if (placeLocalOffset.find(place) == placeLocalOffset.end())
return;
std::cout << "local offset: " << placeLocalOffset[place]
<< std::endl;
std::cout << "parent offset: " << anode.position << std::endl;
Ogre::Quaternion newRotation =
anode.rotation * placeLocalRotation[place];
Ogre::Vector3 newPosition =
anode.position + newRotation * placeLocalOffset[place];
anode.position +
anode.rotation * placeLocalOffset[place];
if (ch.is_valid() && ch.has<CharacterBase>()) {
ch.get<CharacterBase>()
.mBodyNode->_setDerivedOrientation(newRotation);
@@ -478,38 +482,57 @@ out:;
delay += delta;
// activate anly after delay
if (ECS::get<Input>().act == 0 && delay > 0.2f) {
delay = 0.0f;
state = 10;
// Yay!!!
std::cout << "Node data: " << std::endl;
std::cout << anode.props.dump(4) << std::endl;
if (ch.is_valid()) {
PhysicsModule::controlPhysics(ch,
false);
// no control by player or ai
ch.add<CharacterControlDisable>();
if (word == "sit")
ch.set<CharacterInActuator>(
{ "sitting-chair",
{ 0, 0, 0 } });
// else
// ch.set<CharacterInActuator>(
// { "idle", { 0, 0, 0 } });
}
teleport("enter");
delay = 0.0f;
state = 5;
} else if (ECS::get<Input>().act == 0 &&
delay <= 0.2f) {
delay = 0.0f;
state = 10;
state = 100;
}
break;
case 5:
case 10:
if (ch.is_valid()) {
PhysicsModule::controlPhysics(ch, false);
// no control by player or ai
ch.add<CharacterControlDisable>();
// else
// ch.set<CharacterInActuator>(
// { "idle", { 0, 0, 0 } });
}
delay = 0.0f;
state++;
break;
case 11:
teleport("enter");
delay = 0.0f;
state++;
break;
case 12:
if (ch.is_valid()) {
if (word == "sit")
ch.set<CharacterInActuator>(
{ "sitting-chair",
{ 0, 0, 0 } });
}
teleport("enter");
delay = 0.0f;
state++;
break;
case 13:
teleport("enter");
delay = 0.0f;
state = 50;
break;
case 50:
// teleport again to handle possible problems caused by root motion
delay = 0.0f;
teleport("enter");
state++;
break;
case 6:
case 51:
// do not move anywhere until we depress key and wait a bit
if (ECS::get<Input>().act == 0)
delay += delta;
@@ -518,7 +541,7 @@ out:;
state++;
}
break;
case 7:
case 52:
// if the key is pressed for a second move to next state
if (ECS::get<Input>().act)
delay += delta;
@@ -527,15 +550,15 @@ out:;
state++;
}
break;
case 8:
case 53:
delay = 0.0;
state = 10;
state = 100;
break;
case 10:
case 100:
delay = 0.0;
state++;
break;
case 11:
case 101:
// wait until key is depressed for a second
if (ECS::get<Input>().act == 0)
delay += delta;
@@ -544,7 +567,7 @@ out:;
state++;
}
break;
case 12:
case 102:
delay = 0.0f;
state = 0;
return OK;