three-instanced-uniforms-mesh
Advanced tools
Comparing version 0.43.0 to 0.44.0
@@ -6,2 +6,10 @@ # Change Log | ||
# [0.44.0](https://github.com/protectwise/troika/compare/v0.43.1-alpha.0...v0.44.0) (2021-11-14) | ||
**Note:** Version bump only for package three-instanced-uniforms-mesh | ||
# [0.43.0](https://github.com/protectwise/troika/compare/v0.42.0...v0.43.0) (2021-09-20) | ||
@@ -8,0 +16,0 @@ |
@@ -174,2 +174,12 @@ import { InstancedMesh, MeshBasicMaterial, InstancedBufferAttribute } from 'three'; | ||
} | ||
/** | ||
* Unset all instance-specific values for a given uniform, reverting back to the original | ||
* uniform value for all. | ||
* @param {string} name | ||
*/ | ||
unsetUniform (name) { | ||
this.geometry.deleteAttribute(`troika_attr_${name}`); | ||
this._instancedUniformNames = this._instancedUniformNames.filter(n => n !== name); | ||
} | ||
} | ||
@@ -176,0 +186,0 @@ |
@@ -177,2 +177,12 @@ (function (global, factory) { | ||
} | ||
/** | ||
* Unset all instance-specific values for a given uniform, reverting back to the original | ||
* uniform value for all. | ||
* @param {string} name | ||
*/ | ||
unsetUniform (name) { | ||
this.geometry.deleteAttribute(`troika_attr_${name}`); | ||
this._instancedUniformNames = this._instancedUniformNames.filter(n => n !== name); | ||
} | ||
} | ||
@@ -179,0 +189,0 @@ |
@@ -7,2 +7,2 @@ 'use strict';(function(f,h){"object"===typeof exports&&"undefined"!==typeof module?h(exports,require("three"),require("troika-three-utils")):"function"===typeof define&&define.amd?define(["exports","three","troika-three-utils"],h):(f="undefined"!==typeof globalThis?globalThis:f||self,h(f.three_instanced_uniforms_mesh={},f.THREE,f.troika_three_utils))})(this,function(f,h,k){function l(a){let b=[],c="";a=k.createDerivedMaterial(a,{chained:!0,customRewriter({vertexShader:a,fragmentShader:d}){let c=[], | ||
b,c){var e=this.geometry.attributes;let f=`troika_attr_${a}`;var d=e[f];if(!d){var g=this._baseMaterial;g=(d=g.uniforms)&&d[a]?d[a].value:(d=k.getShadersForMaterial(g).uniforms)&&d[a]?d[a].value:null;d=g;d=null==d?0:"number"===typeof d?1:d.isVector2?2:d.isVector3||d.isColor?3:d.isVector4?4:Array.isArray(d)?d.length:0;d=e[f]=new h.InstancedBufferAttribute(new Float32Array(d*this.count),d);if(null!==g)for(e=0;e<this.count;e++)m(d,e,g);this._instancedUniformNames=[...this._instancedUniformNames,a]}m(d, | ||
b,c);d.needsUpdate=!0}}f.InstancedUniformsMesh=t;f.createInstancedUniformsDerivedMaterial=l;Object.defineProperty(f,"__esModule",{value:!0})}) | ||
b,c);d.needsUpdate=!0}unsetUniform(a){this.geometry.deleteAttribute(`troika_attr_${a}`);this._instancedUniformNames=this._instancedUniformNames.filter(b=>b!==a)}}f.InstancedUniformsMesh=t;f.createInstancedUniformsDerivedMaterial=l;Object.defineProperty(f,"__esModule",{value:!0})}) |
{ | ||
"name": "three-instanced-uniforms-mesh", | ||
"version": "0.43.0", | ||
"version": "0.44.0", | ||
"description": "Extension to Three.js InstancedMesh supporting per-instance uniform values", | ||
@@ -17,3 +17,3 @@ "author": "Jason Johnston <jason.johnston@protectwise.com>", | ||
"dependencies": { | ||
"troika-three-utils": "^0.43.0" | ||
"troika-three-utils": "^0.44.0" | ||
}, | ||
@@ -23,3 +23,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "497fa534d015bc8f746c7d00ec7bfde1df92f491" | ||
"gitHead": "a6b913e475a3a8459b2f758c709b8feb16966ed1" | ||
} |
# InstancedUniformsMesh | ||
This package provides a `InstancedUniformsMesh` class which extends Three.js's [`InstancedMesh`](https://threejs.org/docs/#api/en/objects/InstancedMesh) to allow its material's shader uniforms to be set individually per instance. It behaves just like `InstancedMesh` but exposes one new method: | ||
This package provides a `InstancedUniformsMesh` class which extends Three.js's [`InstancedMesh`](https://threejs.org/docs/#api/en/objects/InstancedMesh) to allow its material's shader uniforms to be set individually per instance. It behaves just like `InstancedMesh` but exposes a new method: | ||
@@ -47,2 +47,10 @@ ```js | ||
### Resetting to defaults | ||
If you have set instance-specific values for a given uniform but you want to revert all those to the single original uniform value, you can call: | ||
```js | ||
mesh.unsetUniform(uniformName) | ||
``` | ||
### Examples | ||
@@ -49,0 +57,0 @@ |
export {InstancedUniformsMesh} from './InstancedUniformsMesh.js' | ||
export {createInstancedUniformsDerivedMaterial} from './InstancedUniformsDerivedMaterial.js' |
@@ -0,0 +0,0 @@ import { createDerivedMaterial, getShaderUniformTypes, voidMainRegExp } from 'troika-three-utils' |
@@ -99,2 +99,12 @@ import { InstancedBufferAttribute, InstancedMesh, MeshBasicMaterial } from 'three' | ||
} | ||
/** | ||
* Unset all instance-specific values for a given uniform, reverting back to the original | ||
* uniform value for all. | ||
* @param {string} name | ||
*/ | ||
unsetUniform (name) { | ||
this.geometry.deleteAttribute(`troika_attr_${name}`) | ||
this._instancedUniformNames = this._instancedUniformNames.filter(n => n !== name) | ||
} | ||
} | ||
@@ -101,0 +111,0 @@ |
Sorry, the diff of this file is not supported yet
37087
627
60
+ Addedtroika-three-utils@0.44.0(transitive)
- Removedtroika-three-utils@0.43.0(transitive)
Updatedtroika-three-utils@^0.44.0