Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code/model/animation/modelanimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,7 @@ namespace animation {
{"$Axis Rotation:", ModelAnimationSegmentAxisRotation::parser},
{"$Translation:", ModelAnimationSegmentTranslation::parser},
{"$Sound During:", ModelAnimationSegmentSoundDuring::parser},
{"$Particles During:", ModelAnimationSegmentParticlesDuring::parser},
{"$Inverse Kinematics:", ModelAnimationSegmentIK::parser}
};

Expand Down
108 changes: 108 additions & 0 deletions code/model/animation/modelanimation_segments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <utility>

#include "render/3d.h"
#include "particle/ParticleManager.h"
#include "particle/hosts/EffectHostObject.h"
#include "particle/hosts/EffectHostSubmodel.h"
#include "particle/hosts/EffectHostVector.h"

namespace animation {

Expand Down Expand Up @@ -1287,6 +1291,8 @@ namespace animation {
instance.interruptableSound = false;
instance.currentlyPlaying = sound_handle::invalid();
}

m_segment->forceStopAnimation(pmi_id);
}

void ModelAnimationSegmentSoundDuring::playLoopSnd(polymodel_instance* pmi) {
Expand Down Expand Up @@ -1381,6 +1387,108 @@ namespace animation {
}


ModelAnimationSegmentParticlesDuring::ModelAnimationSegmentParticlesDuring(std::shared_ptr<ModelAnimationSegment> segment, particle::ParticleEffectHandle effect, float atTime, std::shared_ptr<ModelAnimationSubmodel> submodel, std::optional<vec3d> position, std::optional<matrix> orientation) :
m_segment(std::move(segment)), m_submodel(std::move(submodel)), m_position(std::move(position)), m_orientation(std::move(orientation)), m_effect(effect), m_atTime(atTime) { }

ModelAnimationSegment* ModelAnimationSegmentParticlesDuring::copy() const {
auto newCopy = new ModelAnimationSegmentParticlesDuring(*this);
newCopy->m_segment = std::shared_ptr<ModelAnimationSegment>(newCopy->m_segment->copy());
return newCopy;
}

void ModelAnimationSegmentParticlesDuring::recalculate(ModelAnimationSubmodelBuffer& base, ModelAnimationSubmodelBuffer& currentAnimDelta, polymodel_instance* pmi) {
m_segment->recalculate(base, currentAnimDelta, pmi);
m_duration[pmi->id] = m_segment->getDuration(pmi->id);
}

void ModelAnimationSegmentParticlesDuring::calculateAnimation(ModelAnimationSubmodelBuffer& base, float time, int pmi_id) const {
m_segment->calculateAnimation(base, time, pmi_id);
}

void ModelAnimationSegmentParticlesDuring::executeAnimation(const ModelAnimationSubmodelBuffer& state, float timeboundLower, float timeboundUpper, ModelAnimationDirection direction, int pmi_id) {
float atTime = fminf(fmaxf(m_atTime, 0.0f), m_duration.at(pmi_id));
if (timeboundLower <= atTime && atTime <= timeboundUpper) {
createParticleSource(model_get_instance(pmi_id));
}
m_segment->executeAnimation(state, timeboundLower, timeboundUpper, direction, pmi_id);
}

void ModelAnimationSegmentParticlesDuring::exchangeSubmodelPointers(ModelAnimationSet& replaceWith) {
m_segment->exchangeSubmodelPointers(replaceWith);
}

void ModelAnimationSegmentParticlesDuring::forceStopAnimation(int pmi_id) {
m_segment->forceStopAnimation(pmi_id);
}

void ModelAnimationSegmentParticlesDuring::createParticleSource(polymodel_instance* pmi) const {
if (!m_effect.isValid())
return;

auto source = particle::ParticleManager::get()->createSource(m_effect);
if (!source)
return;

matrix orient = m_orientation.value_or(vmd_identity_matrix);
vec3d pos = m_position.value_or(vmd_zero_vector);

std::unique_ptr<EffectHost> host;

if (m_submodel != nullptr && pmi->objnum >= 0) {
auto submodel = m_submodel->findSubmodel(pmi);
if (submodel.first != nullptr) {
host = std::make_unique<EffectHostSubmodel>(&Objects[pmi->objnum], static_cast<int>(submodel.first - pmi->submodel), pos, orient);
}
}

if (!host && pmi->objnum >= 0) {
host = std::make_unique<EffectHostObject>(&Objects[pmi->objnum], pos, orient);
}

if (!host) {
host = std::make_unique<EffectHostVector>(pos, orient, vmd_zero_vector);
}

source->setHost(std::move(host));
source->finishCreation();
}

std::shared_ptr<ModelAnimationSegment> ModelAnimationSegmentParticlesDuring::parser(ModelAnimationParseHelper* data) {
auto submodel = ModelAnimationParseHelper::parseSubmodel();
if (!submodel) {
if (data->parentSubmodel)
submodel = data->parentSubmodel;
}

required_string("+Effect:");
auto effect = particle::util::parseEffect(data->m_animationName);

required_string("+At Time:");
float atTime = 0.0f;
stuff_float(&atTime);

std::optional<vec3d> position = std::nullopt;
if (optional_string("+Position:")) {
vec3d parse;
stuff_vec3d(&parse);
position = std::move(parse);
}

std::optional<matrix> orientation = std::nullopt;
if (optional_string("+Orientation:")) {
angles angle;
stuff_angles_deg_phb(&angle);
matrix mat;
vm_angles_2_matrix(&mat, &angle);
orientation = std::move(mat);
}

auto segment = std::make_shared<ModelAnimationSegmentParticlesDuring>(data->parseSegment(), effect, atTime, submodel, position, orientation);

return segment;
}


ModelAnimationSegmentIK::ModelAnimationSegmentIK(const vec3d& targetPosition, const std::optional<matrix>& targetRotation)
: m_targetPosition(targetPosition), m_targetRotation(targetRotation) { }

Expand Down
29 changes: 29 additions & 0 deletions code/model/animation/modelanimation_segments.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "math/ik_solver.h"
#include "model/animation/modelanimation.h"
#include "particle/particle.h"

namespace animation {

Expand Down Expand Up @@ -290,6 +291,34 @@ namespace animation {

};

class ModelAnimationSegmentParticlesDuring : public ModelAnimationSegment {
std::shared_ptr<ModelAnimationSegment> m_segment;

std::shared_ptr<ModelAnimationSubmodel> m_submodel;
std::optional<vec3d> m_position;
std::optional<matrix> m_orientation;

//configurables:
public:
particle::ParticleEffectHandle m_effect;
float m_atTime;

private:
ModelAnimationSegment* copy() const override;
void recalculate(ModelAnimationSubmodelBuffer& base, ModelAnimationSubmodelBuffer& currentAnimDelta, polymodel_instance* pmi) override;
void calculateAnimation(ModelAnimationSubmodelBuffer& base, float time, int pmi_id) const override;
void executeAnimation(const ModelAnimationSubmodelBuffer& state, float timeboundLower, float timeboundUpper, ModelAnimationDirection direction, int pmi_id) override;
void exchangeSubmodelPointers(ModelAnimationSet& replaceWith) override;
void forceStopAnimation(int pmi_id) override;

void createParticleSource(polymodel_instance* pmi) const;

public:
static std::shared_ptr<ModelAnimationSegment> parser(ModelAnimationParseHelper* data);
ModelAnimationSegmentParticlesDuring(std::shared_ptr<ModelAnimationSegment> segment, particle::ParticleEffectHandle effect, float atTime, std::shared_ptr<ModelAnimationSubmodel> submodel = nullptr, std::optional<vec3d> position = std::nullopt, std::optional<matrix> orientation = std::nullopt);

};

class ModelAnimationSegmentIK : public ModelAnimationSegment {
struct instance_data {

Expand Down
Loading