What sets BoxBufferGeometry apart from BoxGeometry in Three.js?

I'm currently diving into the world of Three.js and I've hit a roadblock trying to distinguish between BoxBufferGeometry and BoxGeometry. Can anyone shed some light on this for me?

Answer №1

[Primitive]Geometry classes are designed for easy manipulation but use more memory compared to JS geometry classes.

Essentially, each piece of data that defines the geometry is stored as an instance of a specific class (Vector3, Vector2, Face3, etc.). These classes come with handy methods for tasks like vertex dot products, translation, UV modifications, normal adjustments, and more. However, this approach incurs overhead in terms of memory and performance due to creating and storing multiple instances.

[Primitive]BufferGeometry classes, on the other hand, prioritize performance by utilizing typed arrays to store data in a format optimized for WebGL.

This means that instead of vertices being stored as an array of Vector3s, they are maintained as typed arrays:

Array[v0, v1... vN]
vs:
Float32Array[v0x, v0y, v0z, v1x, v1y, v1z... vNx, vNy, vNz]

While these are more efficient in storage, they are not as straightforward to manipulate.

For manipulating a vertex:

Using Geometry

// Accessing and modifying properties directly
myGeom.vertices[5].add(new THREE.Vector3(1, 2, 3))

Using BufferGeometry

// Requires manual indexing and calculation for modification
const stride = 3
const index = 5
let offset = index * stride
myGeom.attributes.position.array[offset++] += 1 
myGeom.attributes.position.array[offset++] += 2 
myGeom.attributes.position.array[offset] += 3

However,

THREE.BufferAttribute offers methods for working with the array, albeit in a more verbose manner:

// Adding values to the 5th vertex
const index = 5
const attribute = myGeometry.attributes.position
const v3add = new THREE.Vector3(1, 2, 3)

attribute.setXYZ( 
  index,
  attribute.getX(index) + v3add.x,
  attribute.getY(index) + v3add.y,
  attribute.getZ(index) + v3add.z
)

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

The plugin "react" encountered a conflict while trying to sync with both the "package.json" and the "BaseConfig" files

Whenever I open Terminal in my react folder and try to start the react app using npm start, I always end up encountering an error on the browser. The error message states that the "react" plugin is conflicting between two paths: "package.json » eslint ...

Setting header details for optimal data transfer

Currently, there is a Java code snippet that I am working on which attempts to access the header information sent by an HTML page. Unfortunately, I do not currently have the specific HTML page in question. However, I still need to be able to access and m ...

Generating a JSON file using JavaScript

Currently, I am attempting to create a JSON file through JavaScript. Since I haven't found the appropriate code yet, I am experimenting with creating a text file instead. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html&g ...

Transition a UIView by gradually fading it in and out as it moves across the screen

Animating the view is a simple task: [UIView animateWithDuration:1.0 animations:^{theView.center = newCenter; theView.alpha = 0;} completion:^(BOOL finished){ [theView removeFromSuperview] ...

The column must have a defined value and cannot be left empty

I encountered an issue while trying to populate a database with seed data. The error message I received is: name: 'SequelizeDatabaseError', parent: Error: Column 'id' cannot be null code: 'ER_BAD_NULL_ERROR', errno: 1048, sql ...

TinyMCE - The control with the name 'content' is considered invalid and cannot receive focus

I am utilizing TinyMCE 4 and here is the code snippet for it: <script type="text/javascript" src="//cdn.tinymce.com/4/tinymce.min.js"></script> <script> tinymce.init({ selector: 'textarea[name=content]', ...

Invoke a codebehind function using jQuery

I am encountering an issue while trying to complete a simple task. I am attempting to pass values to a code behind method, perform some calculations, and then return the result. Initially, I started with a test method but have not been successful in making ...

The NGX countdown timer is experiencing a discrepancy when the 'leftTime' parameter exceeds 24 hours, causing it to not count down accurately

When the leftTime configuration exceeds 864000, the timer does not start from a value greater than 24 hours. <countdown [config]="{leftTime: `864000`}"></countdown> For example: 1. When leftTime is set to `864000`, the Timer counts down from ...

Changing from localhost:3000/admin to localhost:3000 within the local server

I am currently developing a node.js application. My goal is to have the homepage rendered after the admin successfully uploads data, transitioning from localhost:3000/admin to localhost:3000. I attempted to achieve this using the code snippet below: route ...

Having difficulty in sending SMS through smsgateway.me following the recent update

Today, I encountered an issue while trying to send SMS messages programmatically using PHP from localhost. The problem arose after updating to version 4 of smsgateway.me and I am unable to send any messages. I am struggling to figure out how to pass the AP ...

What is the best way to incorporate a new field into an established JSON structure?

I have a JSON data set containing 10,000 unique records and I am looking to add another field with a distinct value to each record. What is the best way to achieve this? [ { _id: "5fffd08e62575323d40fca6f", wardName: "CIC", region: &quo ...

Encountering a browser error when trying to access a C# method via AJAX: Javascript

I'm having trouble connecting to my Webservice. I keep getting an error 404, even though everything seems like it should be working fine. The issue started when I moved the code from my *.cshtml file into a separate .js file. The Javascript file is l ...

What is the significance of utilizing app.set() and app.get() in applications?

Is there a way to simplify this code: app.set('port', (process.env.PORT || 3000)); const server = app.listen(app.get('port'), () => { console.log('Server|Port: ', app.get('port')); }); Here is an alternative ...

"Oops! Vite seems to be facing an issue as RefreshRuntime.injectIntoGlobalHook function is

Our CRA react app has been transitioned from webpack to Vite. Problem: When running the application locally in production mode, I encounter the following error: 1. Uncaught TypeError: RefreshRuntime.injectIntoGlobalHook is not a function at (index):6:16 ...

Tips for retrieving information from a dynamically created form using VUE?

Welcome Community I am working on a parent component that includes a child component. The child component dynamically renders a form with various controls from a JSON object retrieved via a Get request using Axios. My goal is to be able to read and loop ...

Vue component fails to render on a specific route

I am having trouble rendering the Login component on my Login Route. Here is my Login component code: <template> <v-app> <h1>Login Component</h1> </v-app> </template> <script> export default { } </script ...

Every time Lodash.uniqueId is called, it consistently generates the value of

Consider using the lodash library, specifically version 4.17.11. _.uniqueId() seems to consistently output 1 instead of a random three-digit number. Similarly, _.uniqueId('prefix') always returns prefix1. Do you see this as a potential issue? ...

Struggling to determine whether an array contains data or is void in ReactJS?

In the state, I have an array and I set the default value of my state to an empty array []. After loading an API request, I need to display a loader until the data is ready. So, I am using a condition like this: (if the array length === 0, the loader wil ...

Bootstrap-tour is incompatible with a row within a table structure

Is there a way to highlight a table row effectively? I've been struggling with it and tried using the fix mentioned in this bootstrap-tour issue here Check out this demonstration on jsFiddle: jsFiddle JAVASCRIPT $("#dialog").dialog(); var t = new ...

Error: The value of 'id' cannot be assigned to an undefined property

Recently, I've been delving into learning JS Express and decided to create a basic solution to handle GET / DELETE / POST / PUT requests. Everything was running smoothly until I encountered an issue with the POST router. Below is the code snippet for ...