Mistakes when showcasing images within a shape using Three.js

I am facing an issue while trying to showcase images on all faces of a polyhedron using three.js r71. I am creating the geometry by loading a JSON file containing the necessary data. Additionally, I have placed a plane beneath the polyhedron. However, upon execution, I encounter an error and I seek assistance in understanding its meaning or identifying any mistakes in my approach. Here is the error message that appears in the JavaScript console:

[.WebGLRenderingContext-0888D200]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1

WebGL: too many errors, no more errors will be reported to the console for this context.

Below is the relevant JavaScript code snippet:

var four;

var meshFour;

var scene = new THREE.Scene();

function init() {
    var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
    var renderer = new THREE.WebGLRenderer();
    renderer.setClearColor(new THREE.Color(0xEEEEEE, 1.0));
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.shadowMapEnabled = true;
    var planeGeometry = new THREE.PlaneGeometry(60, 40, 1, 1);
    var planeMaterial = new THREE.MeshLambertMaterial({color: 0xffffff});
    var plane = new THREE.Mesh(planeGeometry, planeMaterial);
    plane.receiveShadow = true;
    plane.rotation.x = -0.5 * Math.PI;
    plane.position.x = 0;
    plane.position.y = 0;
    plane.position.z = 0;

    //LOADING GEOMETRY
    var loaderFour = new THREE.JSONLoader();
    var materialsArray = [];
    materialsArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture("./resources/images/IPT.PNG")}));
    materialsArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture("./resources/images/Alerts.png")}));
    materialsArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture("./resources/images/action-item-tracking.png")}));
    materialsArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture("./resources/images/admin.png"}));
    
    for(var i = 0; i <= 3; i++) {
        materialsArray[i].map.minFilter = THREE.LinearFilter;
    }
    loaderFour.load("./resources/json/tetrahedron-try.json", function (model) {

        var materialFour = new THREE.MeshFaceMaterial(materialsArray);

        four = new THREE.Mesh(model, materialFour);//issue according to three.js
        four.translateY(1);
        four.scale = new THREE.Vector3(3, 3, 3);
        meshFour = THREE.SceneUtils.createMultiMaterialObject(four, materialFour);
        scene.add(four);
    });

    camera.position.x = 20;
    camera.position.y = 20;
    camera.position.z = 20;
    camera.lookAt(new THREE.Vector3(0, 0, 0));
    
    var spotLight = new THREE.SpotLight(0xffffff);
    spotLight.position.set(-40, 60, 10);
    spotLight.castShadow = true;
    scene.add(spotLight);
    scene.add(plane);


    document.getElementById("WebGL-output").appendChild(renderer.domElement);

    render();
    
    function render() {
        requestAnimationFrame(render);
        renderer.render(scene, camera);
    }
    
}

window.onload = init();

The contents of the JSON file used for defining the shape are displayed below:

{
    "metadata": {
        "type": "Geometry",
        "vertices": 4,
        "uvs": 1,
        "faces": 4,
        "generator": "io_three",
        "version": 3,
        "normals": 4
    },
    "uvs": [[0.250046,0.433025,0.749954,0.433025,0.5,0.865958,0.999907,0.865957,9.3e-05,0.865957,0.5,9.3e-05]],
    "faces": [40,0,1,2,0,1,2,0,1,2,40,3,2,1,3,2,1,3,2,1,40,3,0,2,4,0,2,3,0,2,40,3,1,0,5,1,0,3,1,0],
    "normals": [-0.471389,-0.333323,0.816492,-0.471389,-0.333323,-0.816492,0.942808,-0.333323,0,0,1,0],
    "vertices": [-2.42416,0,4.19877,-2.42416,-0,-4.19877,4.84832,0,-0,-0,6.85655,-0],
    "name": "Tetrahedron.001Geometry.3"
}

Answer №1

Looking at your json file, I see that you have specified "uvs": 1, which aligns with the images provided:

https://i.sstatic.net/kCI3Rm.png https://i.sstatic.net/HzLZUm.png

It appears that you are applying one texture to two faces based on the uv's. This suggests a potential issue with how your model was created.

You can view my version of the fiddle (http://jsfiddle.net/dfnkhbjm/), although it may not work due to the Access-Control-Allow-Origin problem. If you save and run it locally, it should function correctly.

Answer №2

I encountered a similar issue, which seems to be tied to the 71st version. Fortunately, I found that the problem has been resolved in the more stable 72nd version, even though it hasn't been officially released yet. More details can be found at https://example.com/issue1234.

To access the latest 72nd version of the software, visit here.

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

Perform an AJAX call from the main file after inserting data using AJAX beforehand

I am in need of assistance with a question I have. On a page, an AJAX function is executed after the page finishes loading, creating a table in PHP that contains two buttons: one for changing passwords and the other for deleting. This table is then injecte ...

The disappearance of the "Event" Twitter Widget in the HTML inspector occurs when customized styles are applied

Currently, I am customizing the default Twitter widget that can be embedded on a website. While successfully injecting styles and making it work perfectly, I recently discovered that after injecting my styles, clicking on a Tweet no longer opens it in a ne ...

What is the best way to fit a non-square texture onto a geometric plane in Three.js using "background-size:cover"?

I am seeking to replicate the behavior of the "background-size:cover" CSS property for my texture. My approach involves working with UV coordinates. After consulting this answer, I began developing a solution: Three.js Efficiently Mapping UVs to Plane I ...

What is the process for changing a JavaScript date to the Hijri format?

Greetings! I am currently working on a web application using AngularJS/JavaScript. In my project, I have implemented a date picker and I am capturing dates from the front end. My goal is to save the selected date in the database in Hijri format. To achieve ...

Error in Next.js when the value of the target does not change in React-Select's

I am brand new to the world of react/nextjs and I keep encountering a frustrating error that says "Cannot read properties of undefined (reading 'value')". Despite trying various approaches, including treating select as a simple HTML tag, I have s ...

Fade out when the anchor is clicked and fade in the href link

Is it possible to create fade transitions between two HTML documents? I have multiple HTML pages, but for the sake of example, let's use index.html and jobs.html. index.html, jobs.html Both pages have a menu with anchor buttons. What I am aiming to ...

Rzslider not functioning properly due to CSS issues

I am facing an issue where rzslider is not appearing in my app. However, when I copy the code to an online editor, it works perfectly fine. Below is the code snippet: var app = angular.module('rzSliderDemo', ['rzModule', 'ui.boo ...

Break up the JavaScript code into modules to avoid duplicating blocks of code detected by

There is a block of code that SONAR has identified as duplicate. I am looking for guidance on how to address this issue. import fields from '../../utils/utils'; dispatch( fields.change([ { id: 'userData', value: ...

Why is this <div> element refusing to budge according to my jQuery commands?

Currently embarking on a jQuery coding challenge where I am attempting to maneuver a circle around the page in a square pattern. Numerous methods have been tested with no success thus far. While I would like to showcase my various attempts, it would prove ...

Having trouble fetching JSON data using AJAX

Having trouble retrieving Json text from servlet response. The servlet code is functioning properly. It seems there may be an issue with my Ajax code. It doesn't seem to return anything. Do I need a specific jar file for this task? Below you can find ...

Using TypeScript to Add Items to a Sorted Set in Redis

When attempting to insert a value into a sorted set in Redis using TypeScript with code like client.ZADD('test', 10, 'test'), an error is thrown Error: Argument of type '["test", 10, "test"]' is not assigna ...

Obtain the `react-router` Redirect from a collaborative component library

I'm currently working on a component library in (React) that I plan to share. One of the components I want to include is the PrivateRoute. However, I face an error when trying to import this component from the module library into another application: ...

There seems to be an issue with parsing the JSON data due to a

Currently, I am in the process of learning about the JSON Parser. I have been following a tutorial on androidhive and attempted to replicate their code. However, I encountered some errors along the way, such as: 11-22 17:27:12.132: E/AndroidRuntime(1938) ...

Can Angular Universal SSR be activated specifically for Googlebot User Agents?

I am aiming to activate Angular Universal SSR only when the User Agent is identified as Googlebot. However, I am uncertain about how to instruct Angular Universal SSR to deliver server side rendered HTML exclusively if the User Agent is Googlebot. server ...

HTML Elements for Displaying Undefined JSON Information

Hey there, I'm new to programming and I'm looking to display JSON data in an HTML table using jQuery. The issue I'm facing is that the output from the server shows up as 'undefined'. My goal is to have a constantly updated list of ...

Using Node.js: Retrieving a value from a function with an asynchronous call within

Is it possible to create a synchronous function that generates a random string and checks for existing files on Amazon Web Service S3 with the same name? The challenge lies in making this function synchronous, considering the asynchronous nature of calli ...

Array of Gross Pay for Employee Payroll

I have been tasked with developing a code that calculates an employee(s) gross pay, with the condition that the hourly pay cannot fall below $8. Despite no visible errors during compilation, my code fails to execute. public static void main(String[] args) ...

Angular and Node.js Integration: Compiling Files into a Single File

I have a question, is it possible to include multiple require js files in one file? If so, how can I create objects from them? Calling 'new AllPages.OnePage()' doesn't seem to work. To provide some context, I'm looking for something sim ...

What is the best way to determine and showcase the hours that have passed since the user's initial visit to the website?

Can someone provide guidance on how to finalize the hoursSinceFirstVisit() function implementation? Additionally, what content should be displayed on my HTML page? $(document).ready(function() { startTimer(); }); function startTimer() { setInte ...

The AngularJS routing template fails to load

I am currently working on the app.js file: 'use strict'; var app = angular.module('app', [ 'auth0', 'angular-storage', 'angular-jwt', 'ui.router', 'Environment', ...