This repository was archived by the owner on Feb 1, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 47
fix: Smoke component #645
Open
JaimeTorrealba
wants to merge
5
commits into
main
Choose a base branch
from
Fix/smoke-component
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix: Smoke component #645
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ebb8350
fix: Smoke component
JaimeTorrealba 4751fa1
Merge branch 'main' into Fix/smoke-component
JaimeTorrealba 9dc158c
Merge branch 'main' into Fix/smoke-component
alvarosabu 0be64a7
Add: spreadX, spreadY and scale props.
JaimeTorrealba 5993eec
🔥 Remove unused imports
JaimeTorrealba 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,14 +30,6 @@ export interface SmokeProps { | |
| * @see https://threejs.org/docs/#api/en/materials/MeshStandardMaterial | ||
| */ | ||
| speed?: number | ||
| /** | ||
| * The base width. | ||
| * @default 4 | ||
| * @type {number} | ||
| * @memberof SmokeProps | ||
| * @see https://threejs.org/docs/#api/en/materials/MeshBasicMaterial | ||
| */ | ||
| width?: number | ||
| /** | ||
| * The base depth. | ||
| * @default 10 | ||
|
|
@@ -75,15 +67,17 @@ export interface SmokeProps { | |
| const props = withDefaults(defineProps<SmokeProps>(), { | ||
| opacity: 0.5, | ||
| speed: 0.4, | ||
| width: 10, | ||
| depth: 1.5, | ||
| segments: 20, | ||
| texture: 'https://raw.githubusercontent.com/Tresjs/assets/main/textures/clouds/defaultCloud.png', | ||
| color: '#ffffff', | ||
| depthTest: true, | ||
| depth: 0.3, | ||
| segments: 10, | ||
| texture: | ||
| 'https://raw.githubusercontent.com/Tresjs/assets/main/textures/clouds/defaultCloud.png', | ||
| color: '#f7f7f7', | ||
| depthTest: false, | ||
| }) | ||
|
|
||
| const { width, depth, segments, texture, color, depthTest, opacity, speed } = toRefs(props) | ||
| const { depth, segments, texture, color, depthTest, opacity, speed } = toRefs( | ||
| props, | ||
| ) | ||
|
|
||
| const smokeRef = shallowRef() | ||
| const groupRef = shallowRef() | ||
|
|
@@ -92,15 +86,13 @@ defineExpose({ | |
| instance: smokeRef, | ||
| }) | ||
|
|
||
| const smoke = [...[segments]].map((_, index) => ({ | ||
| x: width.value / 2 - Math.random() * width.value, | ||
| y: width.value / 2 - Math.random() * width.value, | ||
| scale: 0.4 + Math.sin(((index + 1) / segments.value) * Math.PI) * ((0.2 + Math.random()) * 10), | ||
| density: Math.max(0.2, Math.random()), | ||
| rotation: Math.max(0.002, 0.005 * Math.random()) * speed.value, | ||
| })) | ||
|
|
||
| const calculateOpacity = (scale: number, density: number): number => (scale / 6) * density * opacity.value | ||
| const smoke = computed(() => | ||
| Array.from({ length: segments.value }, (_, index) => ({ | ||
| x: (Math.random() - 0.5) * 0.5, | ||
| y: (Math.random() - 0.5) * 0.1, | ||
| scale: Math.sin((index + 1) / segments.value), | ||
| })), | ||
| ) | ||
|
|
||
| const { state: map } = useTexture(texture.value) | ||
|
|
||
|
|
@@ -111,8 +103,8 @@ const { onBeforeRender } = useLoop() | |
|
|
||
| onBeforeRender(() => { | ||
| if (smokeRef.value && camera.activeCamera.value && groupRef.value) { | ||
| groupRef.value?.children.forEach((child: Object3D, index: number) => { | ||
| child.rotation.z += smoke[index].rotation | ||
| groupRef.value?.children.forEach((child: Object3D) => { | ||
| child.rotation.z += Math.max(0.002, 0.005 * Math.random()) * speed.value | ||
| }) | ||
| smokeRef.value.lookAt(camera.activeCamera.value?.position) | ||
| // TODO: comment this until invalidate is back in the loop callback on v5 | ||
|
|
@@ -122,31 +114,22 @@ onBeforeRender(() => { | |
| </script> | ||
|
|
||
| <template> | ||
| <TresGroup | ||
| ref="smokeRef" | ||
| v-bind="$attrs" | ||
| > | ||
| <TresGroup | ||
| ref="groupRef" | ||
| :position="[0, 0, (segments / 2) * depth]" | ||
| > | ||
| <TresGroup ref="smokeRef"> | ||
| <TresGroup ref="groupRef" :position="[0, 0, (segments / 2) * depth]"> | ||
| <TresMesh | ||
| v-for="({ scale, x, y, density }, index) in smoke" | ||
| v-for="({ x, y }, index) in smoke" | ||
| :key="`${index}`" | ||
| :position="[x, y, -index * depth]" | ||
| > | ||
| <TresPlaneGeometry | ||
| :scale="[scale, scale, scale]" | ||
| :rotation="[0, 0, 0]" | ||
| /> | ||
| <TresPlaneGeometry /> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: What's the reasoning behind removing with and scale?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The big problem with the width and the scale was that, the randomness was wrong too large, this creates unstable component difficult to use and understand. I think with the previous comment (adding props to controls it) we solve it. The new implementation, treat it different but without actually removing it |
||
| <TresMeshStandardMaterial | ||
| :map="map" | ||
| :depth-test="depthTest" | ||
| :color-space="colorSpace" | ||
| :color="color" | ||
| :depth-write="false" | ||
| transparent | ||
| :opacity="calculateOpacity(scale, density)" | ||
| :opacity="opacity" | ||
| /> | ||
| </TresMesh> | ||
| </TresGroup> | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Is this a known math formula or just to introduce variation/randomness? Do you think it could be interesting for users to be able to tweak the hardcoded values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just introduce randomness/variation
I don't know, we can for instance make the "speed" prop as the whole math formula. But currently, you can control the randomness with the speed prop.
What is your advice? If you ask me I would say is fine (don't put all the weight on the user to create their random, just a simple prop, in my experience most user use the random or don't, set as 0)