Fixed a bug in the multiHeadMatcher
This commit is contained in:
parent
e38612723e
commit
655101d6a8
8 changed files with 355 additions and 38 deletions
|
@ -2,13 +2,13 @@ proposal awaitToPomise{
|
||||||
case single{
|
case single{
|
||||||
applicable to {
|
applicable to {
|
||||||
"let <<ident:Identifier>> = await <<awaitedExpr: Expression>>;
|
"let <<ident:Identifier>> = await <<awaitedExpr: Expression>>;
|
||||||
<<statements: (Statement && !ReturnStatement)+>>
|
<<statements: (Statement && !ReturnStatement && !ContinueStatement &&!BreakStatement)+>>
|
||||||
return <<returnExpr: Expression>>
|
return <<returnExpr: Expression>>
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
transform to{
|
transform to{
|
||||||
"return <<awaitedExpr>>.then((<<ident>>) => {
|
"return <<awaitedExpr>>.then(async <<ident>> => {
|
||||||
<<statements>>
|
<<statements>>
|
||||||
return <<returnExpr>>
|
return <<returnExpr>>
|
||||||
});"
|
});"
|
||||||
|
|
14
dsl_files/pipelineDeep.jstql
Normal file
14
dsl_files/pipelineDeep.jstql
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
proposal Pipeline{
|
||||||
|
|
||||||
|
case SingleArgument {
|
||||||
|
applicable to {
|
||||||
|
"<<someFunctionIdent:Identifier || MemberExpression>>(<<otherFunctionIdent:Identifier || MemberExpression>>(<<arggg:Identifier>>));"
|
||||||
|
}
|
||||||
|
|
||||||
|
transform to {
|
||||||
|
"(<<arggg>> |> <<otherFunctionIdent>>(%)) |> <<someFunctionIdent>>(%);"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,8 +1,104 @@
|
||||||
async function lol() {
|
return awaitedExpr.then(async _geometry => {
|
||||||
let a = 0;
|
const _intersectPoint = /*@__PURE__*/new Vector3();
|
||||||
return gc().then(async (b) => {
|
const _worldScale = /*@__PURE__*/new Vector3();
|
||||||
let c = 100;
|
const _mvPosition = /*@__PURE__*/new Vector3();
|
||||||
let d = await l();
|
const _alignedPosition = /*@__PURE__*/new Vector2();
|
||||||
return 1;
|
const _rotatedPosition = /*@__PURE__*/new Vector2();
|
||||||
});
|
const _viewWorldMatrix = /*@__PURE__*/new Matrix4();
|
||||||
}
|
const _vA = /*@__PURE__*/new Vector3();
|
||||||
|
const _vB = /*@__PURE__*/new Vector3();
|
||||||
|
const _vC = /*@__PURE__*/new Vector3();
|
||||||
|
const _uvA = /*@__PURE__*/new Vector2();
|
||||||
|
const _uvB = /*@__PURE__*/new Vector2();
|
||||||
|
const _uvC = /*@__PURE__*/new Vector2();
|
||||||
|
class Sprite extends Object3D {
|
||||||
|
constructor(material = new SpriteMaterial()) {
|
||||||
|
super();
|
||||||
|
this.isSprite = true;
|
||||||
|
this.type = "Sprite";
|
||||||
|
if (_geometry === undefined) {
|
||||||
|
_geometry = new BufferGeometry();
|
||||||
|
const float32Array = new Float32Array([-0.5, -0.5, 0, 0, 0, 0.5, -0.5, 0, 1, 0, 0.5, 0.5, 0, 1, 1, -0.5, 0.5, 0, 0, 1]);
|
||||||
|
const interleavedBuffer = new InterleavedBuffer(float32Array, 5);
|
||||||
|
_geometry.setIndex([0, 1, 2, 0, 2, 3]);
|
||||||
|
_geometry.setAttribute("position", new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
|
||||||
|
_geometry.setAttribute("uv", new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
|
||||||
|
}
|
||||||
|
this.geometry = _geometry;
|
||||||
|
this.material = material;
|
||||||
|
this.center = new Vector2(0.5, 0.5);
|
||||||
|
}
|
||||||
|
raycast(raycaster, intersects) {
|
||||||
|
if (raycaster.camera === null) {
|
||||||
|
console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
|
||||||
|
}
|
||||||
|
_worldScale.setFromMatrixScale(this.matrixWorld);
|
||||||
|
_viewWorldMatrix.copy(raycaster.camera.matrixWorld);
|
||||||
|
this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
|
||||||
|
_mvPosition.setFromMatrixPosition(this.modelViewMatrix);
|
||||||
|
if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
|
||||||
|
_worldScale.multiplyScalar(-_mvPosition.z);
|
||||||
|
}
|
||||||
|
const rotation = this.material.rotation;
|
||||||
|
let sin, cos;
|
||||||
|
if (rotation !== 0) {
|
||||||
|
cos = Math.cos(rotation);
|
||||||
|
sin = Math.sin(rotation);
|
||||||
|
}
|
||||||
|
const center = this.center;
|
||||||
|
transformVertex(_vA.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
|
||||||
|
transformVertex(_vB.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
|
||||||
|
transformVertex(_vC.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
|
||||||
|
_uvA.set(0, 0);
|
||||||
|
_uvB.set(1, 0);
|
||||||
|
_uvC.set(1, 1);
|
||||||
|
|
||||||
|
// check first triangle
|
||||||
|
let intersect = raycaster.ray.intersectTriangle(_vA, _vB, _vC, false, _intersectPoint);
|
||||||
|
if (intersect === null) {
|
||||||
|
// check second triangle
|
||||||
|
transformVertex(_vB.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
|
||||||
|
_uvB.set(0, 1);
|
||||||
|
intersect = raycaster.ray.intersectTriangle(_vA, _vC, _vB, false, _intersectPoint);
|
||||||
|
if (intersect === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const distance = raycaster.ray.origin.distanceTo(_intersectPoint);
|
||||||
|
if (distance < raycaster.near || distance > raycaster.far) return;
|
||||||
|
intersects.push({
|
||||||
|
distance: distance,
|
||||||
|
point: _intersectPoint.clone(),
|
||||||
|
uv: Triangle.getInterpolation(_intersectPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2()),
|
||||||
|
face: null,
|
||||||
|
object: this
|
||||||
|
});
|
||||||
|
}
|
||||||
|
copy(source, recursive) {
|
||||||
|
super.copy(source, recursive);
|
||||||
|
if (source.center !== undefined) this.center.copy(source.center);
|
||||||
|
this.material = source.material;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
|
||||||
|
// compute position in camera space
|
||||||
|
_alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale);
|
||||||
|
|
||||||
|
// to check if rotation is not zero
|
||||||
|
if (sin !== undefined) {
|
||||||
|
_rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
|
||||||
|
_rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
|
||||||
|
} else {
|
||||||
|
_rotatedPosition.copy(_alignedPosition);
|
||||||
|
}
|
||||||
|
vertexPosition.copy(mvPosition);
|
||||||
|
vertexPosition.x += _rotatedPosition.x;
|
||||||
|
vertexPosition.y += _rotatedPosition.y;
|
||||||
|
|
||||||
|
// transform to world space
|
||||||
|
vertexPosition.applyMatrix4(_viewWorldMatrix);
|
||||||
|
}
|
||||||
|
export { Sprite };
|
||||||
|
return returnExpr;
|
||||||
|
});
|
35
src/index.ts
35
src/index.ts
|
@ -12,7 +12,7 @@ import { parseJSTQL } from "./langium/langiumRunner";
|
||||||
|
|
||||||
const dir = "../prettier/src";
|
const dir = "../prettier/src";
|
||||||
|
|
||||||
const path = "test_files/do_test.js";
|
const path = "test_files/test2.js";
|
||||||
const file = Bun.file(path);
|
const file = Bun.file(path);
|
||||||
const codeFromFile = await file.text();
|
const codeFromFile = await file.text();
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
|
@ -21,16 +21,16 @@ const main = async () => {
|
||||||
/*
|
/*
|
||||||
console.log(codeFromFile);
|
console.log(codeFromFile);
|
||||||
const jstql_file =
|
const jstql_file =
|
||||||
"/home/rolfmg/Coding/Master/didactic-chainsaw/dsl_files/do.jstql";
|
"/home/rolfmg/Coding/Master/didactic-chainsaw/dsl_files/awaitToPromise.jstql";
|
||||||
const test_file = Bun.file(jstql_file);
|
const test_file = Bun.file(jstql_file);
|
||||||
const test_JSTQL = await test_file.text();
|
const test_JSTQL = await test_file.text();
|
||||||
let proposals = await parseJSTQL(test_JSTQL);
|
let proposals = await parseJSTQL(test_JSTQL);
|
||||||
|
|
||||||
let [code, count] = transform(proposals[0].cases, codeFromFile);
|
let [code, count] = transform(proposals[0].cases, codeFromFile);
|
||||||
await Bun.write("output_files/output_do.js", code);
|
await Bun.write("output_files/test2.js", code);
|
||||||
return;
|
return;
|
||||||
*/
|
*/
|
||||||
let basepathExamplesJSFiles = "../react";
|
let basepathExamplesJSFiles = "../next.js";
|
||||||
let examples = (await readdir(basepathExamplesJSFiles, { recursive: true }))
|
let examples = (await readdir(basepathExamplesJSFiles, { recursive: true }))
|
||||||
.filter((x) => x.endsWith(".js"))
|
.filter((x) => x.endsWith(".js"))
|
||||||
.map((x) => basepathExamplesJSFiles + "/" + x);
|
.map((x) => basepathExamplesJSFiles + "/" + x);
|
||||||
|
@ -54,7 +54,7 @@ const main = async () => {
|
||||||
for (let examplesFile of examples) {
|
for (let examplesFile of examples) {
|
||||||
try {
|
try {
|
||||||
if (examplesFile.split("/").includes("compiled")) {
|
if (examplesFile.split("/").includes("compiled")) {
|
||||||
continue;
|
//continue;
|
||||||
}
|
}
|
||||||
console.log(examplesFile);
|
console.log(examplesFile);
|
||||||
let script = await Bun.file(examplesFile).text();
|
let script = await Bun.file(examplesFile).text();
|
||||||
|
@ -63,32 +63,25 @@ const main = async () => {
|
||||||
script
|
script
|
||||||
);
|
);
|
||||||
sum += matches;
|
sum += matches;
|
||||||
|
console.log(matches);
|
||||||
if (matches > 0) {
|
if (matches > 0) {
|
||||||
//await Bun.write(
|
await Bun.write(
|
||||||
// "output_testing/" + count + examplesFile.split("/").at(-1),
|
"output_testing/" +
|
||||||
//resultString
|
count +
|
||||||
//);
|
examplesFile.split("/").join("_"),
|
||||||
|
resultString
|
||||||
|
);
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
filesSucceeded += 1;
|
filesSucceeded += 1;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
failures += 1;
|
failures += 1;
|
||||||
|
//console.log(e);
|
||||||
}
|
}
|
||||||
console.log("current sum", sum);
|
console.log("current sum", sum);
|
||||||
}
|
}
|
||||||
result.push(
|
result.push(
|
||||||
"Total for " +
|
proposalFile + ", " + sum + ", " + count + ", " + filesSucceeded
|
||||||
proposalFile +
|
|
||||||
" is " +
|
|
||||||
sum +
|
|
||||||
",failures " +
|
|
||||||
failures +
|
|
||||||
",succeeded " +
|
|
||||||
filesSucceeded +
|
|
||||||
", Files With Matches " +
|
|
||||||
count +
|
|
||||||
",totalJSFiles " +
|
|
||||||
examples.length
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,7 +226,7 @@ export class Matcher {
|
||||||
let statements: TreeNode<PairedNodes>[] = [];
|
let statements: TreeNode<PairedNodes>[] = [];
|
||||||
let aplToi = 0;
|
let aplToi = 0;
|
||||||
let codei = 0;
|
let codei = 0;
|
||||||
while (aplToi < aplTo.length) {
|
while (aplToi < aplTo.length && codei + y < code.length) {
|
||||||
let [paired, matchResult] = this.exactExprMatcher(
|
let [paired, matchResult] = this.exactExprMatcher(
|
||||||
code[codei + y],
|
code[codei + y],
|
||||||
aplTo[aplToi]
|
aplTo[aplToi]
|
||||||
|
@ -260,6 +260,9 @@ export class Matcher {
|
||||||
aplToi += 1;
|
aplToi += 1;
|
||||||
codei += 1;
|
codei += 1;
|
||||||
}
|
}
|
||||||
|
if (aplToi !== aplTo.length) {
|
||||||
|
fullMatch = false;
|
||||||
|
}
|
||||||
if (fullMatch) {
|
if (fullMatch) {
|
||||||
this.matches.push({ statements });
|
this.matches.push({ statements });
|
||||||
}
|
}
|
||||||
|
@ -317,6 +320,7 @@ export class Matcher {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pairedChild.element.codeNode.push(
|
pairedChild.element.codeNode.push(
|
||||||
...maybeChild.element.codeNode
|
...maybeChild.element.codeNode
|
||||||
);
|
);
|
||||||
|
@ -327,6 +331,10 @@ export class Matcher {
|
||||||
i += 1;
|
i += 1;
|
||||||
aplToi += 1;
|
aplToi += 1;
|
||||||
}
|
}
|
||||||
|
// Verify it is a full match
|
||||||
|
if (aplToi < aplTo.children.length) {
|
||||||
|
return [undefined, MatchResult.NoMatch];
|
||||||
|
}
|
||||||
if (i < code.children.length) {
|
if (i < code.children.length) {
|
||||||
return [undefined, MatchResult.NoMatch];
|
return [undefined, MatchResult.NoMatch];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
async function something() {
|
async function something() {
|
||||||
let a = 100;
|
let a = 100;
|
||||||
a *= 100000;
|
a *= 100000;
|
||||||
return fetch("https://uib.no").then(uib => {
|
return fetch("https://uib.no").then(async uib => {
|
||||||
a += 100000;
|
a += 100000;
|
||||||
a -= 1000;
|
a -= 1000;
|
||||||
return [a, uib];
|
return [a, uib];
|
||||||
|
|
|
@ -91,11 +91,11 @@ function transformSelfHosted(
|
||||||
throw new Error("This no worky LOL");
|
throw new Error("This no worky LOL");
|
||||||
}
|
}
|
||||||
let matches = runMatch(codeTree, applicableToTree, internals);
|
let matches = runMatch(codeTree, applicableToTree, internals);
|
||||||
|
//showTreePaired(matches[0].statements[0]);
|
||||||
console.log("We found", matches.length, "matches");
|
//console.log("We found", matches.length, "matches");
|
||||||
|
|
||||||
let outputAST = transformer(matches, transformToTree, codeAST, transformTo);
|
let outputAST = transformer(matches, transformToTree, codeAST, transformTo);
|
||||||
|
|
||||||
console.log("Finished transforming");
|
//console.log("Finished transforming");
|
||||||
return [outputAST, matches.length];
|
return [outputAST, matches.length];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,208 @@
|
||||||
a(a(a(a(a(a(a(b)))))));
|
let _geometry;
|
||||||
c(c(c(c(c(d, b), b), b), b), b);
|
|
||||||
|
const _intersectPoint = /*@__PURE__*/ new Vector3();
|
||||||
|
const _worldScale = /*@__PURE__*/ new Vector3();
|
||||||
|
const _mvPosition = /*@__PURE__*/ new Vector3();
|
||||||
|
|
||||||
|
const _alignedPosition = /*@__PURE__*/ new Vector2();
|
||||||
|
const _rotatedPosition = /*@__PURE__*/ new Vector2();
|
||||||
|
const _viewWorldMatrix = /*@__PURE__*/ new Matrix4();
|
||||||
|
|
||||||
|
const _vA = /*@__PURE__*/ new Vector3();
|
||||||
|
const _vB = /*@__PURE__*/ new Vector3();
|
||||||
|
const _vC = /*@__PURE__*/ new Vector3();
|
||||||
|
|
||||||
|
const _uvA = /*@__PURE__*/ new Vector2();
|
||||||
|
const _uvB = /*@__PURE__*/ new Vector2();
|
||||||
|
const _uvC = /*@__PURE__*/ new Vector2();
|
||||||
|
|
||||||
|
class Sprite extends Object3D {
|
||||||
|
constructor(material = new SpriteMaterial()) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.isSprite = true;
|
||||||
|
|
||||||
|
this.type = "Sprite";
|
||||||
|
|
||||||
|
if (_geometry === undefined) {
|
||||||
|
_geometry = new BufferGeometry();
|
||||||
|
|
||||||
|
const float32Array = new Float32Array([
|
||||||
|
-0.5, -0.5, 0, 0, 0, 0.5, -0.5, 0, 1, 0, 0.5, 0.5, 0, 1, 1,
|
||||||
|
-0.5, 0.5, 0, 0, 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const interleavedBuffer = new InterleavedBuffer(float32Array, 5);
|
||||||
|
|
||||||
|
_geometry.setIndex([0, 1, 2, 0, 2, 3]);
|
||||||
|
_geometry.setAttribute(
|
||||||
|
"position",
|
||||||
|
new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false)
|
||||||
|
);
|
||||||
|
_geometry.setAttribute(
|
||||||
|
"uv",
|
||||||
|
new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.geometry = _geometry;
|
||||||
|
this.material = material;
|
||||||
|
|
||||||
|
this.center = new Vector2(0.5, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
raycast(raycaster, intersects) {
|
||||||
|
if (raycaster.camera === null) {
|
||||||
|
console.error(
|
||||||
|
'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_worldScale.setFromMatrixScale(this.matrixWorld);
|
||||||
|
|
||||||
|
_viewWorldMatrix.copy(raycaster.camera.matrixWorld);
|
||||||
|
this.modelViewMatrix.multiplyMatrices(
|
||||||
|
raycaster.camera.matrixWorldInverse,
|
||||||
|
this.matrixWorld
|
||||||
|
);
|
||||||
|
|
||||||
|
_mvPosition.setFromMatrixPosition(this.modelViewMatrix);
|
||||||
|
|
||||||
|
if (
|
||||||
|
raycaster.camera.isPerspectiveCamera &&
|
||||||
|
this.material.sizeAttenuation === false
|
||||||
|
) {
|
||||||
|
_worldScale.multiplyScalar(-_mvPosition.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rotation = this.material.rotation;
|
||||||
|
let sin, cos;
|
||||||
|
|
||||||
|
if (rotation !== 0) {
|
||||||
|
cos = Math.cos(rotation);
|
||||||
|
sin = Math.sin(rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
const center = this.center;
|
||||||
|
|
||||||
|
transformVertex(
|
||||||
|
_vA.set(-0.5, -0.5, 0),
|
||||||
|
_mvPosition,
|
||||||
|
center,
|
||||||
|
_worldScale,
|
||||||
|
sin,
|
||||||
|
cos
|
||||||
|
);
|
||||||
|
transformVertex(
|
||||||
|
_vB.set(0.5, -0.5, 0),
|
||||||
|
_mvPosition,
|
||||||
|
center,
|
||||||
|
_worldScale,
|
||||||
|
sin,
|
||||||
|
cos
|
||||||
|
);
|
||||||
|
transformVertex(
|
||||||
|
_vC.set(0.5, 0.5, 0),
|
||||||
|
_mvPosition,
|
||||||
|
center,
|
||||||
|
_worldScale,
|
||||||
|
sin,
|
||||||
|
cos
|
||||||
|
);
|
||||||
|
|
||||||
|
_uvA.set(0, 0);
|
||||||
|
_uvB.set(1, 0);
|
||||||
|
_uvC.set(1, 1);
|
||||||
|
|
||||||
|
// check first triangle
|
||||||
|
let intersect = raycaster.ray.intersectTriangle(
|
||||||
|
_vA,
|
||||||
|
_vB,
|
||||||
|
_vC,
|
||||||
|
false,
|
||||||
|
_intersectPoint
|
||||||
|
);
|
||||||
|
|
||||||
|
if (intersect === null) {
|
||||||
|
// check second triangle
|
||||||
|
transformVertex(
|
||||||
|
_vB.set(-0.5, 0.5, 0),
|
||||||
|
_mvPosition,
|
||||||
|
center,
|
||||||
|
_worldScale,
|
||||||
|
sin,
|
||||||
|
cos
|
||||||
|
);
|
||||||
|
_uvB.set(0, 1);
|
||||||
|
|
||||||
|
intersect = raycaster.ray.intersectTriangle(
|
||||||
|
_vA,
|
||||||
|
_vC,
|
||||||
|
_vB,
|
||||||
|
false,
|
||||||
|
_intersectPoint
|
||||||
|
);
|
||||||
|
if (intersect === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const distance = raycaster.ray.origin.distanceTo(_intersectPoint);
|
||||||
|
|
||||||
|
if (distance < raycaster.near || distance > raycaster.far) return;
|
||||||
|
|
||||||
|
intersects.push({
|
||||||
|
distance: distance,
|
||||||
|
point: _intersectPoint.clone(),
|
||||||
|
uv: Triangle.getInterpolation(
|
||||||
|
_intersectPoint,
|
||||||
|
_vA,
|
||||||
|
_vB,
|
||||||
|
_vC,
|
||||||
|
_uvA,
|
||||||
|
_uvB,
|
||||||
|
_uvC,
|
||||||
|
new Vector2()
|
||||||
|
),
|
||||||
|
face: null,
|
||||||
|
object: this,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
copy(source, recursive) {
|
||||||
|
super.copy(source, recursive);
|
||||||
|
|
||||||
|
if (source.center !== undefined) this.center.copy(source.center);
|
||||||
|
|
||||||
|
this.material = source.material;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
|
||||||
|
// compute position in camera space
|
||||||
|
_alignedPosition
|
||||||
|
.subVectors(vertexPosition, center)
|
||||||
|
.addScalar(0.5)
|
||||||
|
.multiply(scale);
|
||||||
|
|
||||||
|
// to check if rotation is not zero
|
||||||
|
if (sin !== undefined) {
|
||||||
|
_rotatedPosition.x =
|
||||||
|
cos * _alignedPosition.x - sin * _alignedPosition.y;
|
||||||
|
_rotatedPosition.y =
|
||||||
|
sin * _alignedPosition.x + cos * _alignedPosition.y;
|
||||||
|
} else {
|
||||||
|
_rotatedPosition.copy(_alignedPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
vertexPosition.copy(mvPosition);
|
||||||
|
vertexPosition.x += _rotatedPosition.x;
|
||||||
|
vertexPosition.y += _rotatedPosition.y;
|
||||||
|
|
||||||
|
// transform to world space
|
||||||
|
vertexPosition.applyMatrix4(_viewWorldMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Sprite };
|
||||||
|
|
Loading…
Reference in a new issue