-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
feat(environment): enhance environment and background props #590
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ import { | |
CubeReflectionMapping, | ||
CubeTextureLoader, | ||
EquirectangularReflectionMapping, | ||
Euler, | ||
Vector3, | ||
} from 'three' | ||
import { RGBELoader } from 'three-stdlib' | ||
import { computed, ref, toRefs, unref, watch } from 'vue' | ||
|
@@ -28,7 +30,11 @@ const PRESET_ROOT = 'https://raw.githubusercontent.com/Tresjs/assets/main/textur | |
* background = false, | ||
* path = undefined, | ||
* preset = undefined, | ||
* colorSpace = undefined, | ||
* colorSpace = 'srgb', | ||
* backgroundIntensity = 1, | ||
* environmentIntensity = 1, | ||
* backgroundRotation = [0, 0, 0], | ||
* environmentRotation = [0, 0, 0], | ||
* @param {Ref<WebGLCubeRenderTarget | null>} fbo - The framebuffer object | ||
* @return {Promise<Ref<Texture | CubeTexture | null>>} The loaded texture | ||
*/ | ||
|
@@ -44,6 +50,10 @@ export async function useEnvironment( | |
files = ref([]), | ||
path = ref(''), | ||
background, | ||
backgroundIntensity = ref(1), | ||
environmentIntensity = ref(1), | ||
backgroundRotation = ref([0, 0, 0]), | ||
environmentRotation = ref([0, 0, 0]), | ||
} = toRefs(options) | ||
|
||
watch(options, () => { | ||
|
@@ -105,6 +115,67 @@ export async function useEnvironment( | |
immediate: true, | ||
}) | ||
|
||
watch(() => backgroundIntensity?.value, (value) => { | ||
if (scene.value && value) { | ||
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.
|
||
scene.value.backgroundIntensity = value | ||
} | ||
}, { | ||
immediate: true, | ||
}) | ||
|
||
watch(() => environmentIntensity?.value, (value) => { | ||
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.
|
||
if (scene.value && value) { | ||
scene.value.environmentIntensity = value | ||
} | ||
}, { | ||
immediate: true, | ||
}) | ||
|
||
watch(() => backgroundRotation?.value, (value) => { | ||
if (scene.value && value) { | ||
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.
|
||
// TODO: would be nice to abstract this to a function on @tresjs/core | ||
if (value instanceof Euler) { | ||
scene.value.backgroundRotation = value | ||
} | ||
else if (Array.isArray(value)) { | ||
scene.value.backgroundRotation = new Euler(value[0], value[1], value[2]) | ||
} | ||
else if (typeof value === 'number') { | ||
scene.value.backgroundRotation = new Euler(value, value, value) | ||
} | ||
else if (value instanceof Vector3) { | ||
scene.value.backgroundRotation = new Euler(value.x, value.y, value.z) | ||
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. (non-blocking) This branch could be removed. The next predicate will match |
||
} | ||
else if (typeof value === 'object' && 'x' in value && 'y' in value && 'z' in value) { | ||
scene.value.backgroundRotation = new Euler(value.x, value.y, value.z) | ||
} | ||
} | ||
}, { | ||
immediate: true, | ||
}) | ||
|
||
watch(() => environmentRotation?.value, (value) => { | ||
if (scene.value && value) { | ||
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.
|
||
if (value instanceof Euler) { | ||
scene.value.environmentRotation = value | ||
} | ||
else if (Array.isArray(value)) { | ||
scene.value.environmentRotation = new Euler(value[0], value[1], value[2]) | ||
} | ||
else if (typeof value === 'number') { | ||
scene.value.environmentRotation = new Euler(value, value, value) | ||
} | ||
else if (value instanceof Vector3) { | ||
scene.value.environmentRotation = new Euler(value.x, value.y, value.z) | ||
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. (non-blocking) This branch could be removed. The next predicate will match |
||
} | ||
else if (typeof value === 'object' && 'x' in value && 'y' in value && 'z' in value) { | ||
scene.value.environmentRotation = new Euler(value.x, value.y, value.z) | ||
} | ||
} | ||
}, { | ||
immediate: true, | ||
}) | ||
|
||
watch(() => preset?.value, async (value) => { | ||
if (value && value in environmentPresets) { | ||
const _path = PRESET_ROOT | ||
|
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.
In the playground, changing
environmentRotation
doesn't seem to have an effect.I was expecting that changing
environmentRotation
would rotate the material map similar to this THREE demo, whenbackgroundRotationX
andsyncMaterial
are checked (though not in sync with the background rotation).