From 96eec133a0064cc0e2d8add907c1047592ed88c1 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Mon, 12 Feb 2018 15:15:47 +0100 Subject: [PATCH] Initial Commit: CC - Demo New - Key Up (ip0443a52d.js) --- ip0443a52d.js | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 ip0443a52d.js diff --git a/ip0443a52d.js b/ip0443a52d.js new file mode 100644 index 0000000..8ec3a7b --- /dev/null +++ b/ip0443a52d.js @@ -0,0 +1,86 @@ +if (!this.entityLoaded) { + return; +} + +this.initialized = false; + +if (!this.initialized) { + + this.imageSpoon = this.entityLoaded.imageSpoon; + this.imageEarth = this.entityLoaded.imageEarth; + + this.meshBox = this.entityLoaded.meshBox; + this.meshImageGrid = this.entityLoaded.meshImageGrid; + + this.boxGeometry = this.entityLoaded.boxGeometry; + this.instancedGeometry = this.entityLoaded.instancedGeometry; + + this.initialized = true; + + console.log('key up initialized'); +} + +if (data.code === 'KeyL') { + + var colors = []; + + for (var i = 0; i < this.boxGeometry.instance.index.count; i++) { + colors.push(1, 1, 1); + } + + this.boxGeometry.instance.addAttribute('color', new THREE.Float32BufferAttribute(colors, 3)); + + var heightData = this.imageSpoon.getHeightData(); + + var instances = 16384; //128 x 128 + + var x, y = 0; + + var positions = []; + var quaternions = []; + var scales = []; + + var height = 0; + + for (x = 0; x < 128; x++) { + for (y = 0; y < 128; y++) { + + height = heightData[(y * 128) + x] * 10; + scale = height * 0.1; + + positions.push(x - 64, 64 - y, height); + quaternions.push(0, 0, 0, 1); + scales.push(scale, scale, scale); + } + } + + this.instancedGeometry.instance.attributes.position = this.boxGeometry.instance.attributes.position; + //this.instancedGeometry.instance.attributes.position = this.boxGeometry.instance.attributes.position; + //this.instancedGeometry.instance.attributes.color = this.boxGeometry.instance.attributes.color; + + + this.instancedGeometry.instance.removeAttribute('color'); + + this.instancedGeometry.instance.removeAttribute('instancePosition'); + this.instancedGeometry.instance.removeAttribute('instanceQuaternion'); + this.instancedGeometry.instance.removeAttribute('instanceScale'); + + this.instancedGeometry.instance.addAttribute('instancePosition', new THREE.InstancedBufferAttribute( new Float32Array(positions), 3)); + this.instancedGeometry.instance.addAttribute('instanceQuaternion', new THREE.InstancedBufferAttribute( new Float32Array(quaternions), 4)); + this.instancedGeometry.instance.addAttribute('instanceScale', new THREE.InstancedBufferAttribute( new Float32Array(scales), 3)); + + this.instancedGeometry.instance.addAttribute('color', new THREE.Float32BufferAttribute(colors, 3)); + + this.instancedGeometry.instance.clearGroups(); + + this.instancedGeometry.instance.addGroup(0, 36, 0); + + //this.meshImageGrid.geometry.instance = this.instancedGeometry.instance; + + //this.meshImageGrid.materials[0].createInstance(); + //this.meshImageGrid.updateInstance('materials'); + + console.log('got data'); +} + +//@ sourceURL=ccKeyUp.js \ No newline at end of file