66 lines
1.8 KiB
ActionScript 3
66 lines
1.8 KiB
ActionScript 3
// ECS scenegraph demo
|
|
// Loads a scene from TOML and animates the hierarchy
|
|
|
|
uint sceneRoot = 0;
|
|
uint camera = 0;
|
|
uint light = 0;
|
|
float time = 0.0f;
|
|
bool lightToggle = false;
|
|
|
|
void Init() {
|
|
Log(LOG_TRACE, "Initialization complete - Scenegraph demo!");
|
|
Toast::Success("Scenegraph demo initialized.");
|
|
|
|
sceneRoot = Scene::Load("scenes/demo.toml");
|
|
if (!ECS::IsValid(sceneRoot)) {
|
|
Toast::Error("Failed to load scene");
|
|
}
|
|
|
|
// === Set up camera ===
|
|
camera = ECS::CreateEntity();
|
|
ECS::AddCamera3D(camera,
|
|
5.0, 5.0, 5.0, // position
|
|
0.0, 0.0, 0.0, // target
|
|
45.0); // fovy
|
|
ECS::AddTag(camera, "MainCamera");
|
|
|
|
// === Set up light ===
|
|
light = ECS::CreateEntity();
|
|
ECS::AddLight(light, 0.5, 0.7, 0.3, 1.0); // direction + intensity
|
|
ECS::AddTag(light, "MainLight");
|
|
}
|
|
|
|
void Shutdown() {
|
|
Log(LOG_TRACE, "Shutdown complete!");
|
|
}
|
|
|
|
void Update(float dt) {
|
|
time += dt;
|
|
|
|
// Rotate the scene root to show parent/child propagation
|
|
if (ECS::IsValid(sceneRoot) && ECS::HasTransform(sceneRoot)) {
|
|
ECS::SetRotation(sceneRoot, time * 0.5f);
|
|
}
|
|
|
|
// Orbit the camera around the scene
|
|
if (ECS::HasCamera3D(camera)) {
|
|
float angle = time * 0.3f;
|
|
float radius = 7.0f;
|
|
float x = Math::Cos(angle) * radius;
|
|
float z = Math::Sin(angle) * radius;
|
|
ECS::SetCameraPosition(camera, x, 5.0f, z);
|
|
}
|
|
|
|
// Toggle light with jump action
|
|
if (IsActionPressed("jump")) {
|
|
lightToggle = !lightToggle;
|
|
if (lightToggle) {
|
|
ECS::SetLightDirection(light, -0.5, 0.7, -0.3);
|
|
Toast::Info("Light direction changed!");
|
|
} else {
|
|
ECS::SetLightDirection(light, 0.5, 0.7, 0.3);
|
|
Toast::Info("Light direction reset!");
|
|
}
|
|
}
|
|
}
|