Determining surface volume: Duplicate vertices found within the position array of the buffer geometry

I am currently working on calculating the surface area of a 3D model imported through the IFC Loader tool. However, before diving into the complex models, I decided to start with simpler shapes like pyramids to better understand the process.

From my understanding, indexed BufferGeometries consist of a position array containing all the points used in creating the model, and an indexes array that pairs up the points to form triangles. While experimenting with the code below to generate a ply file for a pyramid, I noticed some inconsistencies in the output. There were repeated points and faces that didn't align correctly, resulting in more faces than necessary for a triangular pyramid.

What could be causing these discrepancies? Am I overlooking something crucial in the calculation?

Even though these errors might not impact the overall surface area calculation due to the cross product resulting in zero, I am curious to understand the root cause of these anomalies and why they only occur sporadically.

const geometry = new THREE.ConeGeometry(5, 10, 3);
const material = new THREE.MeshBasicMaterial({ color: 0xffff00 });
const cone = new THREE.Mesh(geometry, material);

const positionsArray = geometry.getAttribute("position").array;
const positions = []
for (var i = 0; i < positionsArray.length; i += 3) {
    positions.push([
        positionsArray[i + 0],
        positionsArray[i + 1],
        positionsArray[i + 2]
    ]);
}
var surface = 0
const faces = geometry.getIndex().array;
var data =
    `ply
format ascii 1.0
element vertex ${positions.length}
property float x
property float y
property float z
element face ${faces.length / 3}
property list uchar int vertex_index
end_header
`
for (const position of positions) {
    data += position.join(" ") + "\n"
}

for (var i = 0; i < faces.length; i += 3) {
    const p1 = positions[faces[i + 0]]
    const p2 = positions[faces[i + 1]]
    const p3 = positions[faces[i + 2]]
    data += `3 ${faces[i + 0]} ${faces[i + 1]} ${faces[i + 2]}\n`
    const p1p2 = p2.map(function (item, index) { return item - p1[index] })
    const p1p3 = p3.map(function (item, index) { return item - p1[index] })
    surface += Math.sqrt(Math.pow(p1p2[1] * p1p3[2] - p1p2[2] * p1p3[1], 2) + Math.pow(p1p2[2] * p1p3[0] - p1p2[0] * p1p3[2], 2) + Math.pow(p1p2[0] * p1p3[1] - p1p2[1] * p1p3[0], 2)) / 2
}

const link = document.createElement('a');
var blob = new Blob([data], { type: "text/plain" });
link.href = URL.createObjectURL(blob);
link.download = 'example.ply';
link.click();
ply
format ascii 1.0
element vertex 15
property float x
property float y
property float z
element face 9
property list uchar int vertex_index
end_header
0 5 0
0 5 0
0 5 0
0 5 0
0 -5 5
4.330127239227295 -5 -2.5
-4.330127239227295 -5 -2.5
-1.2246467996456087e-15 -5 5
0 -5 0
0 -5 0
0 -5 0
0 -5 5
4.330127239227295 -5 -2.5
-4.330127239227295 -5 -2.5
-1.2246467996456087e-15 -5 5
3 0 4 1
3 4 5 1
3 1 5 2
3 5 6 2
3 2 6 3
3 6 7 3
3 12 11 8
3 13 12 9
3 14 13 10

Answer №1

According to the information found in the provided source code, it seems that a ConeGeometry is essentially created by starting with a CylinderGeometry and setting the radius to 0 at one end. This explains why there are multiple points visible in the geometry, as they form a triangle fan at the end where all the vertices are compressed into a single location.

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

Conceal a certain element in development using CSS

Is there a way to hide the footer section from my webpage without affecting the rest of the content? For example, using something like: "div class="poweredby" display: none", but I'm unsure of the correct method... Here is the spe ...

What are the alternatives to invoking a server-side C# method from JavaScript without using a WebMethod or UpdatePanel?

