Exporting an indexed geometry with a draw range using GLTFExporter in Three.js: What's the best approach?

I am encountering a specific issue where I need to export an indexed geometry with a draw range. Unfortunately, the GLTFExporter does not support this feature, as indicated by the comment in the code:

// @TODO Indexed buffer geometry with drawRange not supported yet

You can find this information in the GLTFExporter file on line 564 at the following link: https://github.com/mrdoob/three.js/blob/master/examples/js/exporters/GLTFExporter.js

After investigating the commit history, it seems like this functionality has not been updated for 3 months, indicating it may not be addressed anytime soon. I attempted to work around this by removing the index buffer and adjusting the position buffer attribute array based on the draw range, but unfortunately, this approach did not work and caused my geometry to break. Can anyone suggest a workaround or provide guidance on how to proceed with my geometry?

Any help would be greatly appreciated. Thank you.

EDIT:

As a temporary solution, I have opted to "de-index" my geometry for the export process and maintain the draw range, as this workaround is supported by the exporter. While this method involves creating a new geometry with new BufferAttributes, it only applies to the export process and can be done asynchronously. I am hopeful for a more efficient solution in the future.

Answer №1

Concerning the two variables, I plan to incorporate them into the WebGLUtils in an upcoming pull request. It is inefficient for each instance requiring these constants to repeatedly redefine them.

Answer №2

My issue was resolved by eliminating the indexing of my geometry; although not an ideal solution, it served its purpose for this specific export operation. Here is the approach I took:

// original attributes
const vertices  = geometryTmp.getAttribute("position");
const normals  = geometryTmp.getAttribute("normal");
const uv  = geometryTmp.getAttribute("uv");

// new buffer arrays
let verticesTmp = new Float32Array(3 * geometryTmp.index.array.length);
let normalTmp = new Float32Array(3 * geometryTmp.index.array.length);
let uvTmp = new Float32Array(2 * geometryTmp.index.array.length);

let j = 0;
for(let i = 0; i < verticesTmp.length; i += 3) {
    let index = geometryTmp.index.array[j];
    verticesTmp[i] = vertices.getX(index);
    verticesTmp[i+1] = vertices.getY(index);
    verticesTmp[i+2] = vertices.getZ(index);

    normalTmp[i] = normals.getX(index);
    normalTmp[i+1] = normals.getY(index);
    normalTmp[i+2] = normals.getZ(index);
    j++;
}

j = 0;
for(let i = 0; i < uvTmp.length; i += 2) {
    let index = geometryTmp.index.array[j];
    uvTmp[i] = uv.getX(index);
    uvTmp[i+1] = uv.getY(index);
    j++;
}

let newGeomtry = new THREE.BufferGeometry();
newGeomtry.addAttribute( 'position', new THREE.BufferAttribute( verticesTmp, 3 ) );
newGeomtry.addAttribute( 'normal', new THREE.BufferAttribute( normalTmp, 3 ) );
newGeomtry.addAttribute( 'uv', new THREE.BufferAttribute( uvTmp, 2 ) );

newGeomtry.drawRange = geometryTmp.drawRange;
mesh.geometry = newGeomtry;  

// This process was repeated for all the necessary meshes, which were then added to a new THREE.Scene for exporting with truncateDrawRange set to true

Hopefully, this solution proves helpful to others facing a similar challenge.

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

Leveraging React Native's Async Storage to store and retrieve values consistently within the Render method

Is there a way to set and get a value in the render method with just one line of code, by using a variable between tags? I attempted this approach but encountered an error message stating "Can't find variable: storage_key". import React, { Component } ...

Tips for retrieving data using ajax with servlets:

I am trying to send some data on the page to a servlet So I have created the following jQuery code to achieve this I am using all the data to construct a JSON string and send it directly to the servlet However, I am unsure how to retrieve the entire dat ...

The combination of Angular's ngrx and Router.Events within Rxjs does not seem to function as intended

