Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add volume calculator for 3d mesh #27905

Open
isalgadof opened this issue Mar 12, 2024 · 4 comments
Open

Add volume calculator for 3d mesh #27905

isalgadof opened this issue Mar 12, 2024 · 4 comments

Comments

@isalgadof
Copy link

Description

Three has no native method to calculate mesh's volumes.

Solution

Add a method (mesh.volume) to retrieve the calculated volume of the object-mesh.

Alternatives

Pass through a method using an import for 'three-volume' package

Additional context

https://www.npmjs.com/package/three-volume

isalgadof added a commit to isalgadof/three.js that referenced this issue Mar 12, 2024
isalgadof added a commit to isalgadof/three.js that referenced this issue Mar 12, 2024
@statusunknown418
Copy link

what's the state of this PR? bumping for visibility and bc seems like a very useful utility

@Mugen87
Copy link
Collaborator

Mugen87 commented Jun 20, 2024

what's the state of this PR?

This is an issue. The respective PR is #27906.

Unfortunately, the OP has to honor the feedback in #27906 (comment) to get the code merged. As long as the code is not in the three repository, you can still use three-volume.

@statusunknown418
Copy link

@Mugen87 I'm trying to use the lib but getting this error

TypeError: Cannot read properties of undefined (reading 'attributes')
    at calculateVolume (webpack-internal:///(rsc)/./node_modules/.pnpm/three-volume@2.0.5/node_modules/three-volume/index.js:10:29)
    at POST (webpack-internal:///(rsc)/./src/app/api/analyze/route.ts:29:85)

using this

import { NextResponse, type NextRequest } from "next/server";
import { Box3, Vector3 } from "three";
import { ThreeVolume } from "three-volume";
import { STLLoader } from "three/addons";

export const POST = async (req: NextRequest) => {
  const body = (await req.json()) as { url: string };

  if (!body.url) {
    return NextResponse.json({ error: "No url provided" }, { status: 400 });
  }

  const t1 = performance.now();
  const fileFetch = await fetch(body.url);
  const arrayBuffer = await fileFetch.arrayBuffer();

  const stlLoader = new STLLoader();

  const fileV3 = stlLoader.parse(arrayBuffer);
  const box = new Box3().setFromArray(fileV3.getAttribute("position").array);
  const size = new Vector3();
  const computedVolume = ThreeVolume(fileV3);
  const t2 = performance.now();

  return NextResponse.json(
    { help: true, dimensions: box.getSize(size), computedVolume, took: t2 - t1 },
    { status: 200 },
  );
};

does someone has any solution?

@Mugen87
Copy link
Collaborator

Mugen87 commented Jun 22, 2024

Do you mind reporting this issue at https://github.com/isalgadof/Three-volume instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants