-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
179 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as THREE from 'three'; | ||
import { hsvToRgb } from '../utils/colorConversion.js'; | ||
|
||
export function createHSVCone() { | ||
const coneGroup = new THREE.Group(); | ||
const segments = 32; | ||
const rings = 10; | ||
const height = 1; | ||
const radius = 0.5; | ||
|
||
const points = []; | ||
const colors = []; | ||
|
||
points.push(new THREE.Vector3(0, 0, 0)); | ||
colors.push(new THREE.Color(0, 0, 0)); | ||
|
||
for (let ring = 1; ring <= rings; ring++) { | ||
const v = ring / rings; | ||
const currentRadius = (radius * ring) / rings; | ||
|
||
for (let segment = 0; segment < segments; segment++) { | ||
const theta = (segment / segments) * Math.PI * 2; | ||
const x = currentRadius * Math.cos(theta); | ||
const z = currentRadius * Math.sin(theta); | ||
const y = v * height; | ||
|
||
const hue = (theta / (Math.PI * 2)) * 360; | ||
const saturation = (Math.sqrt(x * x + z * z) / radius) * 100; | ||
const value = v * 100; | ||
const [r, g, b] = hsvToRgb(hue, saturation, value); | ||
|
||
points.push(new THREE.Vector3(x, y, z)); | ||
colors.push(new THREE.Color(r, g, b)); | ||
} | ||
} | ||
|
||
const geometry = new THREE.BufferGeometry(); | ||
geometry.setFromPoints(points); | ||
|
||
const colorArray = new Float32Array(colors.length * 3); | ||
colors.forEach((color, i) => { | ||
colorArray[i * 3] = color.r; | ||
colorArray[i * 3 + 1] = color.g; | ||
colorArray[i * 3 + 2] = color.b; | ||
}); | ||
geometry.setAttribute('color', new THREE.BufferAttribute(colorArray, 3)); | ||
|
||
const material = new THREE.PointsMaterial({ | ||
size: 0.02, | ||
vertexColors: true, | ||
transparent: true, | ||
opacity: 0.8 | ||
}); | ||
|
||
const pointCloud = new THREE.Points(geometry, material); | ||
coneGroup.add(pointCloud); | ||
|
||
coneGroup.position.set(2, 0, 0.5); | ||
return coneGroup; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as THREE from 'three'; | ||
|
||
export function createCube() { | ||
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1); | ||
const cubeMaterial = new THREE.ShaderMaterial({ | ||
vertexShader: ` | ||
varying vec3 vPosition; | ||
void main() { | ||
vPosition = position; | ||
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); | ||
} | ||
`, | ||
fragmentShader: ` | ||
varying vec3 vPosition; | ||
void main() { | ||
vec3 color = vPosition; | ||
if(abs(vPosition.x) == 0.5 || abs(vPosition.y) == 0.5 || abs(vPosition.z) == 0.5) { | ||
gl_FragColor = vec4(color, 0.0); | ||
} else { | ||
gl_FragColor = vec4(color, 0.3); | ||
} | ||
} | ||
`, | ||
transparent: true, | ||
side: THREE.DoubleSide, | ||
depthWrite: false | ||
}); | ||
|
||
const cube = new THREE.Mesh(cubeGeometry, cubeMaterial); | ||
cube.position.set(0.5, 0.5, 0.5); | ||
return cube; | ||
} | ||
|
||
export function createColorPoints() { | ||
const pointsGroup = new THREE.Group(); | ||
const sphereGeo = new THREE.SphereGeometry(0.01); | ||
|
||
for(let x = 0; x <= 1; x += 0.1) { | ||
for(let y = 0; y <= 1; y += 0.1) { | ||
for(let z = 0; z <= 1; z += 0.1) { | ||
const sphereMat = new THREE.MeshBasicMaterial({ | ||
color: new THREE.Color(x, y, z), | ||
transparent: true, | ||
opacity: 0.6 | ||
}); | ||
const sphere = new THREE.Mesh(sphereGeo, sphereMat); | ||
sphere.position.set(x, y, z); | ||
pointsGroup.add(sphere); | ||
} | ||
} | ||
} | ||
|
||
return pointsGroup; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.