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

Missing UV mapping on the geometry #127

Closed
maelp opened this issue Dec 24, 2023 · 4 comments
Closed

Missing UV mapping on the geometry #127

maelp opened this issue Dec 24, 2023 · 4 comments

Comments

@maelp
Copy link

maelp commented Dec 24, 2023

When I do this

const geometries = syncGeometries([replicadMesh], []);
const geometry = geometries[0].faces;

and use the geometry: BufferGeometry, it seems to miss the uv field in geometry.attributes

Do you know if there's an easy way to obtain those?

@maelp
Copy link
Author

maelp commented Dec 24, 2023

Okay I fixed it using this

const updateUVMap = (geometry: THREE.BufferGeometry) => {
geometry.computeBoundingBox();
const max = geometry.boundingBox.max;
const min = geometry.boundingBox.min;
const offset = new THREE.Vector2(0 - min.x, 0 - min.y);
const range = new THREE.Vector2(max.x - min.x, max.y - min.y);
const positions = geometry.attributes.position.array;
const uvs: number[] = [];

for (let i = 0; i < positions.length; i += 3) {
    const x = positions[i];
    const y = positions[i + 1];
    uvs.push((x + offset.x) / range.x, (y + offset.y) / range.y);
}

  geometry.setAttribute('uv', new THREE.BufferAttribute(new Float32Array(uvs), 2));
geometry.uvsNeedUpdate = true;
};

@sgenoud
Copy link
Owner

sgenoud commented Jan 3, 2024

I am not 100% sure I understand how UV and replicad should interact (because I don't really understand them). Is there something you think you be done to improve the situation?

@maelp
Copy link
Author

maelp commented Jan 3, 2024

Not exactly sure how it should work, but the snippet above fixed my issue

@sgenoud
Copy link
Owner

sgenoud commented Jan 3, 2024

It looks like this issue is related: #62 (in case you feel like digging deeper).

@maelp maelp closed this as completed Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants