浏览代码

feat: buffergeometry setAttribute logic

alvarosabu 2 年之前
父节点
当前提交
beee7b3d56
共有 3 个文件被更改,包括 19 次插入13 次删除
  1. 2 2
      playground/src/App.vue
  2. 7 10
      playground/src/components/TheParticles.vue
  3. 10 1
      src/core/nodeOps.ts

+ 2 - 2
playground/src/App.vue

@@ -1,8 +1,8 @@
 <script setup lang="ts">
-import TheExperiment from './components/gltf/TheExperiment.vue'
+import TheParticles from './components/TheParticles.vue'
 </script>
 
 <template>
-  <TheExperiment />
+  <TheParticles />
 </template>
 

+ 7 - 10
playground/src/components/TheParticles.vue

@@ -1,16 +1,15 @@
 <script setup lang="ts">
 import { reactive } from 'vue'
-import { OrbitControls } from '@tresjs/cientos/src'
-import { TresCanvas } from '../core/useRenderer/component'
+import { OrbitControls } from '@tresjs/cientos'
+import { TresCanvas, useRenderLoop } from '/@/'
 import { AdditiveBlending } from 'three'
-import { useRenderLoop } from '../core/useRenderLoop'
+
 /* import { OrbitControls, GLTFModel } from '@tresjs/cientos' */
 
-const state = reactive({
-  clearColor: 'teal',
+const gl = reactive({
+  clearColor: 'black',
   shadows: true,
   alpha: false,
-  physicallyCorrectLights: true,
 })
 
 const shader = {
@@ -52,7 +51,7 @@ const shader = {
   },
 }
 
-const firefliesCount = 30
+const firefliesCount = 3000
 const positionArray = new Float32Array(firefliesCount * 3)
 const scaleArray = new Float32Array(firefliesCount)
 
@@ -70,9 +69,8 @@ onLoop(({ elapsed }) => {
 })
 </script>
 <template>
-  <TresCanvas v-bind="state">
+  <TresCanvas v-bind="gl">
     <TresPerspectiveCamera :position="[5, 5, 5]" :fov="45" :near="0.1" :far="1000" :look-at="[-8, 3, -3]" />
-    <TresScene>
       <OrbitControls />
       <TresAmbientLight :intensity="0.5" />
       <TresPoints>
@@ -80,6 +78,5 @@ onLoop(({ elapsed }) => {
         <TresShaderMaterial v-bind="shader" />
       </TresPoints>
       <TresDirectionalLight :position="[0, 2, 4]" :intensity="1" cast-shadow />
-    </TresScene>
   </TresCanvas>
 </template>

+ 10 - 1
src/core/nodeOps.ts

@@ -1,4 +1,4 @@
-import { Mesh } from 'three'
+import { BufferAttribute, Mesh } from 'three'
 import { useCamera, useRaycaster, useRenderLoop, useLogger } from '/@/composables'
 import { RendererOptions } from 'vue'
 import { catalogue } from './catalogue'
@@ -131,6 +131,15 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
         node.parent = scene as TresObject
       }
 
+      if(root.type === 'BufferGeometry') {
+        const chain = key.split('-')
+        key = chain.pop() as string
+        root.setAttribute(
+          kebabToCamel(key), 
+          new BufferAttribute(...(nextValue as ConstructorParameters<typeof BufferAttribute>))
+        )
+      }
+
       // Traverse pierced props (e.g. foo-bar=value => foo.bar = value)
       if (key.includes('-') && target === undefined) {
         const chain = key.split('-')