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

Texture not showing when exporting scene #186

Closed
Kalabedo opened this issue Dec 19, 2023 · 4 comments
Closed

Texture not showing when exporting scene #186

Kalabedo opened this issue Dec 19, 2023 · 4 comments
Labels
question Further information is requested

Comments

@Kalabedo
Copy link

I used this library to cut stuff from simple geometries when i want to export the newly built geometries the material on it is not correct. In the renderer everything looks fine. As soon as i export the scene via GLTFExporter the mesh has two seperate textures on top of each other. Resulting in this (opened in Blender):

image

In the renderer it looks like this:
Subtraction

This is the code i'm using (i played with useGroups / consolidateMaterials without sucess):

// Object1
const geometry = new THREE.BoxGeometry(1, 1, 1)
const material = new THREE.MeshStandardMaterial({ 
  map: texture, 
})

// Object2
const geometry2 = new THREE.BoxGeometry(.1, 1, .1)
const material2 = new THREE.MeshStandardMaterial({ 
  color: "#232323"
})

// CSG
const brush1 = new Brush( geometry );
brush1.material = material
brush1.updateMatrixWorld();

const brush2 = new Brush( geometry2 );
brush2.material = material2
brush2.position.z = 0.45;
brush2.updateMatrixWorld();

const evaluator = new Evaluator();
evaluator.useGroups = true
evaluator.consolidateMaterials = true
const result = evaluator.evaluate( brush1, brush2, SUBTRACTION );
scene.add(result)
@gkjohnson gkjohnson added the question Further information is requested label Dec 20, 2023
@gkjohnson
Copy link
Owner

From the docs:

CSG results use Geometry.drawRange to help maintain performance which can cause three.js exporters to fail to export the geometry correctly. It is necessary to convert the geometry to remove the use of draw range before exporting with three.js exporters.

@gkjohnson
Copy link
Owner

Either way this is an issue related to an exporter if three.js is not exporting geometry as it's rendered in the application and should be reported elsewhere. At least a warning should be logged.

@Kalabedo
Copy link
Author

Either way this is an issue related to an exporter if three.js is not exporting geometry as it's rendered in the application and should be reported elsewhere. At least a warning should be logged.

I tried with other CSG libraries and the exporting works fine so i thought the implementation in this library does something different with the materials

@Kalabedo
Copy link
Author

Here is a fix:

// CSG
const brush1 = new Brush( geometry );
brush1.material = material
brush1.updateMatrixWorld();

const brush2 = new Brush( geometry2 );
brush2.material = material2
brush2.position.z = 0.45;
brush2.updateMatrixWorld();

const evaluator = new Evaluator();
evaluator.useGroups = true
evaluator.consolidateMaterials = true
const result = evaluator.evaluate( brush1, brush2, SUBTRACTION );

let index = [];
for (let i = 0; i < result.geometry.attributes.position.count; i++)
  index.push(i);
result.geometry.setIndex(index);

scene.add(result)

With the help of thrax, we found out, that the geometry is not indexed after the subtraction. setting an index fixed the issue with exporting. So you were right i think, it is an Exporter issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants