Rendering faces with a different texture using BufferGeometry in Three.js

Here is my output date:

geom[0] = {

texturesindexT: new Int16Array([0,1,2,3]),
texturesindexS: new Int16Array([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,...]),

materialsindexT: new Int16Array([-1,-1,-1,-1]),
materialsindexS: new Int16Array([-1,0,1,2,3,4,5,0,6,2,7,8,-1,0,...]),

startIndicesT: new Uint32Array([0,288,606,897,1380]),
startIndicesS: new Uint32Array([1380,1431,1479,1485,1497,1515,1659,...]),

m_indices: new Uint16Array([0,1,2,3,0,2,4,2,5,4,6,2,7,3,2,8,9,10,...]),

m_vertices: new Float32Array([-81.93996,25.7185,-85.53822,-81.93996,...]),

m_normals: new Float32Array([-0.004215205,0.9999894,-0.001817489,-0.004215205,...]),

m_texCoords: new Float32Array([0,0.04391319,0,0.2671326,0.009521127,0.03514284,...]),

}

var textures = new Array("-1_-1/t0.jpg","-1_-1/t1.jpg","-1_-1/t2.jpg",...);

The data is structured for Index, Vertex, and Normal buffers, but specific sections need to be rendered with different textures and materials.

Attempts to create a THREE.Geometry from the indices, vertices, and texCoords/UVCoords have been unsuccessful.

Now experimenting with using a THREE.BufferGeometry, where I need to render specific sections with different textures based on indices.

Initially tried creating separate BufferGeometries for each section, but faced challenges due to the order of indices for the entire model requiring complete data for just a few faces.

Seeking advice on how to render sections of a BufferGeometry with different textures, or if it's possible to assign texture indices to individual faces.

Alternatively, exploring the idea of creating a material that can render designated faces with different textures.

Answer №1

To incorporate two distinct textures into a single BufferGeometry, you can follow this approach that involves defining drawcalls:

var geometry1 = new THREE.BufferGeometry();
// ...add the necessary data...
var geometry2 = geometry1.clone();

// define drawcalls
geometry1.offsets = geometry1.drawcalls = []; // currently necessary
geometry1.addDrawCall( start1, count1, 0 );

geometry2.offsets = geometry2.drawcalls = []; // currently necessary
geometry2.addDrawCall( start2, count2, 0 );

var material1 = new THREE.MeshPhongMaterial( { map: map1 } );
var material2 = new THREE.MeshPhongMaterial( { map: map2 } );

var mesh1 = new THREE.Mesh( geometry1, material1 );
var mesh2 = new THREE.Mesh( geometry2, material2 );

Using three.js version r.70

Answer №2

By utilizing the concept of shared vertex buffers and separate indexes, you have the ability to craft two distinct geometries:

let position = new THREE.BufferAttribute(positionArray, 3);
let normal = new THREE.BufferAttribute(normalArray, 3);
let uv = new THREE.BufferAttribute(uvArray, 2);

let indices1 = new THREE.BufferAttribute(indexArray1, 1);
let geometry1 = new THREE.BufferGeometry();
geometry1.addAttribute('position', position);
geometry1.addAttribute('normal', normal);
geometry1.addAttribute('uv', uv);
geometry1.addAttribute('index', indices1);

let indices2 = new THREE.BufferAttribute(indexArray2, 1);
let geometry2 = new THREE.BufferGeometry();
geometry2.addAttribute('position', position);
geometry2.addAttribute('normal', normal);
geometry2.addAttribute('uv', uv);
geometry2.addAttribute('index', indices2);

Subsequently, you can proceed to generate two meshes with distinct materials in the usual manner. It's my understanding that this approach allows for the efficient sharing of common data between both meshes.

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 the default values in a Pebble AppSync Tuple

After making a few adjustments to the Pebble weather example program, I encountered an issue. I included some app_log calls for debugging purposes, and I decided to utilize a configuration screen instead of an app to transmit data. However, the app_log cal ...

I am facing difficulties in installing node packages using npm install

Trying to install node packages using npm, but encountering an issue. When I run the command, the output is: up to date, audited 356 packages in 7s found 0 vulnerabilities I have listed the dependencies in my package.json file like so: "dependencies& ...

Setting up Scss and purgeCss configuration in Next.js custom postCSS configuration: A step-by-step guide

My current project is using Scss in combination with Bootstrap for design. I have implemented purgeCss to remove unused Css, and customized my postcss.config.js file as follows: module.exports = { plugins: [ "postcss-flexbugs-fixes", [ " ...

Find distinct elements in an array of objects

Imagine you have an array filled with different objects: var itemsArray = [ {name: "apple", color: "red", weight: "100g"}, {name: "banana", color: "yellow", weight: "120g"}, {name: "apple", color: "red", weight: "100g"}, {name: "banana", color: "y ...

Use promises instead of directly calling res.json(data) when working with Node.js

When I make a post request to the payment_url, it triggers the second block of my function. Unfortunately, I am unable to retrieve any data in the then method because I am unsure how to pass the data back to the resolve function. Client-side call paypal. ...

Tips for extracting data from various select drop-down menus within a single webpage

As a newcomer to JQuery, I apologize if this question seems basic. I have a page with 20 categories, each offering a selection of products in a drop-down menu. The user will choose a product from each category, triggering an ajax call to retrieve the pric ...

Is there a way to utilize redux to trigger the opening of my modal when a button is clicked?

I'm facing a challenge with opening my modal using redux when clicking <CheckoutButton/>. Despite my efforts, the modal keeps appearing every time I reload the browser. I've reviewed my code but can't pinpoint the issue. What am I doin ...

When attempting to retrieve data from an API in Angular 8, I encountered difficulties in dynamically creating a formArray within a formArray

I am struggling to dynamically create form controls based on the data received, specifically for fields like task and template name. Your assistance is greatly appreciated. { "items": [ { "templatename": "Defult" ...

Interested in learning how to filter nested tables?

After successfully integrating a filter code snippet, I encountered an issue with the filter not recognizing data tables that can only be inserted as nested tables. Due to my limited knowledge of JavaScript/CSS, I'm unsure if this problem can be resol ...

Error message received while converting webm video to images using Kagami/ffmpeg.js: Unable to locate an appropriate output format for '%04d.jpg'

These are the current versions: node v12.9.1, npm 6.10.2, [email protected] Repository: https://github.com/Kagami/ffmpeg.js The code in decode.js looks like this: const fs = require('fs'); const ffmpeg = require('ffmpeg.js'); c ...

Navigate to the date selector and select the following month

https://i.sstatic.net/AdWVs.png <button class="mat-calendar-next-button mat-icon-button" mat-icon-button="" type="button" ng-reflect-disabled="false" aria-label="Next month"><span class="mat-button-wrapper"></span><di ...

After executing webpack, it has been noticed that one of the dist files consistently ends up empty

As someone who is new to webpack, I have successfully used the quick start guide to process a simple JS file from src to dist. Everything was working fine. However, I encountered an issue when trying to process more than one JS file. The original tutorial ...

How to allow scrolling in the background while a Material UI Dialog is displayed in React

Currently, I have a component that can toggle a Material UI Dialog open and closed. Right now, the page displays some text followed by a button that opens the dialog. To see where I'm at with this, I've set up a code sandbox: https://codesandbox. ...

What is the most efficient method for implementing absolute imports in Webpack 2?

I'm currently working on configuring Webpack for a React project and I'm looking to streamline how I import my components. Ideally, I want to import components like this: import ComponentName from "components/ComponentName" Instead of the more ...

The TypeScript inference feature is not functioning correctly

Consider the following definitions- I am confused why TypeScript fails to infer the types correctly. If you have a solution, please share! Important Notes: * Ensure that the "Strict Null Check" option is enabled. * The code includes c ...

Toggle the visibility of a particular Model3DGroup in 3D XAML

After creating a detailed XAML file from 3DS, I now have a complex 3D model of an industrial robot with multiple Model3DGroups, each having its unique transform. The challenge I am facing is how to make two specific pieces of the robot appear as Visible ...

Insert a new store into an existing IndexedDB database that is already open

After opening and passing the onupgradeneeded event in IndexedDB, is there a way to create a new store? My attempted code: var store = db.createObjectStore('blah', {keyPath: "id", autoIncrement:true}); This resulted in the following error mess ...

Save Scope in JSON format

Currently, I am developing a web application that dynamically displays specific prompts based on the field in focus. There are several different texts stored as scripts that I want to showcase at these different points. My goal is to incorporate scope dat ...

Toggle the element within the selected row using Jquery

In order to create a client list, users must click on rows to select them and then submit the selections to the database for a cron job to send out emails. Instead of using checkboxes, I am attempting to highlight rows by including two hidden elements - o ...

Is there a way to retrieve a numerical value from within two specific elements when web scraping?

I am new to web scraping and looking to extract the numbers located between the strong tags. Currently, I am using Python 3.8 along with BeautifulSoup for this task. <li class="price-current"> <span class="price-current-label"> </s ...