MCPcopy Create free account
hub / github.com/TheOrcDev/github-creature / ExternalForce

Class ExternalForce

components/liquid-ether.tsx:689–741  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

687 }
688
689 class ExternalForce extends ShaderPass {
690 mouse!: THREE.Mesh;
691 constructor(simProps: any) {
692 super({ output: simProps.dst });
693 this.init(simProps);
694 }
695 init(simProps: any) {
696 super.init();
697 const mouseG = new THREE.PlaneGeometry(1, 1);
698 const mouseM = new THREE.RawShaderMaterial({
699 vertexShader: mouse_vert,
700 fragmentShader: externalForce_frag,
701 blending: THREE.AdditiveBlending,
702 depthWrite: false,
703 uniforms: {
704 px: { value: simProps.cellScale },
705 force: { value: new THREE.Vector2(0, 0) },
706 center: { value: new THREE.Vector2(0, 0) },
707 scale: {
708 value: new THREE.Vector2(
709 simProps.cursor_size,
710 simProps.cursor_size
711 ),
712 },
713 },
714 });
715 this.mouse = new THREE.Mesh(mouseG, mouseM);
716 this.scene!.add(this.mouse);
717 }
718 update(...args: any[]) {
719 const props = args[0] || {};
720 const forceX = (Mouse.diff.x / 2) * (props.mouse_force || 0);
721 const forceY = (Mouse.diff.y / 2) * (props.mouse_force || 0);
722 const cellScale = props.cellScale || { x: 1, y: 1 };
723 const cursorSize = props.cursor_size || 0;
724 const cursorSizeX = cursorSize * cellScale.x;
725 const cursorSizeY = cursorSize * cellScale.y;
726 const centerX = Math.min(
727 Math.max(Mouse.coords.x, -1 + cursorSizeX + cellScale.x * 2),
728 1 - cursorSizeX - cellScale.x * 2
729 );
730 const centerY = Math.min(
731 Math.max(Mouse.coords.y, -1 + cursorSizeY + cellScale.y * 2),
732 1 - cursorSizeY - cellScale.y * 2
733 );
734 const uniforms = (this.mouse.material as THREE.RawShaderMaterial)
735 .uniforms;
736 uniforms.force.value.set(forceX, forceY);
737 uniforms.center.value.set(centerX, centerY);
738 uniforms.scale.value.set(cursorSize, cursorSize);
739 super.update();
740 }
741 }
742
743 class Viscous extends ShaderPass {
744 constructor(simProps: any) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected