Przeglądaj źródła

fix: special handling vector props

Randysheng 2 lat temu
rodzic
commit
d21c1617e1
1 zmienionych plików z 14 dodań i 0 usunięć
  1. 14 0
      src/core/nodeOps.ts

+ 14 - 0
src/core/nodeOps.ts

@@ -7,7 +7,13 @@ import { TresObject } from '../types'
 import { isHTMLTag, kebabToCamel } from '../utils'
 import { isHTMLTag, kebabToCamel } from '../utils'
 
 
 const onRE = /^on[^a-z]/
 const onRE = /^on[^a-z]/
+
+const vectorProps = /(position|rotation|scale)-(x|y|z)/
+const colorProps = /color-(r|g|b)/
+
 export const isOn = (key: string) => onRE.test(key)
 export const isOn = (key: string) => onRE.test(key)
+export const isVectorProps = (key: string) => vectorProps.test(key)
+export const isColorProps = (key: string) => colorProps.test(key)
 
 
 function noop(fn: string): any {
 function noop(fn: string): any {
   fn
   fn
@@ -92,6 +98,13 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
         return
         return
       }
       }
 
 
+      // First handle the Vector props, like: postion、rotation、scale、color.
+      if (isVectorProps(key) || isColorProps(key)) {
+        const chain = key.split('-')
+        root[chain[0]][chain[1]] = nextValue
+        return
+      }
+
       // Traverse pierced props (e.g. foo-bar=value => foo.bar = value)
       // Traverse pierced props (e.g. foo-bar=value => foo.bar = value)
       if (key.includes('-') && target === undefined) {
       if (key.includes('-') && target === undefined) {
         const chain = key.split('-')
         const chain = key.split('-')
@@ -104,6 +117,7 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
         node.events[key] = nextValue
         node.events[key] = nextValue
       }
       }
       let value = nextValue
       let value = nextValue
+
       if (value === '') value = true
       if (value === '') value = true
       // Set prop, prefer atomic methods if applicable
       // Set prop, prefer atomic methods if applicable
       if (isFunction(target)) {
       if (isFunction(target)) {