Loading an image into a Three.js scene

Attempting to display an image in my 360-degree scene, but encountering issues with the code:

<script>

var controls, camera, scene, renderer, element;
var container;
var sceneCube;


init();
animate();

function init() {

    // CAMERAS

    camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 100000 );
    camera.position.set( 0, 0, 1000 );
    cameraCube = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 100000 );

    //

    renderer = new THREE.WebGLRenderer();
    renderer.autoClear = false;
    renderer.setSize( window.innerWidth, window.innerHeight );

    element = renderer.domElement;
    container = document.getElementById('webglviewer');
    container.appendChild(element);
    //



    controls = new THREE.OrbitControls( camera, element );

    controls.noPan = true;
    controls.noZoom = true;



    // SCENE

    scene = new THREE.Scene();
    sceneCube = new THREE.Scene();


    // Textures

    var r = "textures/cube/Bridge2/";
    var urls = [ r + "face_4_2048.jpg", r + "face_2_2048.jpg",
        r + "face_6_2048.jpg", r + "face_5_2048.jpg",
        r + "face_1_2048.jpg", r + "face_3_2048.jpg" ];

    textureCube = THREE.ImageUtils.loadTextureCube( urls );
    textureCube.format = THREE.RGBFormat;
    textureCube.mapping = THREE.CubeReflectionMapping;

    // Materials

    var cubeShader = THREE.ShaderLib[ "cube" ];
    var cubeMaterial = new THREE.ShaderMaterial( {
        fragmentShader: cubeShader.fragmentShader,
        vertexShader: cubeShader.vertexShader,
        uniforms: cubeShader.uniforms,
        depthWrite: true,
        side: THREE.BackSide
    } );

    cubeMaterial.uniforms[ "tCube" ].value = textureCube;

    // Skybox

    cubeMesh = new THREE.Mesh( new THREE.BoxGeometry( 100, 100, 100 ), cubeMaterial );
    sceneCube.add( cubeMesh );




    var materials = THREE.ImageUtils.loadTexture('badge.png');
    myImg = new THREE.Mesh(
            new THREE.BoxGeometry( 562, 562, 562, 1, 1, 1 ),
            new THREE.MeshFaceMaterial( materials ) );
    
    // Attempting to add image to the sceneCube
    sceneCube.add( myImg );

    // Initialization complete
}



function onWindowResize() {

    var width = container.offsetWidth;
    var height = container.offsetHeight;

    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();

    cameraCube.aspect = window.innerWidth / window.innerHeight;
    cameraCube.updateProjectionMatrix();

    renderer.setSize( window.innerWidth, window.innerHeight );

}

//

function animate() {

    requestAnimationFrame( animate );

    render();

    controls.update();

}

function render() {

    var timer = -0.0002 * Date.now();

    camera.lookAt( scene.position );
    cameraCube.rotation.copy( camera.rotation );

    renderer.render( sceneCube, cameraCube );
    renderer.render( scene, camera );

}

Error message encountered at this position:

        var materials = THREE.ImageUtils.loadTexture('badge.png');
    myImg = new THREE.Mesh(
            new THREE.BoxGeometry( 562, 562, 562, 1, 1, 1 ),
            new THREE.MeshFaceMaterial( materials ) );
    
    // Adding image to sceneCube leads to error
    sceneCube.add( myImg );

Error Message Received: three.min.js:538 Uncaught TypeError: Cannot read property 'visible' of undefined

Appreciate any assistance or insights!

Answer №1

It appears that the code you provided may be designed for a different version of three.js than the one currently in use. It seems like your code aligns more closely with three.js version r72.

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

Exploring ways to incorporate or eliminate animations on mobile devices using html/css

Is it possible to control animations on different devices using media queries? For example, can you show an animation only on mobile devices while hiding it on desktop or laptop? Conversely, is there a way to add an animation specifically for mobile device ...

Incorporating SOAP Service into AngularJS Using AngularJS Data Model

As an experienced Flex Developer diving into the world of AngularJS, I must admit, it's quite confusing!!! Currently, my focus is on making a service call to my backend server (located on the same domain) using a SOAP WSDL Request and populating the ...

Choosing options from two separate dropdown menus with the same CSS class name using JavaScript or jQuery: A guide

I am looking to update the values of two dropdowns using the same CSS properties, similar to the design shown in the attached image. Here is the HTML code snippet for reference: <div class="container-fluid" role="main" style="margin-top: 100px;"> ...

I'm puzzled by the "Uncaught TypeError:" error message and can't seem to figure it out