I am looking for alternatives to using an update panel. The common WebMethod approach is causing errors with the code below: private string currentHtml() { StringWriter str_wrt = new StringWriter(); HtmlTextWriter html_wrt = new Htm ...

Utilize the parsing functionality in three.js to extract JSON geometry data

After exporting a model from Blender using the three.js exporter and successfully loading it with the JSONLoader, my next challenge is to store the JSON information in a variable and parse it to display the model without having to load an external file. T ...

What are the steps to incorporating the angular/material version 7.0.1 component into my project?

My journey with Angular and Google Material Design has been successful so far. I have been building my front-end app using the official documentation from https://angular.io/tutorial and https://material.angular.io/guides. While browsing through a similar ...

Alternate. (individually)

Issue with Running Program I've been struggling to get my program to run correctly. The task at hand is to have the program display only one question at a time. But no matter what I try, clicking on all questions displays all the answers simultaneous ...

An issue arose when attempting to load the page using jQuery

Currently, I am implementing the slidedeck jquery plugin on my webpage to display slides. While everything is functioning properly, I am facing an issue with the CSS loading process. After these slides, I have an import statement for another page that retr ...

False return - Inoperative link - Scroll option

I have a JavaScript drop-down menu that is functioning correctly, but when I click on one of the links in the dropdown, the link does not work. I suspect it has something to do with my "return false/true" setup. Here's my JavaScript code: function d ...

The Jquery click event refuses to trigger

Below is the JavaScript code that is not functioning: $('#change-priority-modal').find('.btn-primary').unbind().on("click", function () { //my_func_body } Interestingly, the code works perfectly fine in the developer console. I would ...

Interacting with a C# Web Service Using JQuery

I've set up a JSON web service in C# and I'm working on creating a custom HTML page to interact with it. http://localhost:25524/DBService.svc/json/db=TestDB/query=none When I input this URL into my browser, I expect to receive JSON formatted da ...

Creating a Loop for Tabs on an HTML Form

When navigating through form input boxes using the tab key, it usually goes in order. However, I discovered that you can actually customize this order by using tabindex=x. Since I have 5 inputs on my form, I use tabindex 5 times to specify the order. But ...

What is the best way to create a responsive div containing multiple images?

I am working on a slider and my approach is to create a div and insert 4 images inside it. The images will be stacked one above the other using position: absolute, with a width of 1013px, max-width of 100%, and height set to auto for responsiveness. The is ...

Delivering an XML file generated by PHP to a JavaScript parser

I'm in the process of creating a smart TV app that streams live content. The app functions properly when I provide it with a valid XML playlist. However, when I attempt to use PHP to generate the XML file (which generates without any issues), it fail ...

Is there a method to maintain highlighted text on a webpage even after a user has selected it and clicked elsewhere on the page?

Consider this scenario: a user uses their mouse to select the first line of a paragraph, and then later goes on to select another line lower down on the page. How can we ensure that both the previously selected text and the new selection remain highlighted ...

Smoothly scroll through parallax backgrounds

I've implemented a feature where an element moves in relation to scrolling using jQuery: $('#object').css('transform','translateY('+($(window).scrollTop()*.4)+'px)'); Here's the CSS: #object { width: ...

Fetching images stored on an external website and loading them into an iframe within an Electron application

I am contemplating turning my website into a desktop application using either an iframe or webview within an Electron app. My website contains numerous images that I wish to cache in the Electron app to prevent repeated downloads. Is it possible to access ...

Using async/await with Middleware in Express

I'm struggling to grasp the concept of writing middleware in Express that uses async/await without leaving a floating Promise after execution. Despite reading numerous blogs and StackOverflow posts, it appears that there is a common pattern for utiliz ...

Close the parent electron window while keeping the child window open

I am currently working on a project where I need to create an electron app that displays a splash screen initially and then opens a new window before closing the splash screen. However, despite my efforts, I am facing challenges in achieving this functio ...

The Bulma calendar date input fails to display the pre-filled start date

I am facing a challenge while trying to integrate the Bulma calendar into my project, particularly when it comes to setting a default start date. According to the documentation, I am using the following method: <input type="date" data-start-date="10/2 ...

Is the JSON data missing from the POST request?

I'm having trouble inserting data into the database using a POST request. Here is how I'm making the request: 127.0.0.1:3000/api/users?fname=asd&lname=edc&<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1d7870 ...

What methods are available to trigger an AutoHotkey script using JavaScript?

I'm in the process of creating a Chrome extension designed to streamline tasks. I've come to a stage where I require my extension to execute certain AutoHotkey scripts. Is there a method to execute an AutoHotkey script using JavaScript? (I' ...