// Copyright (c) 2008-2023 the Urho3D project
// License: MIT
#pragma once
#include "Sample.h"
namespace Urho3D
{
class Node;
class Scene;
}
/// Dynamic geometry example.
/// This sample demonstrates:
/// - Cloning a Model resource
/// - Modifying the vertex buffer data of the cloned models at runtime to efficiently animate them
/// - Creating a Model resource and its buffer data from scratch
class DynamicGeometry : public Sample
{
URHO3D_OBJECT(DynamicGeometry, Sample);
public:
/// Construct.
explicit DynamicGeometry(Context* context);
/// Setup after engine initialization and before running the main loop.
void Start() override;
protected:
/// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
String GetScreenJoystickPatchString() const override { return
""
" "
" Animation"
" "
" "
" "
" "
" "
" "
"";
}
private:
/// Construct the scene content.
void CreateScene();
/// Construct an instruction text to the UI.
void CreateInstructions();
/// Set up a viewport for displaying the scene.
void SetupViewport();
/// Subscribe to application-wide logic update events.
void SubscribeToEvents();
/// Read input and move the camera.
void MoveCamera(float timeStep);
/// Animate the vertex data of the objects.
void AnimateObjects(float timeStep);
/// Handle the logic update event.
void HandleUpdate(StringHash eventType, VariantMap& eventData);
/// Cloned models' vertex buffers that we will animate.
Vector> animatingBuffers_;
/// Original vertex positions for the sphere model.
Vector originalVertices_;
/// If the vertices are duplicates, indices to the original vertices (to allow seamless animation.)
Vector vertexDuplicates_;
/// Animation flag.
bool animate_;
/// Animation's elapsed time.
float time_;
};