three.js examples. if you are first in learning three.js , this will give you much help.

Overview

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.BoxGeometry(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.
You might also like...

A simple To-do app project made using JavaScript ES6 and Webpack - Microverse. You can add, remove, check tasks, and remove all the tasks that were done at the same time. Feel free to see the live version, if you like it please give it a star!

To Do List a to do list javascript app buit using webpack and es6. Built With HTML CSS JavaScript Wepack Live Demo (if available) Live Demo Link Getti

Dec 17, 2022

🟒 Music player app with a modern homepage, fully-fledged music player, search, lyrics, song exploration features, search, popular music around you, worldwide top charts, and much more.

🟒 Music player app with a modern homepage, fully-fledged music player, search, lyrics, song exploration features, search, popular music around you, worldwide top charts, and much more.

Music-player-app see the project here. 1. Key Features 2. Technologies I've used Key Features: 🟒 Fully responsive clean UI. 🟒 Entirely mobile respo

Nov 16, 2022

Examples of how to do query, style, dom, ajax, event etc like jQuery with plain javascript.

You (Might) Don't Need jQuery Frontend environments evolve rapidly nowadays and modern browsers have already implemented a great deal of DOM/BOM APIs

Dec 24, 2022

πŸ€ͺ A list of funny and tricky JavaScript examples

πŸ€ͺ A list of funny and tricky JavaScript examples

πŸ€ͺ A list of funny and tricky JavaScript examples

Jan 1, 2023

πŸš€πŸš€ A Shopify embedded app starter template, with updated dependencies, session storage, app context and examples for basic functionalities.

Shopify Node App Starter This is a starter template for embedded shopify apps based on the shopify cli node app. Contributions to create the perfect s

Jan 8, 2023

Verbosely Documented, Minimal Starknet Contract Examples.

cairo-by-example β€’ Verbosely Documented, Minimal Starknet Contract Examples. Cairo By Example deployed to https://cairo-by-example.xyz Developing Clon

Dec 6, 2022

Live Reload Examples

Live Reload Examples Examples of live reloading code to create a fast feedback loop. Examples in this code repo accompany a soon to be published blog

Sep 29, 2022

Examples for Evolllution talk about omni api's

These are examples for the 2022 Evolution Conference. These are only intended for learning puposes so you can learn and develop your own tool set. P

Jun 3, 2022

Offline rendering examples at the command line with Node.js

Elementary Audio Offline Rendering Examples This repository holds a set of small examples using Elementary in Node.js to process audio files. Each sub

Jun 12, 2022
Owner
Software Engineer(Web & Blockchain)
null
Make your first Pull Request on Hacktoberfest 2022. Don't forget to spread love and if you like give us a star

Hacktoberfest2022 Make your first Pull Request on Hacktoberfest 2022. Don't forget to spread love and if you like give us a star Quality of Pull Reque

Google Developer Students Club - Galgotias University 12 Oct 30, 2022
Types generator will help user to create TS types from JSON. Just paste your single object JSON the Types generator will auto-generate the interfaces for you. You can give a name for the root object

Types generator Types generator is a utility tool that will help User to create TS Interfaces from JSON. All you have to do is paste your single objec

Vineeth.TR 16 Dec 6, 2022
e-ONG, an authorial project, whose objective is to help ONGs to find people who need help or would like to help them

This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: npm start Runs the app in the developmen

Lucas Lima 2 Nov 11, 2022
Incredible resources (with links) to help up-skill yourselves on various fields. Resources like programming, designing, engineering and much more and completely Open Source.

Shiryoku Incredible resources (with links) to help up-skill yourselves on various fields. Resources like programming, designing, engineering and much

Kunal Keshan 22 Dec 15, 2022
Grassp is the first ever CLI based Micro Learning Tool!

grassp-cli Grassp is the first ever CLI based Micro Learning Tool! grassp-cli Usage Commands Usage $ npm install -g grassp $ grassp COMMAND running co

Sahil Pabale 9 Aug 9, 2022
Nutrition tracking software that uses machine learning to help you reach your body composition goals.

LogSmarter - Machine Learning Nutrition Tracker Description LogSmarter LogSmarterβ„’ is not just another calorie counter. It is an AI nutrition coach th

Ryan Lefebvre 24 Sep 4, 2022
⚑ the first open-source redis client made with care and acessibility-first πŸš€

⚑ Redis UI The first open-source project to create an awesome and accessible UI for Redis as a native desktop application. ✨ ?? ?? How to develop loca

Nicolas Lopes Aquino 14 Dec 5, 2022
A first person character controller for the Three.js graphics library

charactercontroller A first person character controller for the Three.js graphics library Demo Installation npm install charactercontroller Usage impo

Malted 10 Aug 17, 2022
Text Engraving & Extrusion demo based on Three.js is implemented with Typescript and webpack5. Used THREE-CSGMesh as the core tech to achieve engraving and extrusion results

Text Engraving & Extrusion Text Engraving & Extrusion demo is implemented using Three.js, with Typescript and webpack5. Used THREE-CSGMesh as the core

Jiahong Li 3 Oct 12, 2022