https://github.com/spite/three.decalgeometry
Decals for three.js
https://github.com/spite/three.decalgeometry
Last synced: over 1 year ago
JSON representation
Decals for three.js
- Host: GitHub
- URL: https://github.com/spite/three.decalgeometry
- Owner: spite
- Created: 2014-06-27T22:24:58.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2017-01-05T18:16:44.000Z (over 9 years ago)
- Last Synced: 2025-03-05T03:14:52.580Z (over 1 year ago)
- Language: JavaScript
- Size: 2.66 MB
- Stars: 157
- Watchers: 8
- Forks: 25
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
THREE.DecalGeometry.js
=========================
This object creates a decal geometry, intersecting a cube against a THREE.Geometry. Based on this article [How to project decals](http://blog.wolfire.com/2009/06/how-to-project-decals/). It interesects a cube against an arbitrary geometry and clips vertex coordinates and normals.

Demo is here: [Decal Splatter](http://clicktorelease.com/code/decal-splatter).
How to use
----------
Include the library:
<script src="THREE.DecalGeometry.js" ></script>
Instantiate a geometry passing:
var decalGeometry = new THREE.DecalGeometry(
meshToIntersect, // it has to be a THREE.Mesh
position, // THREE.Vector3 in world coordinates
direction, // THREE.Vector3 specifying the orientation of the decal
dimensions, // THREE.Vector3 specifying the size of the decal box
check // THREE.Vector3 specifying what sides to clip (1-clip, 0-noclip)
);
and create a mesh using that geometry, as usual:
var mesh = new THREE.Mesh( decalGeometry, decalMaterial );
The decal material can be any material, just make sure to have this attributes enabled:
var decalMaterial = new THREE.MeshNormalMaterial( {
transparent: true,
depthTest: true,
depthWrite: false,
polygonOffset: true,
polygonOffsetFactor: -4,
});
License
-------
MIT licensed
Copyright (C) 2014 Jaume Sanchez Elias http://twitter.com/thespite
Lee Perry Smith's head model and textures by [Infinite Realities](http://www.ir-ltd.net/)
http://www.clicktorelease.com