Unable to utilize MeshLambertMaterial with a custom BufferGeometry

I recently created a basic program using Three.js to generate pyramidal roof shapes. Unfortunately, when rendering these shapes along with other objects like extrusions and cubes in BufferGeometry with a MeshLambertMaterial, the roofs appear as if they were generated with a MeshBasicMaterial. I'm unsure of what could be causing this issue since this is just a simplified version of my code:

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
        <script src="three.min.js"></script>
        <script src="OrbitControls.js"></script>
        <style type="text/css">
            body{margin:0;}
        </style>
    </head>
    <body>
        <script>
var camera, SCENE, renderer, controls, SUN, OBJ;

init();
animate();

function init() {
    camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 1000 );

    SCENE = new THREE.Scene();
    SCENE.background = new THREE.Color( 0xBBDDFF );

    SUN = new THREE.DirectionalLight( 0xffffff, 0.6 );
    SCENE.add( SUN );
    SCENE.add( new THREE.AmbientLight( 0xcccccc, 0.8 ) );


    renderer = new THREE.WebGLRenderer( { antialias: true } );
    renderer.setPixelRatio( window.devicePixelRatio );
    renderer.setSize( window.innerWidth, window.innerHeight );

    controls = new THREE.OrbitControls( camera, renderer.domElement );
    controls.minDistance = 1;
    controls.maxDistance = 1000;

    var geometry = new THREE.BufferGeometry();
    var material = new THREE.MeshLambertMaterial( { color:0xff0000} );
    vertices = new Float32Array([
        0,0,0,
        0,1,0,
        1,0,0,

        0,0,0,
        0,0,1,
        0,1,0,

        0,0,0,
        1,0,0,
        0,0,1,

        0,1,0,
        0,0,1,
        1,0,0,
        ]);
    geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
    OBJ = new THREE.Mesh(geometry,material);
    SCENE.add(OBJ);

    camera.position.set(OBJ.position.x,10,OBJ.position.z-10);
    camera.lookAt(OBJ.position);
    controls.target.set(OBJ.position.x,1,OBJ.position.z);
    camera.updateProjectionMatrix();

    SUN.position.copy( camera.position );
    SUN.target = OBJ;

    document.body.appendChild( renderer.domElement );

    renderer.render( SCENE, camera );
}

function animate() {
    requestAnimationFrame( animate );
    renderer.render( SCENE, camera );
}
        </script>
    </body>

Answer №1

When working on your project, it seems like you defined a MeshLambertMaterial in the 'material' variable. However, when creating your Mesh object, you referenced a 'vertexColorMaterial' variable that hasn't been mentioned previously. This could potentially be causing issues within your code. It's worth investigating further to see if this discrepancy is what's causing the problem.

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

Strategies for re-rendering a React component when the useState value remains the same or retains its previous value

I am currently using a useState hook to store the value of selectFolderId: const [selectFolderId, useSelectFolderId] = React.useState(documentStore.id) Despite trying to update selectFolderId with the new value from DocumentStore by using a useEffect hook ...

Difficulty loading AJAX with autocomplete feature. Any suggestions?

I have created a jQuery autocomplete feature that works correctly, but when the value is removed using the Backspace key, the 'LOADING...' message remains visible instead of hiding. How can I make it so that after removing the value with the Back ...

Issue with React form not appearing on web browser

I'm having trouble getting the form to show up on the browser. For some reason, the formComponentDict variable is not displaying any of the form steps. Can anyone point me in the right direction? Any assistance would be greatly appreciated. Thank you ...

By implementing Async.parallel, I ensure that the lifetime of my parameter does not exceed the duration of the asynchronous calls in NodeJS when working with MongoDB

After analyzing the code and its asynchronous behavior, it appears that the 'recipeData' array may not persist long enough to handle the asynchronous callbacks. To mitigate this, I created a copy of the data in a global array. However, I am encou ...

Steps for generating a fresh type denotation from a value within an object

