Comments (2)
polygon.vertices.push(v0, v1, v2);
I'm afraid this is invalid code since Polygon
does not have a vertices
property. Besides, it should not be required to explicitly define objects for centroid
and plane
. They exist by default.
If you want to create polygons from triangles, you have to use the Polygon.fromContour() method.
Creates the polygon based on the given array of points in 3D space. The method assumes the contour (the sequence of points) is defined in CCW order.
from yuka.
Thank you for this suggestion @Mugen87 ,
I tried with the following:
const createNavMeshFromGeometry = (geometry) => {
const navMesh = new NavMesh();
const positions = geometry.attributes.position.array;
const indices = geometry.index.array;
const polygons = [];
for (let i = 0; i < indices.length; i += 3) {
const a = indices[i];
const b = indices[i + 1];
const c = indices[i + 2];
const v0 = new THREE.Vector3(positions[a * 3], positions[a * 3 + 1], positions[a * 3 + 2]);
const v1 = new THREE.Vector3(positions[b * 3], positions[b * 3 + 1], positions[b * 3 + 2]);
const v2 = new THREE.Vector3(positions[c * 3], positions[c * 3 + 1], positions[c * 3 + 2]);
const points = [v0, v1, v2];
const polygon = new Polygon().fromContour(points);
polygons.push(polygon);
}
navMesh.fromPolygons(polygons);
return navMesh;
}
but now it's the navMesh.fromPolygons()
that returns the error:
TypeError: tail.squaredDistanceTo is not a function
at HalfEdge.squaredLength (yuka.js?v=e42d8424:9052:19)
at NavMesh.fromPolygons (
so I am a bit clueless how to go from here?
EDIT:
Here is my final function with the help of chatgpt, although I am starting to think this is actually replacing the NavMeshLoader() since it gives me roughly the same result?
export const createNavMeshFromGeometry = (geometry) => {
const navMesh = new NavMesh();
const positions = geometry.attributes.position.array;
const indices = geometry.index.array;
if (!positions || !indices) {
console.error('Invalid geometry: missing positions or indices.');
return;
}
const polygons = [];
for (let i = 0; i < indices.length; i += 3) {
const a = indices[i];
const b = indices[i + 1];
const c = indices[i + 2];
const v0 = new Vector3(positions[a * 3], positions[a * 3 + 1], positions[a * 3 + 2]);
const v1 = new Vector3(positions[b * 3], positions[b * 3 + 1], positions[b * 3 + 2]);
const v2 = new Vector3(positions[c * 3], positions[c * 3 + 1], positions[c * 3 + 2]);
const polygon = new Polygon().fromContour([v0, v1, v2]);
if (!polygon.centroid) {
polygon.centroid = new Vector3();
}
if (!polygon.plane) {
polygon.plane = new THREE.Plane();
}
polygon.computeCentroid();
polygons.push(polygon);
}
navMesh.fromPolygons(polygons);
return navMesh;
};
this screen is the result of my homemade function to transform my buffergeometry:
and here is the one when I use NavMeshLoader and give it a gltf (by using another function to turn my buffergeomtry into a gltf but it felt overkill)
so I'm not sure how to know if that new method is correct or not, since I'm still at the first step of it all :/
and I'm also a bit surprised at the number of polygons (3500+), since my terrain is just 4500 triangles big?
from yuka.
Related Issues (20)
- jsdoc contradiction to code in GameEntity HOT 16
- Steering handling in `Vehicle.update()` ignores `GameEntity.maxTurnRate` HOT 4
- how to judge arriveBehave over HOT 1
- how to set initial mesh HOT 1
- Request: Pathfinding 3D HOT 4
- Yuka and Babylon.js HOT 5
- Building navmesh HOT 2
- Question: Best Practices HOT 2
- Question: NavMesh HOT 8
- Non-terminating while loop HOT 5
- Is there any way to add obstacles dynamically on a 2D grid? HOT 3
- Building with webpack and es6 modules HOT 5
- SteerBehavior - Vehicle facing the wrong direction HOT 3
- How to generate NavMesh automatically? HOT 3
- NavMeshLoader for Typescript throw reference error for fetch HOT 1
- need explanation for this formula HOT 4
- YUKA findPath is not detecting any collisions in Babylon.js HOT 3
- Pursuit Behavor duplicate gltf model HOT 3
- How to make it work with physics (rapier) and gravity? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yuka.