Deep Dive into Three.js: Unraveling the Mystery of PlaneBuffer

Can you please explain the difference between PlaneBufferGeometry and PlaneGeometry in detail? (revision 69)

Answer №1

PlaneBufferGeometry serves as a more memory-efficient option compared to PlaneGeometry. The object itself showcases various differences. For example, the vertices in PlaneBufferGeometry can be found in

PlaneBufferGeometry.attributes.position
instead of PlaneGeometry.vertices.

A quick look at the browser console can reveal more distinctions, but from my understanding, since the vertices are typically evenly spaced along a grid (X and Y), only the heights (Z) need to be specified for positioning a vertex.

Answer №2

When working with 3D graphics, it's important to understand the distinction between Geometry and BufferGeometry.

Geometry is designed as a user-friendly, object-oriented data structure, while BufferGeometry aligns more closely with how data is utilized in shader programs. BufferGeometry offers faster performance and lower memory usage, but Geometry provides greater flexibility for certain operations.

While I primarily use BufferGeometry due to its efficiency, learning about Geometry can be beneficial since it reflects the actual data structures employed by shaders.

For instance, with a PlaneBufferGeometry, you can manipulate vertex positions like so:

let pos = geometry.getAttribute("position");
let pa = pos.array;

To set z values at these positions:

var hVerts = geometry.heightSegments + 1;
var wVerts = geometry.widthSegments + 1;
for (let j = 0; j < hVerts; j++) {
    for (let i = 0; i < wVerts; i++) {
                            //+0 refers to x, +1 refers to y.
        pa[3*(j*wVerts+i)+2] = Math.random();
    }
}
pos.needsUpdate = true;
geometry.computeVertexNormals();

You could introduce randomness or even plot a function based on x and y coordinates within this loop. For optimized performance with PlaneBufferGeometry, consider adjusting y values in the outer loop using

let y = (0.5-j/(hVerts-1))*geometry.height
.

It's recommended to utilize geometry.computeVertexNormals(); if your material relies on normals and you haven't calculated them manually. Otherwise, default plane normals will be applied.

Keep in mind that the number of vertices exceeds the number of segments by one along each dimension.

Furthermore, note the flipped relationship between y values and j indices when pushing vertices: vertices.push( x, -y, 0 );

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

Utilizing Firebase functions to receive an AJAX post request and logging the data to the console

I am trying to achieve a specific task using AJAX: sending a startdate and enddate from a calendar to a Node.js backend, which is written on a Firebase Cloud Function. Once the button is pressed, I want to post this data and console.log it. Here is my AJA ...

Guide on using Ajax and spring MVC to dynamically fill a modal form

One JSP page displays database results in a table on the browser, allowing users to edit or delete each row. I want to implement a feature where clicking the edit link fetches specific customer data from the database using Spring MVC and Hibernate, display ...

Using window.open in Google Chrome results in multiple tabs being opened instead of just one

I have a dynamic input field with a search button. Initially, only one tab is opened when I click the button. But after saving and clicking it again, multiple tabs open for the same URL. The number of tabs is equal to the number of dynamic input fields cre ...

When attempting to replace a text node with a combination of text and HTML using replaceWith, an error stating "not a function" is triggered

I am dealing with multiple text nodes that need to have some text replaced with HTML: <pre>{ "data": [ { "source": "<a href=www.e.com>e.com</a>", "created_time": "2015-11-13T06:16:09+0000", ...

Shifting v-slot references into a Vue.js component - tips and tricks!

I'm struggling to understand how to transfer the v-slot data into a component. Suppose I want to restructure the code below: <template v-slot:item="data"> <template v-if="typeof data.item !== 'object'"> <v-list-item-co ...

Tips for modifying the text of a label within a node package module

I'm in the process of developing a React web application, and I've incorporated an English node module package called react-timelines. However, I need to translate the label text "Today" into Spanish, which should be "Hoy". When I attempt to modi ...

The length property of a jQuery array may not always match the actual length of the array

Recently delving into jquery, I encountered the issue described in the title. Below is an excerpt from my controller code: [HttpPost] public JsonResult getProjectList() { List<Project> projectList = new List<Project>(); ...

Understanding the relationship between controller and view in AngularJS is crucial for building dynamic

My AngularJS script with MVC architecture is causing some issues. I suspect that there might be errors in the connection between the model, view, and controller layers. JS: var myApp = angular.module("myApp", []); //App.js myApp.controller('MainCon ...

Exploring TypeScript's capabilities: newable objects and enum references

Currently, I am utilizing an external SDK built in JavaScript. One particular module within this SDK, called Blob, is both new-able and contains an enum named FooEnum with the members Bar and Baz. To implement this SDK in JavaScript, the code looks like t ...

Designate the preferred location for requesting the desktop site

Is there a way to specify the location of the 'Request desktop site' option? Here is the code I am currently using: var detector = new MobileDetect(window.navigator.userAgent); if(detector.mobile() != null || detector.phone() != null || det ...

Typescript - Promise resolves prematurely

I have been given a code with three essential parts that cannot be altered: 1. First, there is a call to the getData function, followed by printing the output. getData().then(console.log); 2. The function signature is as follows: async getData(): Promise ...

Faulty lighting using the regular map shader

I've encountered an issue while trying to implement the normal mapping shader THREE.ShaderUtils.lib["normal"]. The normal mapping itself seems to be working fine, but I am facing problems with the lights. Whenever I move the camera or look around, the ...

Encountering a build error with Ubuntu, Node-Gyp, and Canvas – help needed!

Hey there, I'm having some trouble with installing the Canvas package. I've tried Package Versions 6.1.13 and 6.1.3 Here are my system details: Ubuntu 18.04.5, Node 12.18.4 LTS, Python 2.7, g++ installed, pkg-config installed, libjpeg installed ...

Unable to alter the protocol option of the request object in SailsJS

Currently, I am utilizing a library that relies on the req.secure option to proceed without any errors. However, my application is deployed on Heroku and I have implemented custom middleware to check the "x-forwarded-proto" header and set req.secure as tru ...

What is the best way to generate a dynamically interpolated string in JavaScript?

I'm currently developing a reusable UI component and am exploring options to allow the user of this component to provide their own template for a specific section within it. Utilizing TypeScript, I have been experimenting with string interpolation as ...

Unpredictable preset inline styles for HTML input elements

While developing a full-stack MERN application, I encountered an unusual issue when inspecting my React UI in Chrome DevTools. If any of these dependencies are playing a role, below are the ones installed that might be contributing to this problem: Tail ...

"Exploring the process of re-rendering a component with the combination of useEffect and useState

I need help displaying a table in my React component by utilizing the useEffect and useState hooks for rendering the table on the initial load. Here is my component js: import React, { useEffect, useState } from 'react' const Projects = () => ...

The controller method in Laravel is not being triggered by AJAX

In my blade layout file, I have some code that is included in my view multiple times using the @include.layout("blade file link") syntax. When a button is pressed, I want to call a controller function. This works fine without AJAX, but when AJAX is added, ...

How to retrieve the value of a selected radio button in an AngularJS radio button group that uses ng-repeat

In the following code snippet, I am trying to retrieve the value when any of the radio buttons is selected: <label ng-repeat="SurveyType in SurveyTypes"> <input type="radio" name="SurveyTypeName" ng-model="surveyData.SurveyTypeN ...

Using AJAX (jQuery) to call a web method declared in a .cs file that is not tied to any specific aspx or ascx file

After moving a web method from the code-behind file of an ASPX page to another CS file located in the data section (which does not have any associated ASPX page), I encountered an issue with accessing the web method using Ajax. Previously, I accessed the w ...