Skip to content

Commit

Permalink
feat: buffergeometry setAttribute logic
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Mar 23, 2023
1 parent 0ccf3ea commit beee7b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions playground/src/App.vue
Original file line number Diff line number Diff line change
@@ -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>

17 changes: 7 additions & 10 deletions playground/src/components/TheParticles.vue
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -52,7 +51,7 @@ const shader = {
},
}
const firefliesCount = 30
const firefliesCount = 3000
const positionArray = new Float32Array(firefliesCount * 3)
const scaleArray = new Float32Array(firefliesCount)
Expand All @@ -70,16 +69,14 @@ 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>
<TresBufferGeometry :position="[positionArray, 3]" :a-scale="[scaleArray, 1]" />
<TresShaderMaterial v-bind="shader" />
</TresPoints>
<TresDirectionalLight :position="[0, 2, 4]" :intensity="1" cast-shadow />
</TresScene>
</TresCanvas>
</template>
11 changes: 10 additions & 1 deletion src/core/nodeOps.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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('-')
Expand Down

0 comments on commit beee7b3

Please sign in to comment.