Quellcode durchsuchen

docs: added primitive (#398)

* docs: added primitive

* docs: fix grammar

* docs: fix grammar

* docs: fix grammar abstraction

* docs: fix grammar
Alvaro Saburido vor 1 Jahr
Ursprung
Commit
a4c8785ccd
3 geänderte Dateien mit 60 neuen und 7 gelöschten Zeilen
  1. 1 0
      docs/.vitepress/config.ts
  2. 47 0
      docs/advanced/primitive.md
  3. 12 7
      docs/examples/load-models.md

+ 1 - 0
docs/.vitepress/config.ts

@@ -80,6 +80,7 @@ export default defineConfig({
 
 
         items: [
         items: [
           { text: 'Extending', link: '/advanced/extending' },
           { text: 'Extending', link: '/advanced/extending' },
+          { text: 'primitive', link: '/advanced/primitive' },
           {
           {
             text: 'Caveats',
             text: 'Caveats',
             link: '/advanced/caveats',
             link: '/advanced/caveats',

+ 47 - 0
docs/advanced/primitive.md

@@ -0,0 +1,47 @@
+# Primitives
+
+The `<primitive />` component is a versatile low-level component in TresJS that allows you to directly use any Three.js object within your Vue application without an abstraction. It acts as a bridge between Vue's reactivity system and Three.js's scene graph.
+
+## Usage
+
+```html
+<script setup lang="ts">
+  // Import necessary Three.js classes
+  import { Mesh, BoxGeometry, MeshBasicMaterial } from 'three';
+
+  // Create a box geometry and a basic material
+  const geometry = new BoxGeometry(1, 1, 1);
+  const material = new MeshBasicMaterial({ color: 0x00ff00 });
+
+  // Create a mesh with the geometry and material
+  const meshWithMaterial = new Mesh(geometry, material);
+</script>
+
+<template>
+  <TresCanvas>
+    <primitive :object="meshWithMaterial" />
+  </TresCanvas>  
+</template>
+```
+
+## Props
+
+`object`: This prop expects a Three.js Object3D or any of its derived classes. It is the primary object that the `<primitive />` component will render. In the updated example, a `Mesh` object with an associated `Material` is passed to this prop.
+
+## Usage with Models 
+
+The `<primitive />` component is especially useful for rendering complex objects like models loaded from external sources. The following example shows how to load a model from a GLTF file and render it using the `<primitive />` component.
+
+```html
+<script lang="ts" setup>
+import { useGLTF } from '@tresjs/cientos'
+
+const { nodes } = await useGLTF('/models/AkuAku.gltf')
+</script>
+
+<TresCanvas>
+  <Suspense>
+    <primitive :object="nodes.AkuAku" />
+  </Suspense>
+</TresCanvas>
+```

+ 12 - 7
docs/examples/load-models.md

@@ -23,7 +23,7 @@ import { GLTFLoader } from 'three/addons/loaders/GLTFLoader'
 const { scene } = await useLoader(GLTFLoader, '/models/AkuAku.gltf')
 const { scene } = await useLoader(GLTFLoader, '/models/AkuAku.gltf')
 ```
 ```
 
 
-Then you can pass the model scene to a TresJS `primitive`:
+Then you can pass the model scene to a TresJS [`primitive`](/advanced/primitive) component to render it:
 
 
 ```html{3}
 ```html{3}
 <TresCanvas>
 <TresCanvas>
@@ -39,7 +39,7 @@ Notice in the example above that we are using the `Suspense` component to wrap t
 
 
 ## Using `useGLTF`
 ## Using `useGLTF`
 
 
-A more convenient way of loading models is using the `useGLTF` composable available from [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos) package.
+A more convenient way of loading models is using the `useGLTF` composable available from the [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos) package.
 
 
 ```ts
 ```ts
 import { useGLTF } from '@tresjs/cientos'
 import { useGLTF } from '@tresjs/cientos'
@@ -63,8 +63,13 @@ import { useGLTF } from '@tresjs/cientos'
 
 
 const { scene, nodes, animations, materials } = await useGLTF('/models/AkuAku.gltf', { draco: true })
 const { scene, nodes, animations, materials } = await useGLTF('/models/AkuAku.gltf', { draco: true })
 </script>
 </script>
+
 <template>
 <template>
-  <TresCanvas clear-color="#82DBC5" shadows alpha>
+  <TresCanvas
+    clear-color="#82DBC5"
+    shadows
+    alpha
+  >
     <TresPerspectiveCamera :position="[11, 11, 11]" />
     <TresPerspectiveCamera :position="[11, 11, 11]" />
     <OrbitControls />
     <OrbitControls />
     <Suspense>
     <Suspense>
@@ -76,7 +81,7 @@ const { scene, nodes, animations, materials } = await useGLTF('/models/AkuAku.gl
 
 
 ## Using `GLTFModel`
 ## Using `GLTFModel`
 
 
-The `GLTFModel` component is a wrapper around `useGLTF` that's available from [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos) package.
+The `GLTFModel` component is a wrapper around `useGLTF` that's available from the [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos) package.
 
 
 ```vue{2,9}
 ```vue{2,9}
 <script setup lang="ts">
 <script setup lang="ts">
@@ -96,9 +101,9 @@ import { OrbitControls, GLTFModel } from '@tresjs/cientos'
 
 
 This particular approach is more straightforward but gives you less control over the model.
 This particular approach is more straightforward but gives you less control over the model.
 
 
-## useFBX
+## useFBX
 
 
-The `useFBX` composable is available from [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos) package.
+The `useFBX` composable is available from the [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos) package.
 
 
 ```ts
 ```ts
 import { useFBX } from '@tresjs/cientos'
 import { useFBX } from '@tresjs/cientos'
@@ -118,7 +123,7 @@ Then is as straightforward as adding the scene to your scene:
 
 
 ## FBXModel
 ## FBXModel
 
 
-The `FBXModel` component is a wrapper around `useFBX` that's available from [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos) package. It's similar usage to `GLTFModel`:
+The `FBXModel` component is a wrapper around `useFBX` that's available from the [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos) package. It's similar usage to `GLTFModel`:
 
 
 ```vue{2,9}
 ```vue{2,9}
 <script setup lang="ts">
 <script setup lang="ts">