All Projects → marcofugaro → Three Projected Material

marcofugaro / Three Projected Material

📽 Three.js Material which lets you do Texture Projection on a 3d Model

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Three Projected Material

Geo Three
Tile based geographic world map visualization library for threejs
Stars: ✭ 146 (-17.51%)
Mutual labels:  threejs
Vue Displacement Slideshow
A Vue.js 2.0 slideshow component working with Three.js
Stars: ✭ 165 (-6.78%)
Mutual labels:  threejs
React Three Fiber
🇨🇭 A React renderer for Three.js
Stars: ✭ 16,097 (+8994.35%)
Mutual labels:  threejs
Wechart
Create all the [ch]arts by cax or three.js - Cax 和 three.js 创造一切图[表]
Stars: ✭ 152 (-14.12%)
Mutual labels:  threejs
Portfolio
My personal portfolio website built using React and three js
Stars: ✭ 160 (-9.6%)
Mutual labels:  threejs
Threejs Path Flow
🐬🐟 ↶Mesh Deformation / Bending / Following on a Curve
Stars: ✭ 165 (-6.78%)
Mutual labels:  threejs
Antipasto
🍽 Juicy starter for three.js
Stars: ✭ 147 (-16.95%)
Mutual labels:  threejs
Pipes
💿 Classic 3D Pipes screensaver remake (web-based)
Stars: ✭ 176 (-0.56%)
Mutual labels:  threejs
Patches
Patches is a visual programming editor for building WebVR and WebGL experiences.
Stars: ✭ 164 (-7.34%)
Mutual labels:  threejs
Threejs Mesh Modifiers
A Three.js mesh morph modifier
Stars: ✭ 169 (-4.52%)
Mutual labels:  threejs
Texture Compressor
CLI tool for texture compression using ASTC, ETC, PVRTC and S3TC in a KTX container.
Stars: ✭ 156 (-11.86%)
Mutual labels:  threejs
Altspacesdk
Software Development Kit for AltspaceVR
Stars: ✭ 159 (-10.17%)
Mutual labels:  threejs
React Globe
Create beautiful and interactive React + ThreeJS globe visualizations with ease.
Stars: ✭ 167 (-5.65%)
Mutual labels:  threejs
Interactivelandscape
An exploration of an animated interactive landscape built with three.js.
Stars: ✭ 150 (-15.25%)
Mutual labels:  threejs
Encom Boardroom
📈 Web tribute to the Tron: Legacy Boardroom Scene
Stars: ✭ 2,094 (+1083.05%)
Mutual labels:  threejs
Three Ui
UI solution for Three.js
Stars: ✭ 149 (-15.82%)
Mutual labels:  threejs
Threejs Sandbox
Set of experiments and extensions to THREE.js.
Stars: ✭ 163 (-7.91%)
Mutual labels:  threejs
Aframe Effects
A VR Ready Post processing framework for Three.js and/or A-Frame
Stars: ✭ 176 (-0.56%)
Mutual labels:  threejs
Threejs Modern App
Boilerplate and utils for a fullscreen Three.js app
Stars: ✭ 176 (-0.56%)
Mutual labels:  threejs
Expo Voxel
🎮🌳 Voxel Terrain made in React Native. ∛
Stars: ✭ 169 (-4.52%)
Mutual labels:  threejs

three-projected-material

Three.js Material which lets you do Texture Projection on a 3d Model.

Installation

After having installed three.js, install it from npm with:

npm install three-projected-material

or

yarn add three-projected-material

You can also use it from the CDN, just make sure to put this after the three.js script:

<script src="https://unpkg.com/three-projected-material"></script>

Getting started

You can import it like this

import ProjectedMaterial from 'three-projected-material'

or, if you're using CommonJS

const ProjectedMaterial = require('three-projected-material').default

Instead, if you install it from the CDN, its exposed under window.projectedMaterial, and you use it like this

const ProjectedMaterial = window.projectedMaterial.default

Then, you can use it like this:

const geometry = new THREE.BoxBufferGeometry(1, 1, 1)
const material = new ProjectedMaterial({
  camera, // the camera that acts as a projector
  texture, // the texture being projected
  textureScale: 0.8, // scale down the texture a bit
  textureOffset: new THREE.Vector2(0.1, 0.1), // you can translate the texture if you want
  cover: true, // enable background-size: cover behaviour, by default it's like background-size: contain
  color: '#ccc', // the color of the object if it's not projected on
  roughness: 0.3, // you can pass any other option that belongs to MeshPhysicalMaterial
})
const box = new THREE.Mesh(geometry, material)
webgl.scene.add(box)

// move the mesh any way you want!
box.rotation.y = -Math.PI / 4

// and when you're ready project the texture on the box!
material.project(box)

ProjectedMaterial also supports instanced meshes via three.js' InstancedMesh, and even multiple projections. Check out the examples below for a detailed guide!

Examples

API Reference

new ProjectedMaterial({ camera, texture, ...others })

Create a new material to later use for a mesh.

Option Default Description
camera The PerspectiveCamera the texture will be projected from.
texture The Texture being projected.
textureScale 1 Make the texture bigger or smaller.
textureOffset new THREE.Vector2() Offset the texture in a x or y direction. The unit system goes from 0 to 1, from the bottom left corner to the top right corner of the projector camera frustum.
cover false Wheter the texture should act like background-size: cover on the projector frustum. By default it works like background-size: contain.
...options Other options you pass to any three.js material like color, opacity, envMap and so on. The material is built from a MeshPhysicalMaterial, so you can pass any property of that material and of its parent MeshStandardMaterial.

These properties are exposed as properties of the material, so you can change them later.

For example, to update the material texture and change its scale:

material.texture = newTexture
material.textureScale = 0.8

material.project(mesh)

Project the texture from the camera on the mesh. With this method we "take a snaphot" of the current mesh and camera position in space. The After calling this method, you can move the mesh or the camera freely.

Option Description
mesh The mesh that has a ProjectedMaterial as material.

allocateProjectionData(geometry, instancesCount)

Allocate the data that will be used when projecting on an InstancedMesh. Use this on the geometry that will be used in pair with a ProjectedMaterial when initializing InstancedMesh.

This needs to be called before .projectInstanceAt().

Option Description
geometry The geometry that will be passed to the InstancedMesh.
instancesCount The number of instances, the same that will be passed to the InstancedMesh.

material.projectInstanceAt(index, instancedMesh, matrix)

Do the projection for an InstancedMesh. Don't forget to call updateMatrix() like you do before calling InstancedMesh.setMatrixAt().

To do projection an an instanced mesh, the geometry needs to be prepared with allocateProjectionData() beforehand.

dummy.updateMatrix()
projectInstanceAt(i, instancedMesh, dummy.matrix)

Link to the full example about instancing.

Option Description
index The index of the instanced element to project.
instancedMesh The InstancedMesh with a projected material.
matrix The matrix of the dummy you used to position the instanced mesh element. Be sure to call .updateMatrix() beforehand.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].