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

New TriangleSplitter #194

Draft
wants to merge 75 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
dcc63b4
Add triangle graph splitter class
gkjohnson Oct 18, 2023
6c22443
Add classes
gkjohnson Oct 20, 2023
d1dda43
Merge branch 'main' into improved-tri-split
gkjohnson Jan 3, 2024
c9a6980
Updates
gkjohnson Jan 3, 2024
372466d
Fixed references
gkjohnson Jan 3, 2024
845c0e6
More utils
gkjohnson Jan 3, 2024
784bcd6
add fields
gkjohnson Jan 3, 2024
3639b60
Use the graph
gkjohnson Jan 3, 2024
6e0da7a
Fixes
gkjohnson Jan 3, 2024
16ccb1e
Fixes
gkjohnson Jan 3, 2024
c5b5a06
Add debug helper
gkjohnson Jan 3, 2024
07eacfd
rename
gkjohnson Jan 3, 2024
aad00b0
Classes
gkjohnson Jan 3, 2024
22c22bd
Get splitting working in one case
gkjohnson Jan 3, 2024
f76f68e
Add more triangle generation
gkjohnson Jan 4, 2024
889ef74
Add a swap edge
gkjohnson Jan 4, 2024
5306109
Add edge swap
gkjohnson Jan 4, 2024
74e501d
Confirm transformation
gkjohnson Jan 4, 2024
6ddbdc3
Small fixes
gkjohnson Jan 4, 2024
540b320
Add function for validating triangle state, fix added edges
gkjohnson Jan 4, 2024
663b023
bug fix
gkjohnson Jan 4, 2024
9ded1a1
Fix validation
gkjohnson Jan 4, 2024
b01457f
Fix edge swap
gkjohnson Jan 4, 2024
55ec2cf
Fix incorrect point
gkjohnson Jan 4, 2024
326aa06
Rename, update api
gkjohnson Jan 4, 2024
6a5e9e8
Fix coplanar points
gkjohnson Jan 4, 2024
013ee9f
Simplify edge swap
gkjohnson Jan 4, 2024
ab2c5fe
Fix API
gkjohnson Jan 4, 2024
3cc27e7
Rename old splitter
gkjohnson Jan 4, 2024
bc17df0
Add legacy splitter option
gkjohnson Jan 4, 2024
be9b240
Remove unused import
gkjohnson Jan 4, 2024
f99336a
comments
gkjohnson Jan 4, 2024
4e054cb
Comments
gkjohnson Jan 4, 2024
3f740ae
Update test
gkjohnson Jan 4, 2024
a3abea8
Fix simple example vertex colors without groups
gkjohnson Jan 4, 2024
a110137
Add pools
gkjohnson Jan 4, 2024
6eaef3e
Add global fields
gkjohnson Jan 4, 2024
8ec4a66
Updates
gkjohnson Jan 4, 2024
1b9fa19
Member name updates
gkjohnson Jan 4, 2024
23e40eb
Update initialize function
gkjohnson Jan 4, 2024
cd34e17
Use the pools
gkjohnson Jan 4, 2024
73278b3
small improvements
gkjohnson Jan 4, 2024
d50ab07
notes
gkjohnson Jan 4, 2024
5146263
Function rename
gkjohnson Jan 5, 2024
15c7ae5
Support parallel lines in the triangle / edge function
gkjohnson Jan 5, 2024
c12c26a
Update triangle line interscetion
gkjohnson Jan 5, 2024
13e0f20
debug example changes
gkjohnson Jan 5, 2024
421ce89
Ensure caches are reset
gkjohnson Jan 5, 2024
a3a5404
Fix edge cases
gkjohnson Jan 5, 2024
89f7fa1
Updates
gkjohnson Jan 5, 2024
a194eae
Dispose the cache data
gkjohnson Jan 5, 2024
893f493
Fix some todos
gkjohnson Jan 5, 2024
235b7b4
Fixes
gkjohnson Jan 5, 2024
e074adc
Update index
gkjohnson Jan 5, 2024
c8607cc
Lint fixes
gkjohnson Jan 5, 2024
ffd7e40
Reuse arrays
gkjohnson Jan 5, 2024
b9f7709
README and dts update
gkjohnson Jan 5, 2024
1abcd17
IMPL updates
gkjohnson Jan 5, 2024
8bba87b
Fix field name
gkjohnson Jan 5, 2024
5a99cfd
update three.js
gkjohnson Jan 5, 2024
374e7d4
Improve parallel line condition
gkjohnson Jan 5, 2024
a061997
Clean up logs
gkjohnson Jan 5, 2024
00b145e
Fix swap iterations
gkjohnson Jan 5, 2024
5a03e39
some improvements
gkjohnson Jan 5, 2024
59c54c0
Remove need for 2d transformations
gkjohnson Jan 5, 2024
5e09b97
comment
gkjohnson Jan 5, 2024
444f53d
Fix splitter
gkjohnson Jan 5, 2024
82713cb
Revert "Remove need for 2d transformations"
gkjohnson Jan 5, 2024
354ae1e
improvements
gkjohnson Jan 5, 2024
d10f2b4
Improvements
gkjohnson Jan 6, 2024
6bf56c0
Improvements
gkjohnson Jan 6, 2024
c67e7fa
Remove need for basis
gkjohnson Jan 6, 2024
9d42cd1
Remove unused fields
gkjohnson Jan 6, 2024
999ee18
Updates
gkjohnson Jan 6, 2024
8d28a2e
Add legacy splitter toggle to example
gkjohnson Jan 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions examples/triangleGraphSplit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html>
<head>
<title>three-bvh-csg - test</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

<style type="text/css">
html, body {
padding: 0;
margin: 0;
overflow: hidden;
font-family: monospace;
}

canvas {
width: 100%;
height: 100%;
}

#output {
color: #956b00;
position: absolute;
left: 10px;
bottom: 10px;
white-space: pre;
}

#loading-container {
position: fixed;
bottom: 0;
width: 100%;
visibility: hidden;
}

#loading-container .text {
color: #956b00;
text-align: center;
}

#loading-container .bar {
height: 5px;
background: #956b00;
width: 50%;
}

</style>
</head>
<body>
<div id="output"></div>
<script type="module" src="./triangleGraphSplit.js"></script>
</body>
</html>
136 changes: 136 additions & 0 deletions examples/triangleGraphSplit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import * as THREE from 'three';
import { TransformControls } from 'three/examples/jsm/controls/TransformControls.js';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
import { EdgesHelper, PointsHelper, TriangleSetHelper } from '../src/index.js';
import { TriangleGraph } from '../src/core/splitter/TriangleGraph.js';

let renderer, camera, scene;
let controls, transformControls;
let planeObject, planeHelper;
let splitter, clippedTris, initialTris, pointsHelper, edgesHelper;
let plane = new THREE.Plane();
let _vec = new THREE.Vector3();

const ogTris = [
new THREE.Triangle(
new THREE.Vector3( - 0.25, 1.25, 0.25 ),
new THREE.Vector3( - 0.25, 0.25, 0.25 ),
new THREE.Vector3( - 1.25, 1.25, 0.25 ),
)
];

const tris = [
// new THREE.Triangle(
// new THREE.Vector3( - 0.5, 0.5, - 0.5 ),
// new THREE.Vector3( - 0.5, - 0.5, - 0.5 ),
// new THREE.Vector3( - 0.5, 0.5, 0.5 ),
// ),
new THREE.Triangle(
new THREE.Vector3( - 0.5, 0.5, - 0.5 ),
new THREE.Vector3( - 0.5, 0.5, 0.5 ),
new THREE.Vector3( 0.5, 0.5, - 0.5 ),
),
// new THREE.Triangle(
// new THREE.Vector3( -0.5, 0.5, 0.5 ),
// new THREE.Vector3( 0.5, 0.5, 0.5 ),
// new THREE.Vector3( 0.5, 0.5, -0.5 ),
// ),
];

init();
render();

function init() {

const bgColor = 0x111111;

// renderer setup
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( bgColor, 1 );
document.body.appendChild( renderer.domElement );

// scene setup
scene = new THREE.Scene();
scene.fog = new THREE.Fog( 0xffca28, 20, 60 );

const light = new THREE.DirectionalLight( 0xffffff, 3.5 );
light.position.set( - 1, 2, 3 );
scene.add( light );
scene.add( new THREE.AmbientLight( 0xb0bec5, 0.35 ) );

// camera setup
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 50 );
camera.position.set( 1, 2, 4 );
camera.far = 100;
camera.updateProjectionMatrix();

controls = new OrbitControls( camera, renderer.domElement );

transformControls = new TransformControls( camera, renderer.domElement );
transformControls.addEventListener( 'dragging-changed', e => {

controls.enabled = ! e.value;

} );
scene.add( transformControls );

planeObject = new THREE.Object3D();
transformControls.attach( planeObject );
scene.add( planeObject );
planeObject.position.z = 0.5;
planeObject.rotation.y = Math.PI / 2;

planeHelper = new THREE.PlaneHelper( plane );
scene.add( planeHelper );

initialTris = new TriangleSetHelper();
clippedTris = new TriangleSetHelper();
pointsHelper = new PointsHelper();
edgesHelper = new EdgesHelper();

splitter = new TriangleGraph();

scene.add( initialTris, clippedTris, pointsHelper, edgesHelper );

window.addEventListener( 'resize', function () {

camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();

renderer.setSize( window.innerWidth, window.innerHeight );

}, false );

}

function render() {

requestAnimationFrame( render );

_vec.set( 0, 0, 1 ).transformDirection( planeObject.matrixWorld );
plane.setFromNormalAndCoplanarPoint( _vec, planeObject.position );

splitter.initialize( ogTris[ 0 ] );
tris.forEach( t => {

splitter.splitByTriangle( t );

} );

planeHelper.visible = false;
transformControls.visible = false;
transformControls.enabled = false;

pointsHelper.setPoints( splitter.graph.points );
edgesHelper.setEdges( splitter.graph.edges );

clippedTris.setTriangles( ogTris );
initialTris.setTriangles( tris );
// clippedTris.setTriangles( splitter.triangles );
// initialTris.setTriangles( [ ...ogTris, ...tris ] );

renderer.render( scene, camera );

}
Loading
Loading