I'm facing a challenging problem that I can't seem to resolve: onSelectCompany() { combineLatest([this.idCompany$, this.idUser$, this.router.events]).subscribe(res => { if(res[2] instanceOf NavigationEnd){ this.router.navigateByUrl(`g ...

Discovering the flaw in my programming that pertains to JSON parsing

After countless hours of searching and reviewing documentation, I am still unable to identify the issue with my jQuery code. My goal is to practice reading a local JSON file and displaying its contents in the body of my HTML document. $(document).ready(fu ...

Error: You can't call .text as a function in jQuery

While trying to retrieve the text from my td, I encountered the following error: $tds[2].text is not a function. The output of console.log('td',$tds[2]) shows: https://i.stack.imgur.com/OUngP.png $(document).ready(function() { $trs = $(&ap ...

Utilize the $setValidity function within ng-repeat to validate input fields

I am facing an issue with my form that is being repeated in an ng-repeat. Below is a snippet of the form. I need to implement custom validation using $setValidity in the controller. However, I am struggling to access input names by index in the controlle ...

Vue: event triggers malfunctioning and components unresponsive

I am new to Vue.js and I'm attempting to trigger an event from my grand-child component (card) to the child component (hand) and then to the parent component (main): card (emit play event) => hand (listen for play event and emit card-play event) ...

What is the method for extracting a variable from a URL using JavaScript?

For instance, consider this URL- website.com/page/?var=20 I am looking to extract the "var" variable from the URL using JavaScript. By the way, my actual URL is- https://bipit2.pranaypro21292.repl.co/d21292auth/?code=pimWoHEuV7fgKEVQMTntRnzXqVla3G&gu ...

The reason why JavaScript condenses two or more spaces into just one space

After encountering a problem with my HTML/JS/Angular script, I created a simple demo to illustrate the issue. Although I have found a solution, I still wanted to seek advice from experts. <body ng-app> <div ng-controller='abc'> ...

Double Marker Challenge in Brochure

I am currently using Leaflet in conjunction with VueJs. I have encountered an issue where a double marker is appearing at a specific location when I add a marker: The code responsible for this behavior is as follows: mounted() { this.map = L.ma ...

Ways to prevent the "RangeError: Maximum call stack size exceeded" error

Currently, I am working on developing a maze generating algorithm known as recursive division. This algorithm is relatively straightforward to comprehend: Step 1 involves dividing the grid/chamber with a vertical line if the height is less than the width, ...

Angular: Assigning a key from one variable to a value in another

I am currently facing a challenge with rendering a form on a page using ng-repeat, where the data for this form is dynamically fetched from a request. Within this data, there is a nested array called "categories" which contains IDs. I want to display the n ...

Exploring the concept of promise.reject() and the art of passing an object as a parameter

By passing response.json in Promise.reject(), I intended for it to be accessible in the catch block. However, it appears as undefined in the catch block. const checkResponse = (response) => { if (response.status >= 200 && response.status & ...

Encountering an error while trying to import JSON in TypeScript

I am in need of using mock JSON data to test the rendering of my front-end. import MOCK_FAQ from '../../mocks/FAQ.json'; However, when attempting to import the file, I encountered this exception: Cannot find module '../../mocks/FAQ.json&a ...

The table appears to be fixed in place and will not scroll, even though the data

Previously, my code was functioning perfectly with the mCustomScrollbar I implemented to scroll both vertically and horizontally on my table. However, while revising my jQuery code for organization purposes, I seem to have unknowingly altered something tha ...

Looking for a three.js resource to enhance my project

Looking for guidance on how to import a .obj 3D model into three.js. Any information or tutorials available? ...

designing a corner tab element

I'm aiming to create a triangular button in the upper-right corner of my website using fixed positioning. It will be an icon on top of a background color with a hover effect. I'm curious if it's possible to achieve this with an angled div or ...

Error: Attempting to access 'config' property of undefined variable

I am currently utilizing Vue 3 with Typescript and primevue. After integrating primevue into my application, I encountered the following errors and warnings. The issue arises when I attempt to utilize the primevue 'Menubar' component, however, wh ...

The seamless merging of Angular2, TypeScript, npm, and gulp for enhanced development efficiency

I'm fairly new to front-end development and I am currently working on an application using Angularjs2 with TypeScript in Visual Studio 2015. I have been following the steps outlined in this Quickstart https://angular.io/docs/ts/latest/cookbook/visual- ...

What sets apart pixi.js WebGL from three.js?

I attempted to convert the code from this CodePen into PixiJS, but unfortunately, I have not had any success so far. This is what I have tried: let video = document.createElement("video"); video.src = videoUrl; video.loop = true; video.muted = true; var v ...