in cam animation, add red tinting to cuts below z=0

This commit is contained in:
Stewart Allen 2024-09-05 21:49:02 -04:00
commit 40537de055
4 changed files with 45 additions and 3 deletions

View file

@ -14,6 +14,39 @@ const asPoints = false;
// ---( CLIENT FUNCTIONS )---
// tint points below z=0 with red
function add_red_neg_z(material) {
material.onBeforeCompile = (shader) => {
console.log({ OBC: shader });
shader.vertexShader = shader.vertexShader.replace(
`#include <worldpos_vertex>`,
`
#include <worldpos_vertex>
vWorldPosition = vec3(transformed);
`
);
shader.vertexShader = `
varying vec3 vWorldPosition;
` + shader.vertexShader;
shader.fragmentShader = `
varying vec3 vWorldPosition;
` + shader.fragmentShader;
shader.fragmentShader = shader.fragmentShader.replace(
`#include <dithering_fragment>`,
`
#include <dithering_fragment>
if (vWorldPosition.z < 0.0) {
gl_FragColor.rgb += vec3(0.5, 0.0, 0.0); // Add red tint
}
`
);
};
return material;
}
kiri.load(() => {
if (!kiri.client) {
return;
@ -105,13 +138,15 @@ kiri.load(() => {
transparent = true,
opacity = 0.9,
side = THREE.DoubleSide;
material = new THREE.MeshMatcapMaterial({
// material = new THREE.MeshMatcapMaterial({
material = new THREE.MeshPhongMaterial({
flatShading,
transparent,
opacity,
color,
side
});
add_red_neg_z(material);
kiri.client.send("animate_setup", {settings}, ondone);
},
@ -156,6 +191,7 @@ kiri.load(() => {
geo.computeVertexNormals();
}
mesh = new THREE.Mesh(geo, material);
mesh.renderOrder = -10;
}
space.world.add(mesh);
meshes[id] = mesh;

View file

@ -39,6 +39,10 @@ function parse(text, opt = { soup: true }) {
for (let sub of path.subPaths) {
let length = sub.getLength();
let points = sub.getPoints(sub.curves ? Math.max(length/2, 12) : undefined);
if (points.length < 3) {
console.log({ sub, length, points });
continue;
}
let poly = base.newPolygon().addPoints(points.map(p => base.newPoint(p.x, -p.y, 0)));
if (poly.appearsClosed()) poly.points.pop();
if (type === 'polyline') poly.setOpen(true);

View file

@ -1097,9 +1097,11 @@ const tool = {
if (dup_sel) {
selection.clear();
}
let nm = [];
for (let m of models) {
m.duplicate({ select: dup_sel, shift: dup_shift });
nm.push(m.duplicate({ select: dup_sel, shift: dup_shift }));
}
tool.regroup(nm);
},
mirror() {

View file

@ -80,7 +80,7 @@ let materials = mesh.material = {
color: 0x0,
transparent: true,
opacity: 0.5
})
}),
};
/** 3D model rendered on plaform **/