-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53e6761
commit f3ad26d
Showing
13 changed files
with
490 additions
and
261 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ const examples = [ | |
"Magnetic Focus", | ||
"Orbit Animation", | ||
"Axes2D", | ||
"Animation Set", | ||
]; | ||
--- | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
import Example from "../../layouts/Example.astro"; | ||
--- | ||
|
||
<Example title="Animation Set"> | ||
<script> | ||
import * as MRAPH from "../../../src/mraph.js"; | ||
|
||
const layer = new MRAPH.Layer().appendTo(document.body); | ||
|
||
const vf3d = new MRAPH.VectorField3D(); | ||
layer.add(vf3d); | ||
vf3d.colorFunc = (x, y, z, length) => { | ||
const hue = (length - 0.1) * 4 - 1.35; | ||
return MRAPH.MathFunc.lerpArray(new MRAPH.Color(0, 0.9, 1), new MRAPH.Color(1, 0.1, 0.1), hue); | ||
}; | ||
|
||
vf3d.animate.transformTo(new MRAPH.Point(0, 0), { runTime: 1.5 }); | ||
vf3d.animate.transformTo(new MRAPH.VectorField2D(), { runTime: 1.5 }); | ||
vf3d.animate.transformTo(new MRAPH.Axes2D(), { runTime: 1.5 }); | ||
vf3d.animate.rotateZ(Math.PI * 4, { runTime: 3 }); | ||
vf3d.animate.moveTo(MRAPH.VECTORS.UP); | ||
vf3d.animate.moveTo(MRAPH.VECTORS.DOWN, { curve: MRAPH.Timeline.easeOutBounce }); | ||
vf3d.animate.moveTo(MRAPH.VECTORS.ORIGIN); | ||
layer.scene.animate.rotateY(Math.PI / 3); | ||
layer.scene.animate.rotateX(Math.PI / 3); | ||
layer.camera.animate.moveTo(new MRAPH.Vector(0, 0, -5)); | ||
|
||
layer.play(); | ||
</script> | ||
</Example> |
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import Mobject3D from "./Mobject3D.js"; | ||
import Point3D from "./Point3D.js"; | ||
import Cylinder from "../../geometry/Cylinder.js"; | ||
import Matrix from "../../math/Matrix.js"; | ||
import Vector from "../../math/Vector.js"; | ||
import * as VECTORS from "../../constants/vectors.js"; | ||
import * as COLORS from "../../constants/colors.js"; | ||
|
||
export default class Arrow3D extends Mobject3D { | ||
tipWidth = 0.06; | ||
tipLength = 0.12; | ||
strokeWidth = 0.05; | ||
|
||
constructor(start = new Point3D(-1, 0), end = new Point3D(1, 0)) { | ||
super(); | ||
this.start = start; | ||
this.end = Vector.isInstance(end) ? new Point3D(start.center.add(end)) : end; | ||
this.material.colorMode = "single"; | ||
this.setColor(COLORS.SEIYA_PINK); | ||
} | ||
|
||
update() { | ||
const r = this.strokeWidth / 2; | ||
const cylinder = new Cylinder({ | ||
radii: [r, r, this.tipWidth, 0], | ||
heights: [this.length - this.tipLength + 0.05, 0, this.tipLength], | ||
phiSegments: 8, | ||
}); | ||
|
||
cylinder.update(); | ||
this.mergeAttributes(cylinder, "position", "normal"); | ||
this.setIndex(this.getAttributeVal("position").length / 3); | ||
|
||
const vector = this.vector; | ||
const UP = VECTORS.UP; | ||
const pivot = vector.cross(UP); | ||
const angle = Math.acos(vector.project(UP).y / vector.norm); | ||
|
||
const transMatrix = Matrix.rotateOn(pivot, angle, 4).trans(Matrix.translation(...this.start.center)); | ||
|
||
this.matrixTransform(transMatrix, 4); | ||
} | ||
|
||
set vector(vec) { | ||
this.end = new Point3D(this.start.center.add(vec)); | ||
} | ||
|
||
get vector() { | ||
return this.end.center.minus(this.start.center); | ||
} | ||
|
||
set length(val) { | ||
const vec = this.vector; | ||
vec.norm = val; | ||
this.vector = vec; | ||
} | ||
|
||
get length() { | ||
return this.vector.norm; | ||
} | ||
} |
Oops, something went wrong.