You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm encountering a puzzling issue while attempting to perform CSG operations on text geometries using the three-bvh-csg library. The library is designed for constructive solid geometry (CSG) in Three.js.
import*asTHREEfrom'three';import{TextGeometry}from'three/addons/geometries/TextGeometry.js';import{FontLoader}from'three/addons/loaders/FontLoader.js';import{OrbitControls}from'three/addons/controls/OrbitControls';import{Brush,Evaluator,ADDITION}from"three-bvh-csg";constevaluator=newEvaluator();constloader=newFontLoader();letrenderer,camera,scene,textMesh;constmodelViewerWidth=(window.innerWidth/4)*3;constmodelViewerHeight=window.innerHeight;letheight=1;letsize=5;init();asyncfunctioninit(){// create the scene and set a background colorscene=newTHREE.Scene();scene.background=newTHREE.Color("#dadada");camera=newTHREE.PerspectiveCamera(50,modelViewerWidth/modelViewerHeight,1,100);camera.position.set(0,40,20);// set up the renderer and the size of the model viewerrenderer=newTHREE.WebGLRenderer({antialias: true});renderer.setSize(modelViewerWidth,modelViewerHeight);renderer.setPixelRatio(window.devicePixelRatio);renderer.shadowMap.enabled=true;renderer.shadowMap.type=THREE.PCFSoftShadowMap;constcontrols=newOrbitControls(camera,renderer.domElement);// add the renderer to the modelViewer elementdocument.getElementById("modelViewer").appendChild(renderer.domElement);// add the gridHelper to show orientationconstgridHelper=newTHREE.GridHelper(100,100);scene.add(gridHelper);// Initialize with default textupdateTextMesh(document.getElementById("inputText").value);render();}letbrush1,brush2;functionupdateTextMesh(newText){if(textMesh){scene.remove(textMesh);}loader.load('Roboto Black_Regular.json',function(font){constgeometry=newTextGeometry(newText,{font: font,size: size,height: height,curveSegments: 40,});textMesh=newTHREE.Mesh(geometry,newTHREE.MeshBasicMaterial({color: "#01509D"}));// Center the textMeshgeometry.computeBoundingBox();constboundingBox=geometry.boundingBox;constcenterOffset=newTHREE.Vector3();centerOffset.subVectors(boundingBox.max,boundingBox.min);centerOffset.multiplyScalar(-0.5);textMesh.position.add(centerOffset);// Set the y position to place the textMesh on the planetextMesh.position.y=0;textMesh.rotation.x=Math.PI*-0.5;consttextMesh2=textMesh.clone();textMesh2.material=newTHREE.MeshBasicMaterial({color: "#ff0000"});textMesh2.scale.set(0.9,0.9,2);brush1=newBrush(textMesh.geometry,newTHREE.MeshBasicMaterial({color: "#ff0000"}));brush2=newBrush(textMesh2.geometry,newTHREE.MeshBasicMaterial({color: "#ff0000"}));constresult=evaluator.evaluate(brush1,brush2,ADDITION);scene.add(result);});}functionrender(){requestAnimationFrame(render);renderer.render(scene,camera);}// Update text on input changedocument.getElementById("inputText").addEventListener("input",function(event){updateTextMesh(document.getElementById("inputText").value);});// Update height on input changedocument.getElementById("modelHeight").addEventListener("input",()=>{height=document.getElementById("modelHeight").value;updateTextMesh(document.getElementById("inputText").value);});document.getElementById("textSize").addEventListener("input",()=>{size=document.getElementById("textSize").value;updateTextMesh(document.getElementById("inputText").value);})
This is how the letters look after addition
This is how the letters look after subtraction
Additional Notes:
No error messages are displayed in the console.
The issue is specific to text geometries; other geometries seem to behave as expected.
Thanks!
The text was updated successfully, but these errors were encountered:
Probably, there is a problem with a lot of very elongated, so-called "degenerate" triangles. To quickly solve the problem, without waiting for a global change in the library, you can try to reduce the number of segments forming the frontal contour of your "letters", thereby making the ratio of the perimeter to its area more towards the area.
Issues with 3D text loader
I'm encountering a puzzling issue while attempting to perform CSG operations on text geometries using the three-bvh-csg library. The library is designed for constructive solid geometry (CSG) in Three.js.
This is how the letters look after addition
This is how the letters look after subtraction
Additional Notes:
Thanks!
The text was updated successfully, but these errors were encountered: