Is it possible to integrate an HTML page into a Mesh using three.js and WebGLRenderer?

As a beginner in three.js, I am attempting to display an HTML page on a box object. While I have managed to achieve this using CSS3DRenderer, I am struggling to find a solution that allows me to maintain my original scene:

// Canvas
const canvas = document.querySelector('canvas.webgl')

// Scene
const scene = new THREE.Scene()

const monitorMaterial = new THREE.MeshPhongMaterial( {color: "darkgrey"} );
const monitorLength = 12
const monitorWidth = 7

const monitorX = 10
const monitorY = 5.5
const monitorZ = 10

const monitorGeometry = new THREE.BoxGeometry(monitorLength, monitorWidth, 0.25, 100, 50, 10);
const monitor = new THREE.Mesh( monitorGeometry, monitorMaterial );
monitor.position.x = monitorX
monitor.position.y = monitorY
monitor.position.z = monitorZ

const baseGeometry = new THREE.CylinderGeometry(3, 3, 0.25, 100);
const base = new THREE.Mesh( baseGeometry, new THREE.MeshPhongMaterial({ color:  "black"}) );
base.position.x = monitorX
base.position.y = 0.5
base.position.z = monitorZ

const bracketGeometry = new RoundedBoxGeometry( 0.5, 4, 0.5, 1, 1 );
const bracket = new THREE.Mesh( bracketGeometry, new THREE.MeshPhongMaterial({ color:  "black"}) );
bracket.position.x = monitorX
bracket.position.y = 2
bracket.position.z = 9.2
bracket.rotation.x = -2.75

/**
 * Camera
 */
// Base camera
const camera = new THREE.PerspectiveCamera(50, sizes.width / sizes.height, 0.1, 100)
camera.position.x = 36
camera.position.y = 35
camera.position.z = 65
scene.add(camera)

// Controls
const controls = new OrbitControls(camera, canvas)
controls.enabled = false
controls.enableDamping = true

/**
 * Renderer
 */
const renderer = new THREE.WebGLRenderer({
    canvas: canvas
})
renderer.setSize(sizes.width, sizes.height)
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
renderer.setClearColor( 0xffffff, 1);

/**
 * Animate
 */
const clock = new THREE.Clock()

const tick = () =>
{
    const elapsedTime = clock.getElapsedTime()

    // Update controls
    controls.update()

    // Render
    renderer.render(scene, camera)

    // Call tick again on the next frame
    window.requestAnimationFrame(tick)
   
}



I aim to modify the Mesh of the monitorMaterial to showcase an HTML site that users can interact with as they would with a regular website, but within the canvas and on the element.

Answer №1

To incorporate interactive HTML elements in a Three.js 3D environment, the use of a CSS3DRenderer is necessary. While this method may mimic the appearance of 3D using CSS transformations on an HTML <div>, it does not provide the same capabilities as true WebGL rendering. Certain features such as depth perception, occlusion, materials, lighting, and shadows are compromised when opting for this approach. Careful consideration must be given to the advantages and disadvantages before proceeding with integration.

For a practical demonstration, check out this showcase featuring a YouTube video player embedded within a 3D space through CSS transformations.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Do not include JavaScript-generated CSS when running Grunt's un-css task

Recently, I started using Grunt for minifying JavaScript and CSS files and I must say, it's an incredible tool. As I delved deeper into Grunt, I discovered the uncss module, which aids in optimizing the load time and size of CSS files, especially for ...

Is there a way to ensure that the background position remains stable and does not shift or collapse?

Still getting the hang of all this, but I'm making progress by learning on the go and enrolling in courses. Sometimes I face small obstacles like the one I'm encountering now. Everything looks great when the browser is at 100%, but when I minimi ...

Having difficulty linking a subclass in HTML with CSS

<div class="section-3"> <div class="section-3a"> <div class="section-3a(a)"> <p>light background color (header and sidebar)</p> </div> <div class="section-3a(b)"> <p>#FFFFFF</p> ...

Is it possible to obtain a user's public URL using the Facebook API in version 2?

In version 1, it is possible to obtain the user's public link by using the following endpoint: /v1.0/me function testAPI() { console.log('Welcome! Fetching your information....'); FB.api('/me', function(response) { ...

cannot successfully remove items from array

I'm working with an array called cartarray that has the following format. 1: {id: "1510-01-312-3501-OkqcPp3xJwfgmNinwGsKZmAa8xt1-1514542566148", name: "AIRPLANE UTILITY", price: "$90", quantity: "1"} 2: {id: "1510-00-033-6312-OkqcPp3xJwfgmNinwGsKZmA ...

React, Axios, and the PokeAPI are like a team of explorers navigating an

Trying to enhance my React abilities, I decided to follow this tutorial on creating a list of names using PokeAPI. However, I hit a roadblock at 11.35 into the tutorial while implementing the provided code snippets in both App.js and PokemonList.js: fu ...

Display element exclusively when nav-tab is in an active state in Bootstrap 4

I'm working on creating nav-tabs with a unique feature where an arrow is displayed only on the active tab. How can I make this arrow disappear when another tab is clicked? Alternatively, how can I move the arrow to point to the content of the selected ...

Ways to compare arrays and merge them into a single array with JavaScript

Here are two arrays of objects: Object 1: [ { "id":"30772", "posimage":"/b/l/blue-shirt_1_1.jpg", "position":"Position Chest", "tech":"Embroidery" }, { "id":"30772", "posimage":"/b/l/blue-shirt_1_1.j ...

Using setTimeout in a recursive function

Utilizing a recursive function to retrieve data from an external source, process it, and make additional calls if required. I require a method to pause prior to calling this external source numerous times in succession. How can I guarantee that I have co ...

Is it possible to create a sharing button on Facebook that includes a JSON attachment?

I currently have some code that consistently generates the json needed for my facebook app's streamPublish FBJS call in the desired format. Now, I am experimenting with facebook.connect and I would like to reuse the same json. While exploring facebook ...

What is the purpose of incorporating the replace function in my regular expression for Palindromes?

I'm currently tackling some challenges on FreeCodeCamp and I've hit a roadblock in a simple task which requires checking for palindromes. The solution provided involves the following step: str = str.replace(/[^a-zA-Z]/g, '').toLowerCas ...

Encountering the error message "React child cannot be an object" while trying to map over an imported object referencing components

I have an array in a separate file that I import and iterate over in another component. One of the properties within this array, labeled component, actually refers to a different individual component. I am attempting to render this component, but I keep e ...

Tips for preserving the Context API state when navigating between pages in Next.js

Currently, I am working on a project that involves using nextJs and TypeScript. To manage global states within my application, I have implemented the context API. However, a recurring issue arises each time I navigate between pages - my state re-evaluates ...

Is there a way to make res.render in node.js/express/mongo wait until the database search is finished before loading?

Having some difficulty with loading a table properly on my page because the information is not being passed to the ejs template before the page loads. I'm fairly new at this and could use some assistance! Just a heads up, owneditems consists of an ar ...

What is the technique for utilizing an array element as a parameter in the indexOf function?

I have encountered an issue with two arrays of values. I am trying to utilize the elements from one array as arguments for an indexOf function, but I consistently receive a -1 (indicating that the value is not found) even though I know the value exists in ...

Using an External Stylesheet with Polymer 2.0: A Step-by-Step Guide

I am still learning the ropes, so please bear with me... Currently, I am attempting to customize a Polymer 2.0 custom element by utilizing an external stylesheet. However, for some reason, the styles from the external stylesheet are not being applied to t ...

How can I display a list of relative urls in an android TextView?

I have a situation in my application where I am displaying a block of HTML content in a TextView, which has been extracted and parsed from a webpage. This HTML includes numerous links, with some being absolute and others relative. My goal is to allow the u ...

What is the best way to center text vertically within an image?

How can I vertically align a blog entry title on an entry thumbnail image? The image size changes with the window size and the title varies in length for each entry. After finding a website that successfully achieved this effect, I tried replicating it us ...

What advantages does using immutablejs offer compared to using object.freeze?

I've scoured the internet trying to find convincing reasons for using immutablejs instead of Object.freeze(), but I still haven't found a satisfactory answer! What are the advantages of working with non-native data structures in this library ove ...

Is it possible for jQuery to detect if an email was sent from the client's email account?

I am working towards a feature on my website where users fill out specific fields and then click "send email" to activate their email platform via "mailTo", with the email pre-populated for easy sending. The challenge lies in confirming if the user actuall ...