Update: CC - Demo New - Entity Loaded (tuby5lj4di.js) 2155 bytes modified
parent
a224fc56a6
commit
bc0184b0bc
|
@ -28,4 +28,79 @@ if (this.parentEntity === data.entity) {
|
||||||
this.ccKeyUp.entityLoaded = this;
|
this.ccKeyUp.entityLoaded = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.CustomCode.prototype.generateAttributeData = function(index, width, height) {
|
||||||
|
|
||||||
|
var heightData = this.images[this.currentImageIndex].getHeightData();
|
||||||
|
|
||||||
|
var offsets = [];
|
||||||
|
var scales = [];
|
||||||
|
var orientations = [];
|
||||||
|
|
||||||
|
var x, y, z = 0;
|
||||||
|
|
||||||
|
for (x = 0; x < width; x++) {
|
||||||
|
for (y = 0; y < height; y++) {
|
||||||
|
z = heightData[(y * width) + x] * 10;
|
||||||
|
scale = height * 0.19;
|
||||||
|
offsets.push((x - 64) * 2, (64 - y) * 2, z);
|
||||||
|
orientations.push(0, 0, 0, 1);
|
||||||
|
scales.push(scale, scale, scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
offsets : offsets,
|
||||||
|
scales : scales,
|
||||||
|
orientations : orientations
|
||||||
|
};
|
||||||
|
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
|
GameLib.CustomCode.prototype.buildInstancedGeometry = function(index) {
|
||||||
|
|
||||||
|
var attributeData = this.generateAttributeData(index, 128, 128);
|
||||||
|
|
||||||
|
var uniforms = Object.assign(
|
||||||
|
THREE.UniformsLib['lights'],
|
||||||
|
THREE.UniformsLib['common'],
|
||||||
|
{
|
||||||
|
map : {
|
||||||
|
value : this.textureWhite.instance
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
uniforms.diffuse.value.r = 0.47;
|
||||||
|
uniforms.diffuse.value.g = 0.72;
|
||||||
|
uniforms.diffuse.value.b = 1.0;
|
||||||
|
|
||||||
|
this.materialRawPhong.instance.uniforms = uniforms;
|
||||||
|
|
||||||
|
this.instancedGeometry.instance.index = this.boxGeometry.instance.index;
|
||||||
|
this.instancedGeometry.instance.groups = this.boxGeometry.instance.groups;
|
||||||
|
this.instancedGeometry.instance.attributes.position = this.boxGeometry.instance.attributes.position;
|
||||||
|
this.instancedGeometry.instance.attributes.normal = this.boxGeometry.instance.attributes.normal;
|
||||||
|
this.instancedGeometry.instance.attributes.uv = this.boxGeometry.instance.attributes.uv;
|
||||||
|
|
||||||
|
var offsetAttribute = new THREE.InstancedBufferAttribute(
|
||||||
|
new Float32Array(attributeData.offsets),
|
||||||
|
3
|
||||||
|
).setDynamic(true);
|
||||||
|
|
||||||
|
var orientationAttribute = new THREE.InstancedBufferAttribute(
|
||||||
|
new Float32Array(attributeData.orientations),
|
||||||
|
4
|
||||||
|
);
|
||||||
|
|
||||||
|
var scaleAttribute = new THREE.InstancedBufferAttribute(
|
||||||
|
new Float32Array(attributeData.scales),
|
||||||
|
3
|
||||||
|
).setDynamic(true);
|
||||||
|
|
||||||
|
this.instancedGeometry.instance.addAttribute('offset', offsetAttribute);
|
||||||
|
this.instancedGeometry.instance.addAttribute('orientation', orientationAttribute);
|
||||||
|
this.instancedGeometry.instance.addAttribute('scale', scaleAttribute);
|
||||||
|
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
//@ sourceURL=entiyuLoaded.js
|
//@ sourceURL=entiyuLoaded.js
|
Loading…
Reference in New Issue