Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use CubeTextureLoader correctly with array of files #807

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
"access": "public"
},
"scripts": {
"dev": "cd playground && npm run dev",
"dev": "cd playground/vue && npm run dev",
"dev:nuxt": "cd playground/nuxt && npm run dev",
"build": "vite build",
"playground": "cd playground && npm run dev",
"test": "vitest",
"test:ci": "vitest run",
"test:ui": "vitest --ui --coverage.enabled=true",
Expand Down
8 changes: 4 additions & 4 deletions playground/.eslintrc-auto-import.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"ComponentPublicInstance": true,
"ComputedRef": true,
"EffectScope": true,
"ExtractDefaultPropTypes": true,
"ExtractPropTypes": true,
"ExtractPublicPropTypes": true,
"InjectionKey": true,
"PropType": true,
"Ref": true,
Expand Down Expand Up @@ -59,9 +62,6 @@
"watch": true,
"watchEffect": true,
"watchPostEffect": true,
"watchSyncEffect": true,
"ExtractDefaultPropTypes": true,
"ExtractPropTypes": true,
"ExtractPublicPropTypes": true
"watchSyncEffect": true
}
}
21 changes: 0 additions & 21 deletions playground/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,7 @@ export {}
/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
AkuAku: typeof import('./src/components/AkuAku.vue')['default']
AnimatedObjectUseUpdate: typeof import('./src/components/AnimatedObjectUseUpdate.vue')['default']
BlenderCube: typeof import('./src/components/BlenderCube.vue')['default']
Box: typeof import('./src/components/Box.vue')['default']
DirectiveSubComponent: typeof import('./src/components/DirectiveSubComponent.vue')['default']
DynamicModel: typeof import('./src/components/DynamicModel.vue')['default']
FBOCube: typeof import('./src/components/FBOCube.vue')['default']
GraphPane: typeof import('./src/components/GraphPane.vue')['default']
LocalOrbitControls: typeof import('./src/components/LocalOrbitControls.vue')['default']
Overlay: typeof import('./src/components/Overlay.vue')['default']
OverlayInfo: typeof import('./src/components/OverlayInfo.vue')['default']
PbrSphere: typeof import('./src/components/PbrSphere.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
TakeOverLoopExperience: typeof import('./src/components/TakeOverLoopExperience.vue')['default']
TestResult: typeof import('./src/components/TestResult.vue')['default']
Tests: typeof import('./src/components/Tests.vue')['default']
TestSphere: typeof import('./src/components/TestSphere.vue')['default']
Text3D: typeof import('./src/components/Text3D.vue')['default']
TheCameraOperator: typeof import('./src/components/TheCameraOperator.vue')['default']
TheExperience: typeof import('./src/components/TheExperience.vue')['default']
TheSphere: typeof import('./src/components/TheSphere.vue')['default']
UgglyBunny: typeof import('./src/components/UgglyBunny.vue')['default']
}
}
2 changes: 2 additions & 0 deletions playground/nuxt/.github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [alvarosabu]
ko_fi: alvarosaburido
27 changes: 27 additions & 0 deletions playground/nuxt/.github/workflows/actions/pnpm/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# From https://github.com/remirror/template/blob/4f8c5f5629a081217672a8cce1df085510f43913/.github/actions/pnpm/action.yml
name: pnpm installation
description: Install and audit dependencies for pnpm
inputs:
cache: # id of input
description: The location of the pnpm cache
required: true
default: .pnpm-store
version: # id of input
description: The version to use
required: false
default: 6.10.0

runs:
using: composite
steps:
- name: install pnpm
run: npm install pnpm@${{ inputs.version }} -g
shell: bash

- name: setup pnpm config
run: pnpm config set store-dir ${{ inputs.cache }}
shell: bash

- name: install dependencies
run: pnpm install --shamefully-hoist
shell: bash
17 changes: 17 additions & 0 deletions playground/nuxt/.github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Lint PR

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23 changes: 23 additions & 0 deletions playground/nuxt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Nuxt dev/build outputs
.output
.nuxt
.nitro
.cache
dist

# Node dependencies
node_modules

# Logs
logs
*.log

# Misc
.DS_Store
.fleet
.idea

# Local env files
.env
.env.*
!.env.example
2 changes: 2 additions & 0 deletions playground/nuxt/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shamefully-hoist=true
strict-peer-dependencies=false
3 changes: 3 additions & 0 deletions playground/nuxt/.stackblitzrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"installDependencies": true
}
21 changes: 21 additions & 0 deletions playground/nuxt/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022-present, (alvarosabu) Alvaro Saburido and Tres contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
67 changes: 67 additions & 0 deletions playground/nuxt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
![repo-banner](/public/repo-banner.png)

# TresJS 🚀 Starter + Nuxt

