Skip to content

Commit

Permalink
Merge pull request #66 from Tresjs/feature/65-vector-2-support
Browse files Browse the repository at this point in the history
feat: add vector 2 support
  • Loading branch information
alvarosabu authored Nov 4, 2023
2 parents 1305e57 + 1c067ff commit 7638404
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
13 changes: 7 additions & 6 deletions playground/src/pages/folders.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
import { BasicShadowMap, SRGBColorSpace, NoToneMapping, Vector3 } from 'three'
import { BasicShadowMap, SRGBColorSpace, NoToneMapping, Vector3, Vector2 } from 'three'
import { OrbitControls, Sphere } from '@tresjs/cientos'
Expand All @@ -17,12 +17,13 @@ const gl = {
}
const { position } = useControls('camera', {
position: new Vector3(3, 3, 3),
position: new Vector3(3, 2, 3),
/* delay: new Vector2(1.5, 3.5), */
})
const { position: lightPosition } = useControls('light', {
/* const { position: lightPosition } = useControls('light', {
position: new Vector3(3, 3, 3),
})
}) */
</script>

<template>
Expand All @@ -36,10 +37,10 @@ const { position: lightPosition } = useControls('light', {
<Sphere>
<TresMeshToonMaterial />
</Sphere>
<TresDirectionalLight
<!-- <TresDirectionalLight
:args="[0xffffff, 1]"
:position-x="lightPosition.x"
/>
/> -->
<TresAmbientLight :intensity="1" />
</TresCanvas>
</template>
2 changes: 1 addition & 1 deletion playground/src/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { Vector3 } from 'three'
import { Vector3, Vector2 } from 'three'
import { TresCanvas } from '@tresjs/core'
import { OrbitControls } from '@tresjs/cientos'
Expand Down
4 changes: 2 additions & 2 deletions src/components/VectorControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ watch(mouse.x, (newValue) => {
<div
v-for="(_subcontrol, $index) in vector"
:key="label + $index"
class="flex items-center w-1/3 bg-gray-100 rounded"
:class="{ 'w-2/5': focused === $index }"
class="flex items-center bg-gray-100 rounded"
:class="{ 'w-2/5': focused === $index, 'w-1/3': isVector3(control.value), 'w-1/2': isVector2(control.value) }"
>
<span
v-if="labels[$index] && isVector"
Expand Down
4 changes: 2 additions & 2 deletions src/utils/is.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function isVector2(obj: { x: number; y: number; z: number }) {
return obj && typeof obj.x === 'number' && typeof obj.y === 'number' && typeof obj.z === 'undefined'
export function isVector2(obj: { x: number; y: number }) {
return obj && typeof obj.x === 'number' && typeof obj.y === 'number'
}

export function isVector3(obj: { x: number; y: number; z: number }) {
Expand Down
7 changes: 6 additions & 1 deletion src/utils/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isVector3 } from '.'
import { isVector2, isVector3 } from '.'

export interface Vector3Prop { x: number; y: number; z: number }
export interface Vector2Prop { x: number; y: number }
export type SizeFlexibleParams =
| number[]
| {
Expand Down Expand Up @@ -29,6 +30,10 @@ export function normalizeVectorFlexibleParam(value: VectorFlexibleParams): Array
const { x, y, z } = value as Vector3Prop
return [x, y, z]
}
if (isVector2(value as Vector2Prop)) {
const { x, y } = value as Vector2Prop
return [x, y]
}
return value as Array<number>
}

0 comments on commit 7638404

Please sign in to comment.