|
|
hace 1 año | |
|---|---|---|
| .github | hace 1 año | |
| .idea | hace 1 año | |
| examples | hace 1 año | |
| plugins | hace 1 año | |
| scripts | hace 1 año | |
| src | hace 1 año | |
| website | hace 1 año | |
| .eslintignore | hace 3 años | |
| .eslintrc.cjs | hace 2 años | |
| .gitignore | hace 1 año | |
| .npmignore | hace 3 años | |
| CONTRIBUTING.md | hace 1 año | |
| LICENSE | hace 2 años | |
| NOTICE | hace 2 años | |
| README.md | hace 1 año | |
| package-lock.json | hace 1 año | |
| package.json | hace 1 año | |
| tsconfig.json | hace 1 año | |
| typedoc.json | hace 2 años | |
| vite.config.js | hace 1 año | |
A new way to work with three.js, 3D models and rendering on the web.
ThreePipe — Github — Examples — API Reference — WebGi
ThreePipe is a modern 3D framework built on top of three.js, written in TypeScript, designed to make creating high-quality, modular, and extensible 3D experiences on the web simple and enjoyable.
Key features include:
Checkout the documentation and guides on the threepipe website for more details.
Code samples and demos covering various usecases and test are present in the examples folder.
Try them: https://threepipe.org/examples/
View the source code by pressing the code button on the top left of the example page.
To make changes and run the example, click on the CodePen button on the top right of the source code.
Checkout the full Getting Started Guide on threepipe.org
To create a new project locally
And follow the instructions to create a new project.
### HTML/JS Quickstart (CDN)
```html
<canvas id="three-canvas" style="width: 800px; height: 600px;"></canvas>
<script type="module">
import {ThreeViewer, DepthBufferPlugin} from 'https://unpkg.com/threepipe@latest/dist/index.mjs'
const viewer = new ThreeViewer({canvas: document.getElementById('three-canvas')})
// Add some plugins
viewer.addPluginSync(new DepthBufferPlugin())
// Load an environment map
const envPromise = viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
const modelPromise = viewer.load('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
autoCenter: true,
autoScale: true,
})
Promise.all([envPromise, modelPromise]).then(([env, model]) => {
console.log('Loaded', model, env, viewer)
})
</script>
Check it in action: https://threepipe.org/examples/#html-js-sample/
Check out the details about the ThreeViewer API and more plugins.
The best way to use the viewer in react is to wrap it in a custom component.
Here is a sample react component in tsx to render a model with an environment map.
import React from 'react'
function ThreeViewerComponent({src, env}: {src: string, env: string}) {
const canvasRef = React.useRef(null)
React.useEffect(() => {
const viewer = new ThreeViewer({canvas: canvasRef.current})
const envPromise = viewer.setEnvironmentMap(env)
const modelPromise = viewer.load(src)
Promise.all([envPromise, modelPromise]).then(([env, model]) => {
console.log('Loaded', model, env, viewer)
})
return () => {
viewer.dispose()
}
}, [])
return (
<canvas id="three-canvas" style={{width: 800, height: 600}} ref={canvasRef} />
)
}
Check it in action: https://threepipe.org/examples/#react-tsx-sample/
Other examples in js: https://threepipe.org/examples/#react-js-sample/ and jsx: https://threepipe.org/examples/#react-jsx-sample/
A sample vue.js component in js to render a model with an environment map.
const ThreeViewerComponent = {
setup() {
const canvasRef = ref(null);
onMounted(() => {
const viewer = new ThreeViewer({ canvas: canvasRef.value });
const envPromise = viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr');
const modelPromise = viewer.load('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf');
Promise.all([envPromise, modelPromise]).then(([env, model]) => {
console.log('Loaded', model, env, viewer)
})
onBeforeUnmount(() => {
viewer.dispose();
});
});
return { canvasRef };
},
};
Check it in action: https://threepipe.org/examples/#vue-html-sample/
Another example with Vue SFC(Single file component): https://threepipe.org/examples/#vue-sfc-sample/
A sample svelte component in js to render a model with an environment map.
<script>
import {onDestroy, onMount} from 'svelte';
import {ThreeViewer} from 'threepipe';
let canvasRef;
let viewer;
onMount(() => {
viewer = new ThreeViewer({canvas: canvasRef});
const envPromise = viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr');
const modelPromise = viewer.load('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf');
Promise.all([envPromise, modelPromise]).then(([env, model]) => {
console.log('Loaded', model, env, viewer)
})
});
onDestroy(() => viewer.dispose())
</script>
<canvas bind:this={canvasRef} id="three-canvas" style="width: 800px; height: 600px"></canvas>
Check it in action: https://threepipe.org/examples/#svelte-sample/
npm install threepipe
First, create a canvas element in your HTML page:
<canvas id="three-canvas" style="width: 800px; height: 600px;"></canvas>
Then, import the viewer and create a new instance:
import {ThreeViewer, IObject3D} from 'threepipe'
// Create a viewer
const viewer = new ThreeViewer({canvas: document.getElementById('three-canvas') as HTMLCanvasElement})
// Load an environment map
await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
// Load a model
const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
autoCenter: true,
autoScale: true,
})
That’s it! You should now see a 3D model on your page.
The 3D model can be opened in the editor to view and edit the scene settings, objects, materials, lights, cameras, post-processing, etc. and exported as a GLB file. All settings are automatically serialized and saved in the GLB file, which can be loaded into the viewer. Any plugins used in the editor can be added to the viewer to add the same functionality. The plugin data is automatically loaded(if the plugin is added) when the model is added to the scene.
The viewer initializes with a Scene, Camera, Camera controls(Orbit Controls), several importers, exporters and a default rendering pipeline. Additional functionality can be added with plugins.
Check out the glTF Load example to see it in action or to check the JS equivalent code: https://threepipe.org/examples/#gltf-load/
Check out the Plugins section to learn how to add additional functionality to the viewer.
The core framework(src, dist, examples folders) and any plugins without a separate license are under the Free Apache 2.0 license.
Some plugins(in the plugins folder) might have different licenses. Check the individual plugin documentation and the source folder/files for more details.
The project is in beta stage and under active development.
Many features will be added but the core API will not change significantly in future releases.
ViewHelper/AxisHelper that syncs with the main camera.controlsMode to the mainCamera for device orientation controls(gyroscope rotation control).controlsMode to the mainCamera for pointer lock controls.controlsMode to the mainCamera for first person controls from threejs.MaterialConfiguratorPlugin and SwitchNodePlugin to allow users to select variationsCheck the list of all functions, classes and types in the API Reference Docs.
Contributions to ThreePipe are welcome and encouraged! Feel free to open issues and pull requests on the GitHub repository.