Skip to content

Commit

Permalink
fix: correct casing of key names when pierced props
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Apr 12, 2023
1 parent 45cdebb commit b6a808f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
12 changes: 10 additions & 2 deletions playground/src/components/VectorSetProps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ const state = reactive({
outputEncoding: sRGBEncoding,
toneMapping: NoToneMapping,
})
const context = ref(null)
watchEffect(() => {
if (context.value) {
console.log(context.value?.state?.scene)
}
})
</script>
<template>
<TresCanvas v-bind="state">
<TresCanvas v-bind="state" ref="context">
<TresPerspectiveCamera
:position-x="5"
:position-y="5"
Expand All @@ -36,7 +44,7 @@ const state = reactive({
:rotation-x="Math.PI * 1.5"
:rotation-y="Math.PI * 0.6"
:rotation-z="Math.PI * 0.2"
:position-y="1"
:position-y="5"
:position-z="-2"
cast-shadow
>
Expand Down
2 changes: 1 addition & 1 deletion playground/src/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts"></script>
<template>
<Suspense>
<TheEvents />
<VectorSetProps />
</Suspense>
</template>
12 changes: 6 additions & 6 deletions src/core/nodeOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
if (node) {
let root = node
let key = prop
const camelKey = kebabToCamel(key)
let target = root?.[camelKey]
let finalKey = kebabToCamel(key)
let target = root?.[finalKey]

if (!node.parent) {
node.parent = scene as TresObject
Expand All @@ -97,7 +97,7 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
const chain = key.split('-')
target = chain.reduce((acc, key) => acc[kebabToCamel(key)], root)
key = chain.pop() as string

finalKey = key.toLowerCase()
if (!target?.set) root = chain.reduce((acc, key) => acc[kebabToCamel(key)], root)
}
if (isOn(key)) {
Expand All @@ -107,11 +107,11 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
if (value === '') value = true
// Set prop, prefer atomic methods if applicable
if (isFunction(target)) {
if (Array.isArray(value)) node[camelKey](...value)
else node[camelKey](value)
if (Array.isArray(value)) node[finalKey](...value)
else node[finalKey](value)
return
}
if (!target?.set && !isFunction(target)) root[camelKey] = value
if (!target?.set && !isFunction(target)) root[finalKey] = value
else if (target.constructor === value.constructor && target?.copy) target?.copy(value)
else if (Array.isArray(value)) target.set(...value)
else if (!target.isColor && target.setScalar) target.setScalar(value)
Expand Down

0 comments on commit b6a808f

Please sign in to comment.