direct modification
This commit is contained in:
		
							parent
							
								
									c419dca58f
								
							
						
					
					
						commit
						7611192683
					
				
							
								
								
									
										96
									
								
								index.html
									
									
									
									
									
								
							
							
						
						
									
										96
									
								
								index.html
									
									
									
									
									
								
							| @ -23,86 +23,90 @@ | |||||||
| <script type="module"> | <script type="module"> | ||||||
|     import { Scene, THREE } from './scene.js'; |     import { Scene, THREE } from './scene.js'; | ||||||
| 
 | 
 | ||||||
|     let average = (inCenter, inArray, ...inPointsInd) => |     let average = (inArray, inPointInd, ...inOthersInd) => | ||||||
|     { |     { | ||||||
|         let output = [0, 0, 0]; |         let pointX = inPointInd*3 + 0; | ||||||
|  |         let pointY = inPointInd*3 + 1; | ||||||
|  |         let pointZ = inPointInd*3 + 2; | ||||||
| 
 | 
 | ||||||
|         for(let i=0; i<inPointsInd.length; i++) |         let centerX = Math.round(inArray[pointX]); | ||||||
|  |         let centerY = Math.round(inArray[pointY]); | ||||||
|  |         let centerZ = Math.round(inArray[pointZ]); | ||||||
|  |          | ||||||
|  |         for(let i=0; i<inOthersInd.length; i++) | ||||||
|         { |         { | ||||||
|             let pointInd = inPointsInd[i]*3; |             let otherInd = inOthersInd[i]*3; | ||||||
|             output[0] += inArray[pointInd+0]; |             inArray[pointX] += inArray[otherInd+0]; | ||||||
|             output[1] += inArray[pointInd+1]; |             inArray[pointY] += inArray[otherInd+1]; | ||||||
|             output[2] += inArray[pointInd+2]; |             inArray[pointZ] += inArray[otherInd+2]; | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         let reducer = inPointsInd.length; |         let reducer = inOthersInd.length+1; | ||||||
|         output[0] /= reducer; |  | ||||||
|         output[1] /= reducer; |  | ||||||
|         output[2] /= reducer; |  | ||||||
| 
 |  | ||||||
|         let limit = (inCenter, inPoint) =>  |         let limit = (inCenter, inPoint) =>  | ||||||
|         { |         { | ||||||
|             var limit; |             var limit; | ||||||
|              |             limit = inCenter-0.49; | ||||||
|             limit = inCenter-0.5; |             if(inPoint <= limit) | ||||||
|             if(inPoint < limit){ return limit; } |             { | ||||||
| 
 |                 return limit; | ||||||
|             limit = inCenter+0.5; |             } | ||||||
|             if(inPoint > limit){ return limit; } |             limit = inCenter + 0.49; | ||||||
|  |             if(inPoint >= limit) | ||||||
|  |             { | ||||||
|  |                 return limit; | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|             return inPoint; |             return inPoint; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         var limited = []; |         inArray[pointX] = limit(centerX, inArray[pointX]/reducer); | ||||||
|         limited[0] = limit(inCenter[0], output[0]); |         inArray[pointY] = limit(centerY, inArray[pointY]/reducer); | ||||||
|         limited[1] = limit(inCenter[1], output[1]); |         inArray[pointZ] = limit(centerZ, inArray[pointZ]/reducer); | ||||||
|         limited[2] = limit(inCenter[2], output[2]); |  | ||||||
| 
 |  | ||||||
|         //console.log(`<${output[0].toFixed(2)}, ${output[1].toFixed(2)}> limited to <${limited[0].toFixed(2)}, ${limited[1].toFixed(2)}> by <${inCenter[0].toFixed(2)}, ${inCenter[1].toFixed(2)}>`) |  | ||||||
| 
 |  | ||||||
|         output[0] = limited[0]; |  | ||||||
|         output[1] = limited[1]; |  | ||||||
|         output[2] = limited[2]; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|         return output; |  | ||||||
|     }; |     }; | ||||||
|     let smooth = (inArray, inTimes) => |     let smooth = (inArray, inTimes) => | ||||||
|     { |     { | ||||||
|         let output = [...inArray]; |         let count = inArray.length/3; | ||||||
|         let count = output.length/3; |  | ||||||
|         for(let t=0; t<inTimes; t++) |         for(let t=0; t<inTimes; t++) | ||||||
|         { |         { | ||||||
|             for(let i=0; i<count; i++) |             for(let i=0; i<count; i++) | ||||||
|             { |             { | ||||||
|                 var av; |  | ||||||
|                 var center = [inArray[i*3 + 0], inArray[i*3 + 1], inArray[i*3 + 2]] |  | ||||||
|                 if(i==0) |                 if(i==0) | ||||||
|                 { |                 { | ||||||
|                     av = average(center, output,  count-1, i, i+1); |                     average(inArray,  i, count-1, i+1); | ||||||
|                 } |                 } | ||||||
|                 else |                 else | ||||||
|                 { |                 { | ||||||
|                     if(i==count-1) |                     if(i==count-1) | ||||||
|                     { |                     { | ||||||
|                         av = average(center, output, i-1, i, 0); |                         average(inArray,  i, i-1, 0); | ||||||
|                     } |                     } | ||||||
|                     else |                     else | ||||||
|                     { |                     { | ||||||
|                         av = average(center, output, i-1, i, i+1); |                         average(inArray,  i, i-1, i+1); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 output[i*3+0] = av[0];  |  | ||||||
|                 output[i*3+1] = av[1];  |  | ||||||
|                 output[i*3+2] = av[2];  |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         return output; |  | ||||||
|     } |     } | ||||||
|  |      | ||||||
|  |     /* | ||||||
|  |     let testPoints = | ||||||
|  |     [ | ||||||
|  |          0,  0,  0, | ||||||
|  |          0,  1,  0, | ||||||
|  |          1,  1,  0 | ||||||
|  |     ]; | ||||||
|  |     console.log(testPoints); | ||||||
|  |     average(testPoints, 1, 0, 2); | ||||||
|  |     console.log(testPoints); | ||||||
|  |     */ | ||||||
|  | 
 | ||||||
|     let path = (inPoints, inSmoothing, inColor) => |     let path = (inPoints, inSmoothing, inColor) => | ||||||
|     { |     { | ||||||
|  |         let clone = [...inPoints]; | ||||||
|  |         smooth(clone, inSmoothing); | ||||||
|         const geometry = new THREE.BufferGeometry(); |         const geometry = new THREE.BufferGeometry(); | ||||||
|         geometry.setAttribute('position', new THREE.Float32BufferAttribute( smooth(inPoints, inSmoothing), 3 )); |         geometry.setAttribute('position', new THREE.Float32BufferAttribute( clone, 3 )); | ||||||
|         const materialLine = new THREE.LineBasicMaterial( { color: inColor, linewidth: 3 } ); |         const materialLine = new THREE.LineBasicMaterial( { color: inColor, linewidth: 3 } ); | ||||||
|         const materialPoint = new THREE.PointsMaterial( { color:inColor, size: 0.05 } ); |         const materialPoint = new THREE.PointsMaterial( { color:inColor, size: 0.05 } ); | ||||||
|         const output = new THREE.Group(); |         const output = new THREE.Group(); | ||||||
| @ -142,11 +146,7 @@ | |||||||
|         Init(inScene) |         Init(inScene) | ||||||
|         { |         { | ||||||
|             inScene.add(path(points, 0, 0xFF0000)); |             inScene.add(path(points, 0, 0xFF0000)); | ||||||
|             inScene.add(path(points, 1, 0x003300)); |             inScene.add(path(points, 50, 0x00ff00)); | ||||||
|             inScene.add(path(points, 3, 0x005500)); |  | ||||||
|             inScene.add(path(points, 5, 0x007700)); |  | ||||||
|             inScene.add(path(points, 7, 0x009900)); |  | ||||||
|             inScene.add(path(points, 100, 0x00bb00)); |  | ||||||
|         }, |         }, | ||||||
|         Update(scene, delta) |         Update(scene, delta) | ||||||
|         { |         { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user