Is it possible to create a new type alias based on an object's values? const test = { 'a': ['music','bbq','shopping'], 'b': ['move','work'] }; How can we extract this information f ...

Modifying tag classes dynamically with JavaScript

I am working on creating a list of projects where the user can select one as the default project for future use in other processes. The issue I am facing is that each project in the list has a unique id and by default, they all have the RegularIcon class ...

When attempting to retrieve information, the variable is displaying as undefined, although the console log is indicating that data

Here is the code I am currently using: function get_last_chat_time(steamid){ if(!db_connect) { return 0; } chat_db.aggregate( [ {"$match":{"name":"chat-msg",steamid: steamid}}, { "$sort" : { date : -1 } }, {"$limit" : 1} ...

The returned type of intersected functions in Typescript does not match the inferred type

While attempting to extract the return type of an intersected request, I encountered a discrepancy between the return type and the inferred type. Check out the shortened URL for more details: https://tsplay.dev/mAxZZN export {} type Foo = (() => Promis ...

Having issues with the script not functioning when placed in an HTML document or saved as a .js file

Even though the database insertion is working, my script doesn't seem to be functioning properly. The message "successfully inserted" appears on the saveclient.php page instead of the index.html. In my script (member_script.js), I have placed this in ...

Guide to centering a Material UI Table on a webpage

Is it possible to center the <Table> within a fixed width <div>, and have a scrollbar appear when the browser is resized, while maintaining the fixed width of the <Table>? Thanks in advance. This is my current setup: <div> ...

The order of execution is not maintained for $.getJSON() calls within the $.each() loop

As I iterate through an HTML table, I am making a $.getJSON() request based on the data in each row. My goal is to retrieve the data from that $.getJSON call and update the corresponding row with it. Unfortunately, when I run my code, it seems to be execu ...

Substituting JSON objects with alphabets

When running this code, the expected output will display the name and the choices. To clarify, I aim to substitute the values of Not effective, Neither effective nor Effective, Effective with "A", "B", and "C", respectively. ...

Code snippet for calculating the size of an HTML page using JavaScript/jQuery

Does anyone know of a way to calculate and display the size/weight (in KB) of an HTML page, similar to what is done here: Page size: 403.86KB This would include all resources such as text, images, and scripts. I came across a Pelican plugin that does th ...

Steps to temporarily turn off Backbone.sync for a fresh model and then reactivate it once the user clicks the save button

I am currently working with a Backbone collection model that consists of sub-models as elements, along with views to edit it. My objective is to have the syncing functionality "turned off" initially when the model is created, so that the back end is not c ...

Leveraging HTTP/2 in conjunction with angularJS

As I was exploring ways to improve the performance of my web application, I came across HTTP/2. After learning about its features that can enhance website speed, I decided to implement it. Upon upgrading my browser to the latest version to enable HTTP/2 s ...

Node-express can seamlessly switch between multiple databases dynamically

After extensive searching for a solution to my problem, I have come up empty-handed. If anyone has experience in similar situations, your help would be greatly appreciated. I have developed an application server in Node Express with MySQL as the database. ...

What is the best way to assign the "active" class to a navigation list item using JavaScript within Bootstrap 4?

Update: just to clarify, I'm working on activating the navbar button based on the current page. I have a navigation bar set up and I am trying to dynamically add an "active" class to the li element when you are on that specific page. However, for som ...

obtain data from an array using Angular 5

i need assistance with retrieving values from an array. Below is my code snippet: this.RoleServiceService.getRoleById(this.id).subscribe(data => { this.roleData.push(data['data']); console.log(this.roleData); }) however, the resulting ar ...

Order an array in Javascript based on the day of the month

I am trying to create a unique function that changes the order of a string based on the day of the month. For instance, if the input string is "HELLO" and today's date is the 1st of April, the output should be "LHEOL". On the 2nd of April, it should ...

Implementing a Timer on an HTML Page with JavaScript

I am looking to add a timer to my HTML page using JavaScript. The timer should get the selected date and time from an input field <input type="date" /> and control it. If the time difference between the current time and the selected time is less than ...