Last active
July 18, 2023 17:48
-
-
Save jgphilpott/59ad8432ba8567e91176e669454b9afa to your computer and use it in GitHub Desktop.
Perform OctreeCSG.js mesh operations on three.js meshes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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