import * as THREE from "three"; import { OrbitControls } from…
- User
import * as THREE from "three"; import { OrbitControls } from "three/addons/controls/OrbitControls.js";
const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const renderer = new THREE.WebGLRenderer(); renderer.setSize(window.innerWidth, window.innerHeight); renderer.setAnimationLoop(animate); document.body.appendChild(renderer.domElement);
const controls = new OrbitControls(camera, renderer.domElement);
const geometry = new THREE.BoxGeometry(1, 1, 1); const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 }); const cube = new THREE.Mesh(geometry, material); scene.add(cube);
camera.position.z = 5; controls.update();
function animate() { cube.rotation.x += 0.01; cube.rotation.y += 0.01; controls.update(); renderer.render(scene, camera); }
"cube edge is not smooth"
- Assistant
To make the cube's edges appear smooth, you can enable antialiasing when creating the
THREE.WebGLRenderer. This helps to eliminate the jagged edges caused by aliasing.Here's the updated code with antialiasing enabled:
import * as THREE from "three"; import { OrbitControls } from "three/addons/controls/OrbitControls.js"; const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 ); // Enable antialiasing in the WebGLRenderer const renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(window.innerWidth, window.innerHeight); renderer.setAnimationLoop(animate); document.body.appendChild(renderer.domElement); const controls = new OrbitControls(camera, renderer.domElement); const geometry = new THREE.BoxGeometry(1, 1, 1); const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 }); const cube = new THREE.Mesh(geometry, material); scene.add(cube); camera.position.z = 5; controls.update(); function animate() { cube.rotation.x += 0.01; cube.rotation.y += 0.01; controls.update(); renderer.render(scene, camera); } - User
add responsive code
- Assistant
- User
//create globe
const geom = new THREE.SphereBufferGeometry(5, 180, 90);
//load map texture const loader = new THREE.TextureLoader(); loader.setCrossOrigin(""); const texture = loader.load("/earthspec1k.jpg"); texture.wrapS = THREE.RepeatWrapping; texture.wrapT = THREE.RepeatWrapping; texture.repeat.set(1, 1);
//particle texture const disk = loader.load("/circle.png");
const points = new THREE.Points( geom, new THREE.ShaderMaterial({ vertexColors: THREE.VertexColors, uniforms: { visibility: { value: texture, }, shift: { value: 0, }, shape: { value: disk, }, size: { value: 0.2, }, scale: { value: window.innerHeight / 2, }, }, vertexShader: ` uniform float scale; uniform float size; varying vec2 vUv; varying vec3 vColor;
void main() { vUv = uv; vColor = color; vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 ); gl_PointSize = size * ( scale / length( mvPosition.xyz )) * (0.3 + sin(uv.y * 3.1415926) * 0.6 ); gl_Position = projectionMatrix * mvPosition; } `, fragmentShader: ` uniform sampler2D visibility; uniform float shift; uniform sampler2D shape; varying vec2 vUv; varying vec3 vColor; void main() { vec2 uv = vUv; uv.x += shift; vec4 v = texture2D(visibility, uv); if (length(v.rgb) > 1.0) discard; gl_FragColor = vec4(vColor, 1.0); vec4 shapeData = texture2D(shape, gl_PointCoord); if (shapeData.a < 0.0625) discard; gl_FragColor = gl_FragColor * shapeData; } `, transparent: false, - Assistant
- User
- Assistant
- User
add pinpoint where is some one hover to show text
- Assistant
- User
no no you create wrong i am saying create some pin point on globe is show this user if user mouse hover to show text
- Assistant
- User
- Assistant
- User
give final who i just copy and paste
- Assistant