-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support EAC & Stereo EAC Videos from youtube #5
Comments
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cube to Sphere Transformation</title>
<style>
body { margin: 0; }
canvas { display: block; }
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
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);
document.body.appendChild(renderer.domElement);
// Create a cube geometry with subdivisions
const geometry = new THREE.BoxGeometry(1, 1, 1, 10, 10, 10); // The 4th, 5th, and 6th arguments add subdivisions
// Access the position attribute of the geometry
const positionAttribute = geometry.attributes.position;
const sphereRadius = 1.5; // Set the radius of the sphere
// Loop through each vertex and project onto the sphere
for (let i = 0; i < positionAttribute.count; i++) {
const x = positionAttribute.getX(i);
const y = positionAttribute.getY(i);
const z = positionAttribute.getZ(i);
// Calculate the length (distance from origin)
const length = Math.sqrt(x * x + y * y + z * z);
// Normalize and scale to sphere radius
const newX = (x / length) * sphereRadius;
const newY = (y / length) * sphereRadius;
const newZ = (z / length) * sphereRadius;
// Set the new vertex positions
positionAttribute.setXYZ(i, newX, newY, newZ);
}
// Update the geometry after modification
positionAttribute.needsUpdate = true;
// Create a basic material and mesh
const material = new THREE.MeshBasicMaterial({color: 0x00ff00, wireframe: true});
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
camera.position.z = 5;
// Render loop
function animate() {
requestAnimationFrame(animate);
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html> |
port old threejs |
code gen: To update the above code to use // Define geometry for the cube
const movieGeometry = new THREE.BoxGeometry(256, 256, 256);
// Update UV mapping for the cube
const uvAttribute = new Float32Array([
// Right face
0.333, 1, 0.666, 1, 0.666, 0.5,
0.666, 0.5, 0.333, 0.5, 0.333, 1,
// Left face
0, 1, 0.333, 1, 0.333, 0.5,
0.333, 0.5, 0, 0.5, 0, 1,
// Top face
0.666, 1, 1, 1, 1, 0.5,
1, 0.5, 0.666, 0.5, 0.666, 1,
// Bottom face
0, 0.5, 0.333, 0.5, 0.333, 0,
0.333, 0, 0, 0, 0, 0.5,
// Front face
0.333, 0.5, 0.666, 0.5, 0.666, 0,
0.666, 0, 0.333, 0, 0.333, 0.5,
// Back face
0.666, 0.5, 1, 0.5, 1, 0,
1, 0, 0.666, 0, 0.666, 0.5
]);
// Assign the custom UVs to the geometry
movieGeometry.setAttribute('uv', new THREE.BufferAttribute(uvAttribute, 2));
// Create material using the video texture
const movieMaterial = new THREE.MeshBasicMaterial({
map: videoTexture,
side: THREE.BackSide
});
// Create the mesh with the geometry and material
const movieScreen = new THREE.Mesh(movieGeometry, movieMaterial);
// Position and rotate the mesh
movieScreen.position.set(position.x, position.y, position.z);
movieScreen.rotation.y = -Math.PI;
// Add to the scene
scene.add(movieScreen); Key Updates:
This code ensures compatibility with modern versions of Three.js. Make sure you properly calculate UVs as per your texture layout. |
Specs:
https://gist.github.com/gtk2k/2aa7aa1a1c6beeb9f9829c7be335a08f
The text was updated successfully, but these errors were encountered: