Skip to content
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

Open
mysterion opened this issue Apr 21, 2024 · 3 comments
Open

Support EAC & Stereo EAC Videos from youtube #5

mysterion opened this issue Apr 21, 2024 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@mysterion
Copy link
Owner

Specs:
https://gist.github.com/gtk2k/2aa7aa1a1c6beeb9f9829c7be335a08f

@mysterion mysterion added enhancement New feature or request help wanted Extra attention is needed labels Apr 21, 2024
@mysterion mysterion moved this to Todo in aframe-vr-player Jul 2, 2024
@mysterion
Copy link
Owner Author

<!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>

@mysterion
Copy link
Owner Author

mysterion commented Oct 8, 2024

https://github.com/videojs/videojs-vr/blob/fb110c98dececf00de01c804647c9ec55055ff81/src/plugin.js#L200

port old threejs faceVertexUvs to newer threejs geometry equivalent

@mysterion
Copy link
Owner Author

https://github.com/videojs/videojs-vr/blob/fb110c98dececf00de01c804647c9ec55055ff81/src/plugin.js#L200

port old threejs faceVertexUvs to newer threejs geometry equivalent

code gen:

To update the above code to use THREE.BufferGeometry and replace the deprecated faceVertexUvs, you can use BufferGeometry attributes like uv to assign texture coordinates. Here's the modernized code:

// 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:

  1. BufferGeometry with UV mapping:

    • The uvAttribute defines texture coordinates for each face.
    • Each face requires two triangles, with 3 vertices each, mapped to the corresponding texture.
  2. Using BufferAttribute:

    • The uv attribute is set using new THREE.BufferAttribute with the UV coordinates.
  3. Improved performance:

    • BufferGeometry is more efficient than the old Geometry class.

This code ensures compatibility with modern versions of Three.js. Make sure you properly calculate UVs as per your texture layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Status: Todo
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant