-
Notifications
You must be signed in to change notification settings - Fork 180
Model surface particles #7447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Model surface particles #7447
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
99452e0
Pick model surface particle by sampling random vertex
BMagnu 14ba164
Parse and keep buffers
BMagnu f06120c
Add local position scaling
BMagnu ea9f5ab
Fix warning
BMagnu 88d224a
Fix warning 2
BMagnu b42d5d8
Fix warning 3
BMagnu 8778af3
Fix warning 4
BMagnu d3cb038
Add scale parameter
BMagnu 6ad053d
Incorporate feedback
BMagnu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #include "ModelSurfaceVolume.h" | ||
|
|
||
| #include "math/vecmat.h" | ||
|
|
||
| namespace particle { | ||
| ModelSurfaceVolume::ModelSurfaceVolume() : m_modelScale(::util::UniformFloatRange(1.f)), m_modular_curve_instance(m_modular_curves.create_instance()) { | ||
| Model_load_clear_CPU_buffers = false; | ||
| }; | ||
|
|
||
| vec3d ModelSurfaceVolume::sampleRandomPoint(const matrix &orientation, decltype(ParticleEffect::modular_curves_definition)::input_type_t source, float particlesFraction, const EffectHost& host) { | ||
| int obj_num = host.getParentObjAndSig().first; | ||
| int submodel = host.getParentSubmodel(); | ||
|
|
||
| vec3d point = ZERO_VECTOR; | ||
|
|
||
| auto curveSource = std::tuple_cat(source, std::make_tuple(particlesFraction)); | ||
|
|
||
| if (obj_num >= 0) { | ||
| const polymodel* pm = object_get_model(&Objects[obj_num]); | ||
| if (pm != nullptr) { | ||
| if (submodel < 0) { | ||
|
wookieejedi marked this conversation as resolved.
|
||
| SCP_vector<int> eligible_submodels; | ||
| for (int i = 0; i < pm->n_models; ++i) { | ||
| if (!pm->submodel[i].flags[Model::Submodel_flags::Is_lod, Model::Submodel_flags::Is_damaged, Model::Submodel_flags::Is_live_debris]) | ||
| eligible_submodels.emplace_back(i); | ||
| } | ||
|
|
||
| if (!eligible_submodels.empty()) | ||
| submodel = eligible_submodels[::util::UniformUIntRange(0U, static_cast<unsigned int>(eligible_submodels.size()) - 1).next()]; | ||
| } | ||
|
|
||
| if (submodel >= 0) { | ||
| const bsp_info* submodel_data = &pm->submodel[submodel]; | ||
| const auto* geometry_data = submodel_data->buffer.model_list; | ||
| Assertion(geometry_data != nullptr, "ModelSurfaceVolume particles were spawned on a model with no data available!"); | ||
|
|
||
| size_t target_vertex = ::util::UniformUIntRange(0U, static_cast<unsigned int>(geometry_data->n_verts) - 1).next(); | ||
|
|
||
| //This point is, despite its name, not in world space, but in model local space (NOT submodel local though!) | ||
| point = geometry_data->vert[target_vertex].world; | ||
|
|
||
| point *= m_modelScale.next() * m_modular_curves.get_output(VolumeModularCurveOutput::SCALE_MULT, curveSource, &m_modular_curve_instance); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return pointCompensateForOffsetAndRotOffset(point, orientation, | ||
| m_modular_curves.get_output(VolumeModularCurveOutput::OFFSET_ROT, curveSource, &m_modular_curve_instance), | ||
| m_modular_curves.get_output(VolumeModularCurveOutput::POINT_TO_ROT, curveSource, &m_modular_curve_instance)); | ||
| } | ||
|
|
||
| void ModelSurfaceVolume::parse() { | ||
| if (optional_string("+Scale:")) { | ||
| m_modelScale = ::util::ParsedRandomFloatRange::parseRandomRange(); | ||
| } | ||
|
|
||
| ParticleVolume::parseCommon(); | ||
|
|
||
| m_modular_curves.parse("$Volume Curve:"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #pragma once | ||
|
|
||
| #include "particle/ParticleVolume.h" | ||
| #include "particle/ParticleEffect.h" | ||
|
|
||
| namespace particle { | ||
| class ModelSurfaceVolume : public ParticleVolume { | ||
| ::util::ParsedRandomFloatRange m_modelScale; | ||
| enum class VolumeModularCurveOutput : uint8_t {SCALE_MULT, OFFSET_ROT, POINT_TO_ROT, NUM_VALUES}; | ||
|
|
||
| constexpr static auto modular_curve_definition = ParticleEffect::modular_curves_definition.derive_modular_curves_subset<float, VolumeModularCurveOutput>( | ||
| std::array { | ||
| std::pair { "Scale Mult", VolumeModularCurveOutput::SCALE_MULT }, | ||
| std::pair { "Offset Rotate Around Fvec", VolumeModularCurveOutput::OFFSET_ROT }, | ||
| std::pair { "Point To Rotate Around Fvec", VolumeModularCurveOutput::POINT_TO_ROT } | ||
| }, | ||
| std::pair { "Fraction Particles Spawned", modular_curves_self_input{}}); | ||
|
|
||
| public: | ||
| MODULAR_CURVE_SET(m_modular_curves, modular_curve_definition); | ||
|
|
||
| private: | ||
| modular_curves_entry_instance m_modular_curve_instance; | ||
|
|
||
| public: | ||
| explicit ModelSurfaceVolume(); | ||
|
|
||
| vec3d sampleRandomPoint(const matrix &orientation, decltype(ParticleEffect::modular_curves_definition)::input_type_t source, float particlesFraction, const EffectHost& host) override; | ||
| void parse() override; | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.