I'm having trouble displaying the value of 'true' within my objects and keep encountering an error message. Uncaught TypeError: Cannot set property 'toDoIsRemoved' of undefined at removeTask (main.js:85) at HTMLButtonElemen ...

Tips for effortlessly enlarging an element

When you click on "#sidebarnav>li", the following happens: 1) The second child of it - <ul> element will expand and its class toggles between "collapse" and "collapse in". 2) "#sidebarnav>li" will receive the "active" class. 3) The "aria-ex ...

Display information when hovering over a tag

I'm working on adding a feature where hovering over a link will display a tooltip. For reference, here is an example: https://i.stack.imgur.com/K84Wf.png Are there any alternative JavaScript libraries that offer this functionality? (ideally similar ...

Shade the div if the name of the child element matches the location's hash

I am currently working on an AngularJS web project. My goal is to highlight a specific div when clicking on an anchor link. The structure of the HTML is as follows: <div interaction-list-item="" sfinx-interaction="interaction" class="ng-isolate-scope" ...

What is the reason behind the momentary functionality of v-for?

I'm facing a strange issue while working with Vue.js. I'm not sure if the problem lies with my code or if it's a bug in the framework. Here's the scenario: When I use v-for with a comma before it (v-bind), there are no errors but nothi ...

How can you incorporate a displacement map onto a mesh using the Three.js framework?

JSFiddle: http://jsfiddle.net/ma791nd8/1/ I'm encountering some challenges due to outdated tutorials and limited documentation, which is why I've decided to seek assistance here. After reviewing one of the examples provided, I created a jsfiddl ...

Guide to scraping a website using node.js, ASP, and AJAX

I am currently facing an issue where I need to perform web scraping on this specific webpage form. This webpage is dedicated to vehicle technical reviews, and you can try inputting the car license CDSR70 for testing purposes. As mentioned earlier, I am u ...

Error encountered: JSON parsing failure at position 351 due to an unexpected token "}". This issue was found within the JSON object containing the property "license" with the value of "

I'm a newcomer to JavaScript and JSON, and I'm currently in the process of uploading my NPM package. However, I keep encountering an error when I attempt to publish it: Unexpected token } in JSON at position 351 while parsing near '..."lice ...

Protractor: Command Line Tips for Providing URLs

When running a Protractor test, the URL is usually specified in the spec file. However, it is possible to also include it directly in the spec.js file: browser.get('www.google.com'); To run the test, the command would be: protractor conf.js I ...

Utilizing Twitter API authentication to prevent hitting rate limits

Currently, I am implementing the Twitter API to showcase the most recent tweets from 4 distinct users on my webpage. It seems that once a certain number of calls are made, an error message appears stating "NetworkError: 400 Bad Request" and prevents the tw ...

When the click event occurs, add a class. After a delay using a timeout function, remove the added

I am currently using Jimdo and I have a section where I can edit all the codes, which is working fine except for one feature. Any assistance would be greatly appreciated! Here is the code that adds a class to an animated SVG image with its status set as d ...

A function in Jasmine for testing that returns a promise

I have implemented the following function: function getRepo(url) { var repos = {}; if (repos.hasOwnProperty(url)) { return repos[url]; } return $.get(url) .then(repoRetrieved) .fail(failureHandler); function ...

New feature alert! Introducing the Mentio JS menu now available at the bottom of the webpage

I am currently working on creating a Twitter-style @mention feature using Angular JS and a library called MentioJS. One issue I encountered is that after dynamically adding content to the page, a mysterious menu appears at the bottom of the page. This pro ...

The Backbone.js template does not automatically inherit attributes from the model

Hey there, I'm currently working on setting up a simple SPA using Backbone for testing purposes. However, when I try to render my view, the Underscore template doesn't seem to be picking up any attributes from my model. I've been trying to t ...

Is there a way to resolve this issue? (An error occurred: TypeError - res.json is not a valid function)

When attempting to add an object to my MongoDB database const response = await fetch("/api/contact", { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json", }, }); I encounter the error message ...

Using jQuery, you can utilize the $.when() function with both a single deferred object and an

In my current jquery setup, I am working with two variables. trackFeatures - representing a single ajax request, and artistRequests - an array of ajax requests. I am looking for a way to create a condition that triggers when both trackFeatures and artist ...

Tips for launching a colorbox within a specific div container

I am looking to implement a color box that opens without a popup and only shows/hides inside a specific div. Is it possible to target a div to open the colorbox content? <a href='#myGallery' class='group'>click here</a> &l ...