瀏覽代碼

fix(core): allow comments inside TresInstance

Madjid Taha 2 年之前
父節點
當前提交
471c6f47d3
共有 2 個文件被更改,包括 3 次插入1 次删除
  1. 1 0
      packages/tres/src/components/TheBasic.vue
  2. 2 1
      packages/tres/src/core/useInstanceCreator/index.ts

+ 1 - 0
packages/tres/src/components/TheBasic.vue

@@ -35,6 +35,7 @@ onLoop(({ elapsed }) => {
       <TresMesh ref="sphereRef" :position="[0, 4, 0]" cast-shadow>
       <TresMesh ref="sphereRef" :position="[0, 4, 0]" cast-shadow>
         <TresSphereGeometry />
         <TresSphereGeometry />
         <TresMeshToonMaterial color="#FBB03B" />
         <TresMeshToonMaterial color="#FBB03B" />
+        <!-- <TresMeshToonMaterial color="#FBB03B" /> -->
       </TresMesh>
       </TresMesh>
       <TresDirectionalLight :position="[0, 8, 4]" :intensity="0.7" cast-shadow />
       <TresDirectionalLight :position="[0, 8, 4]" :intensity="0.7" cast-shadow />
       <TresMesh :rotation="[-Math.PI / 2, 0, 0]" receive-shadow>
       <TresMesh :rotation="[-Math.PI / 2, 0, 0]" receive-shadow>

+ 2 - 1
packages/tres/src/core/useInstanceCreator/index.ts

@@ -159,10 +159,11 @@ export function useInstanceCreator(prefix: string) {
   function createInstanceFromVNode(vnode: TresVNode): TresInstance | TresInstance[] | undefined {
   function createInstanceFromVNode(vnode: TresVNode): TresInstance | TresInstance[] | undefined {
     const fragmentRegex = /^Symbol\(Fragment\)$/g
     const fragmentRegex = /^Symbol\(Fragment\)$/g
     const textRegex = /^Symbol\(Text\)$/g
     const textRegex = /^Symbol\(Text\)$/g
+    const commentRegex = /^Symbol\(Comment\)$/g
     // Check if the vnode is a Fragment
     // Check if the vnode is a Fragment
     if (fragmentRegex.test(vnode.type.toString())) {
     if (fragmentRegex.test(vnode.type.toString())) {
       return vnode.children.map(child => createInstanceFromVNode(child as TresVNode)) as TresInstance[]
       return vnode.children.map(child => createInstanceFromVNode(child as TresVNode)) as TresInstance[]
-    } else if (textRegex.test(vnode.type.toString())) {
+    } else if (textRegex.test(vnode.type.toString()) || commentRegex.test(vnode.type.toString())) {
       return
       return
     } else {
     } else {
       const vNodeType = ((vnode.type as TresVNodeType).name as string).replace(prefix, '')
       const vNodeType = ((vnode.type as TresVNodeType).name as string).replace(prefix, '')