Skip to content

Instantly share code, notes, and snippets.

@jgphilpott
Last active July 18, 2023 17:48
Show Gist options
  • Save jgphilpott/59ad8432ba8567e91176e669454b9afa to your computer and use it in GitHub Desktop.
Save jgphilpott/59ad8432ba8567e91176e669454b9afa to your computer and use it in GitHub Desktop.
Perform OctreeCSG.js mesh operations on three.js meshes.
# Requirements
# Three JS
# https://github.com/mrdoob/three.js
# OctreeCSG
# https://github.com/giladdarshan/OctreeCSG
morph = (operation, aMesh, bMesh) ->
aMesh.updateMatrix()
bMesh.updateMatrix()
switch operation
when "join"
return OctreeCSG.meshUnion aMesh, bMesh
when "cut"
return OctreeCSG.meshSubtract aMesh, bMesh
when "intersect"
return OctreeCSG.meshIntersect aMesh, bMesh
else
return null
join = (aMesh, bMesh) ->
return morph "join", aMesh, bMesh
cut = (aMesh, bMesh) ->
return morph "cut", aMesh, bMesh
intersect = (aMesh, bMesh) ->
return morph "intersect", aMesh, bMesh
// Requirements
// Three JS
// https://github.com/mrdoob/three.js
// OctreeCSG
// https://github.com/giladdarshan/OctreeCSG
var cut, intersect, join, morph;
morph = function(operation, aMesh, bMesh) {
aMesh.updateMatrix();
bMesh.updateMatrix();
switch (operation) {
case "join":
return OctreeCSG.meshUnion(aMesh, bMesh);
case "cut":
return OctreeCSG.meshSubtract(aMesh, bMesh);
case "intersect":
return OctreeCSG.meshIntersect(aMesh, bMesh);
default:
return null;
}
};
join = function(aMesh, bMesh) {
return morph("join", aMesh, bMesh);
};
cut = function(aMesh, bMesh) {
return morph("cut", aMesh, bMesh);
};
intersect = function(aMesh, bMesh) {
return morph("intersect", aMesh, bMesh);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment