Encountering an error when rendering a mesh with multiple materials: "Unable to access property 'uniform' of undefined"

I recently exported a 3D model from Blender to a Three.js file, and it seems to have two different materials applied to distinct parts of it. Due to the complex nature of the model with numerous vertices and UV coordinates, I've decided not to include the code here. However, upon inspecting the model, I noticed that it indeed has two materials present. Therefore, I suspect that the error lies within my Three.js code. Notably, the model lacks bones, morph targets, and colors, which I am unsure is crucial for my specific application, potentially contributing to the issue at hand.

Here's an overview of what I have implemented so far:

var camera, scene1, scene2, raycaster, renderer, staticMesh , loader;

var highlighted, standard;

var mouse = new THREE.Vector2(), INTERSECTED;

init();
animate();

function init() {

    standard = new THREE.MeshLambertMaterial( { color: 0x9999ff } );
    highlighted = new THREE.MeshLambertMaterial( { color: 0xff0000 } )

    camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
    camera.position.z = 15;

    scene1 = new THREE.Scene();
    scene2 = new THREE.Scene();

    loader = new THREE.JSONLoader();

    loader.load( "abs.json", function( geometry ) {
        var mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: 0x9999ff } ) );
        mesh.position.y = -6;
        mesh.position.x = 0;
        scene2.add( mesh );
    } );

    loader.load( "bodyTest.json", function(geometry, material) {
            material[0] = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: 0x9999ff } ) );
            material[1] = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: 0x9999ff } ) );
            var materials = new THREE.MeshFaceMaterial(material);
            staticMesh = new THREE.Mesh( geometry, materials );
            scene1.add( staticMesh );
  } );

    // Additional lighting setup
    var directionalLight = new THREE.DirectionalLight(0xffffff);
    directionalLight.position.set(-1, -1, -1).normalize();
    scene1.add(directionalLight);

    directionalLight = new THREE.DirectionalLight(0xffffff);
    directionalLight.position.set(1, 1, 1).normalize();
    scene1.add(directionalLight);

    raycaster = new THREE.Raycaster();

    renderer = new THREE.WebGLRenderer({ antialiasing: true});
    renderer.setClearColor( 0xffffff );
    renderer.setSize( window.innerWidth, window.innerHeight );
    renderer.sortObjects = false;

    document.body.appendChild( renderer.domElement );
    document.addEventListener( 'mousemove', onDocumentMouseMove, false );
    window.addEventListener( 'resize', onWindowResize, false );
}

// Event listener for window resize
function onWindowResize() {
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize( window.innerWidth, window.innerHeight );
}

// Handling mouse movement
function onDocumentMouseMove( event ) {
    event.preventDefault();
    mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
    mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
}

function animate() {
    requestAnimationFrame( animate );

    scene1.rotation.y += 0.007;
    scene2.rotation.y += 0.007;

    /*    
        var vector = new THREE.Vector3( mouse.x, mouse.y, 1 ).unproject( camera );
        ...
    */

    renderer.render( scene2, camera );
    renderer.render( scene1, camera );
}

I have already commented out portions that I suspected might be causing errors, and testing without rendering one scene did not result in any issues.

Answer №1

Although I'm not entirely clear on how this solution worked, I stumbled upon it in a different scenario and surprisingly, it did the trick. The 'standard' material had already been defined as a lambert material earlier.

loader.load( "bodyTest.json", function(geometry) {
            var material = [];
            material.push( standard );
            material.push( standard );
            var materials = new THREE.MeshFaceMaterial(material);
            staticMesh = new THREE.Mesh( geometry, materials );
            scene1.add( staticMesh );
  } );

If anyone can shed light on what exactly my issue was, I'd greatly appreciate it.

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

Color section of a highcharts graph

Is there a way to paint the final section of a highcharts chart similar to what is shown in this image? Chart If painting the last section is not possible, would changing the color of those final datapoints be a feasible alternative? Thank you! ...

Vue routing stops working when there is no hash in the URL (no designated input file)

I am facing the need to operate Vue router in its default mode, known as hash mode, and unable to use it in history mode. In this mode, all my dynamic routes have a leading hash, like http://myurl.com/#/highlights. However, removing that initial hash, such ...

What is the proper way to showcase the hover effect on a nested ul list item in the DOM?

In an attempt to create a menu, I have written the following code: var sheet_nav = document.createElement('style'); sheet_nav.innerHTML = "nav{ margin: 100px auto; text-align: center;}"; document.head.appendChild(sheet_nav); var sheet_nav_ul = ...

Custom options titled MUI Palette - The property 'primary' is not found in the 'TypeBackground' type

I am currently working on expanding the MUI palette to include my own custom properties. Here is the code I have been using: declare module '@mui/material/styles' { interface Palette { border: Palette['primary'] background: Pa ...

When making an Ajax request to another website, the response received is in HTML format instead of

I am attempting to retrieve an array by making an AJAX GET request to a URL. Below is my controller code, which is hosted locally at localhost:3000 def merchant_ids merchants = Merchant.where(id: params[:id]).pluck(:merchant_name, :id, :merchant_city, ...

Display and conceal different sections using hyperlinks

Hey there, I'm back with another issue related to this code snippet on jsfiddle: https://jsfiddle.net/4qq6xnfr/9/. The problem I'm facing is that when I click on one of the 5 links in the first column, a second div appears with 3 links. Upon clic ...

Tips for patiently waiting for a promise to be fulfilled

Currently, I am faced with a scenario in a NodeJs framework where a specific function must be synchronous, yet I need to access a value asynchronously. Ideally, I would be able to return a promise, however, that is not feasible. To address this issue quic ...

Getting an image file to an API server using Node.js

I am looking to create an API server using node.js, and one of the requirements is to upload image files to it. While I have successfully implemented the logic for the GET method in my code, I am struggling with how to write the logic for the POST method ...

ng-class not updating using a combination of object and string

I am just starting to learn angular js and I recently came across the ng-class directive. Below is an example of how I have used it: ng-class="[{'highlighter-row-Class' : (file.id == 1 && file.processed), 'bold-row-Class' : ...

Enhancing user registration with Bootstrap 4 validation, ensuring password confirmation and disabling submit button until form is successfully validated

There are 3 input fields in a simple form, each with its own regex pattern. The 'Password' and 'Confirm Password' fields must match. If they don't, a message "Not Matching" is displayed. If they do, "Valid" is displayed. I am tr ...

Leveraging $http or $timeout in conjunction with $stateProvider in AngularJS

I am seeking guidance on loading a template for a specific state in Angular using $http after coming across this question on Stack Overflow: Is it possible to load a template via AJAX request for UI-Router in Angular? The documentation for ui.router demon ...

How should .has(), .get() and .set() be properly implemented for a JavaScript Map() within an ExpressJS server?

Feeling thrown off by javascript Map()? My query revolves around javascript Map() - the set, get, and has() functions. Despite thinking I was an expert, it seems I still have things to learn... Situation: I'm dealing with a 'global' map sto ...

Experimenting with parallelism using TypeScript/JS

Currently, I am tackling a TS project that involves testing concurrent code and its interactions with a database, specifically focusing on idepotency. My goal is to ensure that multiple requests modifying the same resource will either apply changes correct ...

Exploring AngularJS 1.x: Understanding the differences between isolated scope and using require with ngModel

Throughout my experience with Angular 1.x, I have always used isolated scope in my directives. However, recently I encountered a directive that solely utilized ngModel. This made me curious about the differences and potential issues when using both methods ...

Store the current function in the cache, incorporate new features, and execute those additions upon calling another function

I have a pre-existing function that I am unable to directly access or modify. Due to this limitation, I have resorted to caching the function and incorporating additional functions alongside it. This function loads periodically, sometimes occurring on pag ...

A guide on assigning a value to an array within a formgroup

if (Object.prototype.hasOwnProperty.call(data, 'checklists')) { if (Array.isArray(data.checklists)) { data.checklists.map((dt: any) => { dt.tasks.forEach((task: any) => { const dataArray = new FormGroup({ ...

when passing a JavaScript symbol in Django's JSON objects, it does not display properly

When working with Django (2.2), my goal is to send a JSON response in this format: return JsonResponse(data, safe=False) Within the data object, there is a value that looks like this: "unit": "\u33A5" (cubic meters). However, ...

Using JavaScript to add a class when hovering over an element

I am trying to customize the ul inside one of my li elements in the nav by adding a class when hovered. However, I am encountering an issue where the menu disappears when I try to click on it after hovering over it. I want to achieve this functionality usi ...

A problem arises when utilizing jQuery's $.isArray functionality

Successfully executing an AJAX post, the function test is utilized to process the passed data. $("#formID").submit(function (event) { $('#postError').html('').hide(); $('#postInfo').html('loading results').s ...

Guidelines for setting up Kendo notifications using an angularjs service

I have successfully defined the Kendo notification in my Angular service. However, when I try to use it with the line uiService.notify.error("You missed some required fields.");, I am getting an error that says "Cannot read property 'show' of nul ...