Skip to content

Commit 906f2e1

Browse files
authored
fix: do not change pierced props case (#608)
1 parent 05069ab commit 906f2e1

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<script setup lang="ts">
2+
import { shallowRef } from 'vue'
3+
import { TresCanvas, useRenderLoop } from '@tresjs/core'
4+
5+
const x = shallowRef(1)
6+
const y = shallowRef(1)
7+
const z = shallowRef(1)
8+
const rx = shallowRef(1)
9+
const ry = shallowRef(1)
10+
const rz = shallowRef(1)
11+
const sx = shallowRef(1)
12+
const sy = shallowRef(1)
13+
const sz = shallowRef(1)
14+
const label = shallowRef('')
15+
16+
const refs = [x, y, z, rx, ry, rz, sx, sy, sz]
17+
const labels = [
18+
'position-x', 'position-y', 'position-z',
19+
'rotation-x', 'rotation-y', 'rotation-z',
20+
'scale-x', 'scale-y', 'scale-z',
21+
]
22+
23+
const PI2 = Math.PI * 2
24+
25+
useRenderLoop().onLoop(({ elapsed }) => {
26+
const i = Math.floor(elapsed % refs.length)
27+
refs[i].value = Math.cos(elapsed * Math.PI * 2)
28+
label.value = `${labels[i]} ${Math.trunc(refs[i].value * 10) / 10}`
29+
})
30+
</script>
31+
32+
<template>
33+
<div class="overlay">
34+
<p>Demonstrate pierced props</p>
35+
{{ label }}
36+
</div>
37+
<TresCanvas>
38+
<TresMesh
39+
:position-x="x"
40+
:position-y="y"
41+
:position-z="z"
42+
:rotation-x="rx"
43+
:rotation-y="ry"
44+
:rotation-z="rz"
45+
:scale-x="sx"
46+
:scale-y="sy"
47+
:scale-z="sz"
48+
>
49+
<TresBoxGeometry />
50+
<TresMeshNormalMaterial />
51+
</TresMesh>
52+
</TresCanvas>
53+
</template>
54+
55+
<style>
56+
.overlay {
57+
position: fixed;
58+
padding: 10px;
59+
font-family: sans-serif;
60+
}
61+
</style>

playground/src/router/routes/basic.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ export const basicRoutes = [
3434
name: 'Responsiveness',
3535
component: () => import('../../pages/basic/Responsiveness.vue'),
3636
},
37+
{
38+
path: '/basic/pierced-props',
39+
name: 'Pierced Props',
40+
component: () => import('../../pages/basic/PiercedProps.vue'),
41+
},
3742
]

src/core/nodeOps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export const nodeOps: () => RendererOptions<TresObject, TresObject | null> = ()
263263
const chain = key.split('-')
264264
target = chain.reduce((acc, key) => acc[kebabToCamel(key)], root)
265265
key = chain.pop() as string
266-
finalKey = key.toLowerCase()
266+
finalKey = key
267267
if (!target?.set) root = chain.reduce((acc, key) => acc[kebabToCamel(key)], root)
268268
}
269269
let value = nextValue

src/core/nodeOpts.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,22 @@ describe('nodeOps', () => {
193193
expect(node.castShadow === nextValue)
194194
})
195195

196+
it('patchProp should preserve ALL_CAPS_CASE in pierced props', () => {
197+
// Issue: https://github.com/Tresjs/tres/issues/605
198+
const {createElement, patchProp} = nodeOps()
199+
const node = createElement('TresMeshStandardMaterial', null, null, {})
200+
const allCapsKey = 'STANDARD'
201+
const allCapsUnderscoresKey = 'USE_UVS'
202+
const allCapsValue = 'hello'
203+
const allCapsUnderscoresValue = 'goodbye'
204+
205+
patchProp(node, 'defines-' + allCapsKey, null, allCapsValue)
206+
patchProp(node, 'defines-' + allCapsUnderscoresKey, null, allCapsUnderscoresValue)
207+
208+
expect(node.defines[allCapsKey]).equals(allCapsValue)
209+
expect(node.defines[allCapsUnderscoresKey]).equals(allCapsUnderscoresValue)
210+
})
211+
196212
it('parentNode: returns parent of a node', async () => {
197213
// Setup
198214
const parent: TresObject = new Scene()

0 commit comments

Comments
 (0)