animation preview play/pause button
This commit is contained in:
parent
7b0385a48a
commit
c958fbc9c6
12 changed files with 102 additions and 5 deletions
|
@ -397,6 +397,18 @@ void PropertyView::onScriptCompiled(const Lumix::Path& path, uint32_t status)
|
|||
}
|
||||
|
||||
|
||||
void PropertyView::on_animablePlayPause()
|
||||
{
|
||||
m_client->playPausePreviewAnimable();
|
||||
}
|
||||
|
||||
|
||||
void PropertyView::on_animableTimeSet(int value)
|
||||
{
|
||||
m_client->setAnimableTime(value);
|
||||
}
|
||||
|
||||
|
||||
void PropertyView::on_compileScriptClicked()
|
||||
{
|
||||
for(int i = 0; i < m_properties.size(); ++i)
|
||||
|
@ -425,6 +437,25 @@ void PropertyView::on_editScriptClicked()
|
|||
}
|
||||
|
||||
|
||||
void PropertyView::addAnimableCustomProperties()
|
||||
{
|
||||
QTreeWidgetItem* tools_item = new QTreeWidgetItem(QStringList() << "Tools");
|
||||
m_ui->propertyList->topLevelItem(0)->insertChild(0, tools_item);
|
||||
QWidget* widget = new QWidget();
|
||||
QHBoxLayout* layout = new QHBoxLayout(widget);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
QPushButton* compile_button = new QPushButton("Play/Pause", widget);
|
||||
QSlider* slider = new QSlider(Qt::Orientation::Horizontal, widget);
|
||||
slider->setMinimum(0);
|
||||
slider->setMaximum(100);
|
||||
layout->addWidget(compile_button);
|
||||
layout->addWidget(slider);
|
||||
m_ui->propertyList->setItemWidget(tools_item, 1, widget);
|
||||
connect(compile_button, &QPushButton::clicked, this, &PropertyView::on_animablePlayPause);
|
||||
connect(slider, &QSlider::valueChanged, this, &PropertyView::on_animableTimeSet);
|
||||
}
|
||||
|
||||
|
||||
void PropertyView::addScriptCustomProperties()
|
||||
{
|
||||
QTreeWidgetItem* tools_item = new QTreeWidgetItem(QStringList() << "Tools");
|
||||
|
@ -508,6 +539,7 @@ void PropertyView::onEntitySelected(Lumix::EntitySelectedEvent& e)
|
|||
else if (e.components[i] == crc32("animable"))
|
||||
{
|
||||
addProperty("animable", "preview", "Preview animation", Property::FILE, "Animation (*.ani)");
|
||||
addAnimableCustomProperties();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -65,6 +65,8 @@ private slots:
|
|||
void on_browseFilesClicked();
|
||||
void on_compileScriptClicked();
|
||||
void on_editScriptClicked();
|
||||
void on_animablePlayPause();
|
||||
void on_animableTimeSet(int value);
|
||||
|
||||
private:
|
||||
void clear();
|
||||
|
@ -74,6 +76,7 @@ private:
|
|||
void addProperty(const char* component, const char* name, const char* label, Property::Type type, const char* file_type);
|
||||
void onPropertyValue(Property* property, void* data, int32_t data_size);
|
||||
void addScriptCustomProperties();
|
||||
void addAnimableCustomProperties();
|
||||
void onScriptCompiled(const Lumix::Path& path, uint32_t status);
|
||||
void setScriptStatus(uint32_t status);
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ void Animation::getPose(float time, Pose& pose, Model& model) const
|
|||
int model_bone_index = iter.value();
|
||||
lerp(m_positions[off + i], m_positions[off2 + i], &pos[model_bone_index], t);
|
||||
nlerp(m_rotations[off + i], m_rotations[off2 + i], &rot[model_bone_index], t);
|
||||
|
||||
/*int parent = model.getBone(model_bone_index).parent_idx;
|
||||
ASSERT(parent < model_bone_index);
|
||||
if (parent >= 0)
|
||||
|
@ -109,6 +110,7 @@ void Animation::getPose(float time, Pose& pose, Model& model) const
|
|||
}
|
||||
}
|
||||
pose.setIsRelative();
|
||||
pose.computeAbsolute(model);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -176,6 +176,24 @@ namespace Lumix
|
|||
}
|
||||
|
||||
|
||||
void AnimationSystem::setFrame(Component cmp, int frame)
|
||||
{
|
||||
m_impl->m_animables[cmp.index].m_time = m_impl->m_animables[cmp.index].m_animation->getLength() * frame / 30.0f; /// TODO get rid of the constant
|
||||
}
|
||||
|
||||
|
||||
bool AnimationSystem::isManual(Component cmp)
|
||||
{
|
||||
return m_impl->m_animables[cmp.index].m_manual;
|
||||
}
|
||||
|
||||
|
||||
void AnimationSystem::setManual(Component cmp, bool is_manual)
|
||||
{
|
||||
m_impl->m_animables[cmp.index].m_manual = is_manual;
|
||||
}
|
||||
|
||||
|
||||
void AnimationSystem::getPreview(Component cmp, string& path)
|
||||
{
|
||||
path = m_impl->m_animables[cmp.index].m_animation ? m_impl->m_animables[cmp.index].m_animation->getPath().c_str() : "";
|
||||
|
@ -209,7 +227,7 @@ namespace Lumix
|
|||
for(int i = 0, c = m_impl->m_animables.size(); i < c; ++i)
|
||||
{
|
||||
AnimationSystemImpl::Animable& animable = m_impl->m_animables[i];
|
||||
if(animable.m_animation->isReady())
|
||||
if (animable.m_animation && animable.m_animation->isReady())
|
||||
{
|
||||
RenderScene* scene = static_cast<RenderScene*>(animable.m_renderable.system);
|
||||
animable.m_animation->getPose(animable.m_time, scene->getPose(animable.m_renderable), *scene->getModel(animable.m_renderable));
|
||||
|
|
|
@ -33,6 +33,9 @@ namespace Lumix
|
|||
virtual Component createComponent(uint32_t, const Entity&) override;
|
||||
virtual const char* getName() const override { return "animation"; }
|
||||
|
||||
void setFrame(Component cmp, int frame);
|
||||
bool isManual(Component cmp);
|
||||
void setManual(Component cmp, bool is_manual);
|
||||
void getPreview(Component cmp, string& path);
|
||||
void setPreview(Component cmp, const string& path);
|
||||
void destroy();
|
||||
|
|
|
@ -27,9 +27,11 @@ struct ClientMessageType
|
|||
SET_EDIT_MODE, // 16
|
||||
EDIT_SCRIPT, // 17
|
||||
SET_WIREFRAME, // 18
|
||||
NEW_UNIVERSE = 19, // 19
|
||||
LOOK_AT_SELECTED = 20, // 20
|
||||
NEW_UNIVERSE, // 19
|
||||
LOOK_AT_SELECTED, // 20
|
||||
STOP_GAME_MODE, // 21
|
||||
PLAY_PAUSE_ANIMABLE,
|
||||
SET_ANIMABLE_TIME
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -199,6 +199,16 @@ namespace Lumix
|
|||
m_impl->sendMessage(ClientMessageType::NEW_UNIVERSE, NULL, 0);
|
||||
}
|
||||
|
||||
void EditorClient::setAnimableTime(int32_t time)
|
||||
{
|
||||
m_impl->sendMessage(ClientMessageType::SET_ANIMABLE_TIME, &time, sizeof(time));
|
||||
}
|
||||
|
||||
void EditorClient::playPausePreviewAnimable()
|
||||
{
|
||||
m_impl->sendMessage(ClientMessageType::PLAY_PAUSE_ANIMABLE, NULL, 0);
|
||||
}
|
||||
|
||||
void EditorClient::setEntityPosition(int32_t entity, const Vec3& position)
|
||||
{
|
||||
uint8_t data[sizeof(entity) + sizeof(position)];
|
||||
|
|
|
@ -44,6 +44,8 @@ namespace Lumix
|
|||
void setEntityPosition(int32_t entity, const Vec3& position);
|
||||
void setWireframe(bool is_wireframe);
|
||||
void newUniverse();
|
||||
void playPausePreviewAnimable();
|
||||
void setAnimableTime(int time);
|
||||
const char* getBasePath() const;
|
||||
PropertyListCallback& propertyListReceived();
|
||||
EntitySelectedCallback& entitySelected();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "editor_server.h"
|
||||
|
||||
#include "animation/animation_system.h"
|
||||
#include "core/array.h"
|
||||
#include "core/blob.h"
|
||||
#include "core/crc32.h"
|
||||
|
@ -113,6 +114,8 @@ struct EditorServerImpl
|
|||
void stopGameMode();
|
||||
void lookAtSelected();
|
||||
void newUniverse();
|
||||
void playPausePreviewAnimable();
|
||||
void setAnimableTime(int frame);
|
||||
void logMessage(int32_t type, const char* system, const char* msg);
|
||||
Entity& getSelectedEntity() { return m_selected_entity; }
|
||||
bool isGameMode() const { return m_is_game_mode; }
|
||||
|
@ -590,6 +593,20 @@ void EditorServerImpl::loadMap(FS::IFile* file, bool success, FS::FileSystem& fs
|
|||
fs.close(file);
|
||||
}
|
||||
|
||||
void EditorServerImpl::setAnimableTime(int frame)
|
||||
{
|
||||
AnimationSystem* anim_system = static_cast<AnimationSystem*>(m_engine.getPluginManager().getPlugin("animation"));
|
||||
Component cmp = m_selected_entity.getComponent(crc32("animable"));
|
||||
anim_system->setFrame(cmp, frame);
|
||||
}
|
||||
|
||||
void EditorServerImpl::playPausePreviewAnimable()
|
||||
{
|
||||
AnimationSystem* anim_system = static_cast<AnimationSystem*>(m_engine.getPluginManager().getPlugin("animation"));
|
||||
Component cmp = m_selected_entity.getComponent(crc32("animable"));
|
||||
anim_system->setManual(cmp, !anim_system->isManual(cmp));
|
||||
}
|
||||
|
||||
void EditorServerImpl::newUniverse()
|
||||
{
|
||||
destroyUniverse();
|
||||
|
@ -1077,6 +1094,12 @@ void EditorServerImpl::onMessage(const uint8_t* data, int32_t size)
|
|||
case ClientMessageType::NEW_UNIVERSE:
|
||||
newUniverse();
|
||||
break;
|
||||
case ClientMessageType::PLAY_PAUSE_ANIMABLE:
|
||||
playPausePreviewAnimable();
|
||||
break;
|
||||
case ClientMessageType::SET_ANIMABLE_TIME:
|
||||
setAnimableTime(msg[1]);
|
||||
break;
|
||||
default:
|
||||
ASSERT(false); // unknown message
|
||||
break;
|
||||
|
|
|
@ -27,6 +27,7 @@ Pose::~Pose()
|
|||
|
||||
void Pose::resize(int count)
|
||||
{
|
||||
m_is_absolute = false;
|
||||
LUMIX_DELETE_ARRAY(m_positions);
|
||||
LUMIX_DELETE_ARRAY(m_rotations);
|
||||
m_count = count;
|
||||
|
|
|
@ -527,7 +527,7 @@ namespace Lumix
|
|||
info.m_model = &m_renderables[i]->m_model;
|
||||
info.m_matrix = &m_renderables[i]->m_model.getMatrix();
|
||||
|
||||
m_renderables[i]->m_model.getPose().computeAbsolute(*info.m_model->getModel());
|
||||
//m_renderables[i]->m_model.getPose().computeAbsolute(*info.m_model->getModel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -543,12 +543,13 @@ struct PhysicsSceneImpl : public PhysicsScene
|
|||
const uint16_t* LUMIX_RESTRICT data = (const uint16_t*)terrain->m_heightmap->getData();
|
||||
for (int j = 0; j < height; ++j)
|
||||
{
|
||||
int idx = j * width;
|
||||
for (int i = 0; i < width; ++i)
|
||||
{
|
||||
int idx = i + j * width;
|
||||
int idx2 = j + i * height;
|
||||
heights[idx].height = data[idx2];
|
||||
heights[idx].materialIndex0 = heights[idx].materialIndex1 = 0;
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue