Skip to content

Commit

Permalink
split cube and cone
Browse files Browse the repository at this point in the history
  • Loading branch information
lilpacy committed Nov 15, 2024
1 parent 0a5aa02 commit e664f0f
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,34 +80,36 @@ controls.zoomSpeed = 1.2; // ズームの速度
controls.enableZoom = true;

// RGBカラーキューブの作成
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);
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);
}
}
`,
transparent: true,
side: THREE.DoubleSide,
depthWrite: false
});
`,
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);
scene.add(cube);
const cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
cube.position.set(0.5, 0.5, 0.5);
return cube;
}

// 現在位置を示すマーカーの作成
const markerGeometry = new THREE.SphereGeometry(0.04);
Expand Down Expand Up @@ -317,7 +319,6 @@ window.addEventListener('resize', () => {
});

animate();

// HSV円錐の描画関数を追加
function drawHSVCone() {
const canvas = document.getElementById('hsv-cone');
Expand Down Expand Up @@ -486,6 +487,10 @@ function createHSVCone() {
return coneGroup;
}

// シーンに追加
const cube = createCube();
scene.add(cube);

const hsvCone = createHSVCone();
scene.add(hsvCone);

Expand All @@ -501,3 +506,4 @@ const hsvMarkerMaterial = new THREE.MeshBasicMaterial({
});
const hsvMarker = new THREE.Mesh(hsvMarkerGeometry, hsvMarkerMaterial);
scene.add(hsvMarker);

0 comments on commit e664f0f

Please sign in to comment.