> Quick start repo for [Nuxt](https://nuxt.com) projects with [TresJS](https://tresjs.org) integration via [`@tresjs/nuxt` module](https://tresjs.org/guide/nuxt.html).

Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.

## Setup

Make sure to install the dependencies:

```bash
# npm
npm install

# pnpm
pnpm install

# yarn
yarn install
```

## Development Server

Start the development server on `http://localhost:3000`:

```bash
# npm
npm run dev

# pnpm
pnpm run dev

# yarn
yarn dev
```

## Production

Build the application for production:

```bash
# npm
npm run build

# pnpm
pnpm run build

# yarn
yarn build
```

Locally preview production build:

```bash
# npm
npm run preview

# pnpm
pnpm run preview

# yarn
yarn preview
```

Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.
29 changes: 29 additions & 0 deletions playground/nuxt/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script setup lang="ts">
import { BasicShadowMap, NoToneMapping, SRGBColorSpace } from 'three'

const gl = {
clearColor: '#c0ffee',
shadows: true,
alpha: false,
shadowMapType: BasicShadowMap,
outputColorSpace: SRGBColorSpace,
toneMapping: NoToneMapping,
}
</script>

<template>
<div style="height: 100vh">
<TresCanvas v-bind="gl">
<TheExperience />
</TresCanvas>
</div>
</template>

<style>
html,
body {
margin: 0;
padding: 0;
overflow: hidden;
}
</style>
41 changes: 41 additions & 0 deletions playground/nuxt/components/EnvironmentLocal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script setup lang="ts">
import { CubeReflectionMapping, type CubeTexture, CubeTextureLoader, EquirectangularReflectionMapping, type Texture } from 'three'
import type { LoaderProto } from '@tresjs/core'
import { useLoader, useTresContext } from '@tresjs/core'
import { RGBELoader } from 'three-stdlib'

/* const files = ref(['/px.jpg', '/nx.jpg', '/py.jpg', '/ny.jpg', '/pz.jpg', '/nz.jpg']) */
const files = ref('venice/venice_sunset_1k.hdr')
const path = 'https://raw.githubusercontent.com/Tresjs/assets/main/textures/hdr/'
const texture: Ref<Texture | CubeTexture | null> = ref(null)

const { scene } = useTresContext()

const isCubeMap = computed(() => Array.isArray((files as Ref<string[]>).value))
const result = ref()
const loader = computed(() => isCubeMap.value ? CubeTextureLoader as unknown as LoaderProto<CubeTexture | RGBELoader> : RGBELoader as unknown as LoaderProto<CubeTexture | RGBELoader>)

result.value = await useLoader<CubeTexture | RGBELoader>(
loader.value,
isCubeMap.value ? [...unref(files)] : unref(files),
(loader: any) => {
if (path) { loader.setPath(unref(path)) }
/* if (colorSpace) loader.colorSpace = colorSpace */
},
)
if (result.value) {
texture.value = result.value
if (texture.value) {
texture.value.mapping = isCubeMap.value ? CubeReflectionMapping : EquirectangularReflectionMapping
scene.value.environment = texture.value
scene.value.background = texture.value
}
}
</script>

<template>
<TresMesh>
<TresSphereGeometry args="[1, 64, 32]" />
<TresMeshStandardMaterial :envMap="texture" />
</TresMesh>
</template>
19 changes: 19 additions & 0 deletions playground/nuxt/components/TheExperience.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script setup lang="ts">

</script>

<template>
<TresPerspectiveCamera
:position="[-5.3, 8.3, 10.6]"
:look-at="[0, 0, 0]"
/>
<Suspense>
<EnvironmentLocal />
</Suspense>
<TresMesh :position="[0, 2, 0]">
<TresBoxGeometry />
<TresMeshNormalMaterial />
</TresMesh>
<TresGridHelper />
<OrbitControls />
</template>
21 changes: 21 additions & 0 deletions playground/nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
import { resolve } from 'pathe'

export default defineNuxtConfig({
modules: ['@tresjs/nuxt'],
devtools: { enabled: true },

vite: {
resolve: {
alias: {
'@tresjs/core': resolve(__dirname, '../../src/'),
},
},
},

tres: {
glsl: true,
},

compatibilityDate: '2024-08-30',
})
36 changes: 36 additions & 0 deletions playground/nuxt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@tresjs/nuxt-starter",
"type": "module",
"version": "1.0.0",
"description": "Quick Nuxt starter template for TresJS",
"author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
"license": "MIT",
"keywords": [
"vue",
"tresjs",
"webgl",
"vite",
"3d",
"threejs",
"three",
"threejs-vue"
],
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
},
"devDependencies": {
"@nuxt/devtools": "latest",
"@tresjs/cientos": "^4.0.0",
"@tresjs/core": "workspace:^",
"@tresjs/nuxt": "3.0.4",
"@tresjs/post-processing": "^0.7.1",
"@types/node": "^22.5.1",
"@types/three": "^0.167.2",
"nuxt": "^3.5.2",
"three": "^0.168.0"
}
}
Loading
Loading