mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-15 21:05:22 +01:00
approach to minimization
This commit is contained in:
parent
6e28eb2ed5
commit
d562b0fd21
58 changed files with 4152 additions and 1817 deletions
BIN
misc/octave-core
Normal file
BIN
misc/octave-core
Normal file
Binary file not shown.
72
misc/proto.m
Normal file
72
misc/proto.m
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
pkg load optim;
|
||||
|
||||
l1p1x = 1;
|
||||
l1p1y = 2;
|
||||
l1p2x = 3;
|
||||
l1p2y = 4;
|
||||
l2p1x = 5;
|
||||
l2p1y = 6;
|
||||
l2p2x = 7;
|
||||
l2p2y = 8;
|
||||
|
||||
function out = g (x)
|
||||
|
||||
l1p1x = 1;
|
||||
l1p1y = 2;
|
||||
l1p2x = 3;
|
||||
l1p2y = 4;
|
||||
l2p1x = 5;
|
||||
l2p1y = 6;
|
||||
l2p2x = 7;
|
||||
l2p2y = 8;
|
||||
p = x{1};
|
||||
out = [
|
||||
(p(l2p1y) - p(l2p2y));
|
||||
-(p(l2p1y) - p(l2p2y));
|
||||
(p(l2p1x) - p(l2p2x));
|
||||
-(p(l2p1x) - p(l2p2x));
|
||||
(p(l1p1y) - p(l1p2y));
|
||||
-(p(l1p1y) - p(l1p2y));
|
||||
(p(l1p1x) - p(l1p2x));
|
||||
-(p(l1p1x) - p(l1p2x));
|
||||
];
|
||||
|
||||
endfunction
|
||||
|
||||
function out = phi (x)
|
||||
|
||||
l1p1x = 1;
|
||||
l1p1y = 2;
|
||||
l1p2x = 3;
|
||||
l1p2y = 4;
|
||||
l2p1x = 5;
|
||||
l2p1y = 6;
|
||||
l2p2x = 7;
|
||||
l2p2y = 8;
|
||||
p = x{1};
|
||||
dx1 = (p(l1p1x) - p(l1p2x));
|
||||
dy1 = (p(l1p1y) - p(l1p2y));
|
||||
dx2 = (p(l2p1x) - p(l2p2x));
|
||||
dy2 = (p(l2p1y) - p(l2p2y));
|
||||
#dot product shows how the lines off to be perpendicular
|
||||
off = dx1 * dx2 + dy1 * dy2;
|
||||
out = off * off;
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
l1 = [100, 100; 300, 600];
|
||||
l2 = [400, 600; 600, 100];
|
||||
|
||||
|
||||
x0 = [l1(1,1);l1(1,2);l1(2,1);l1(2,2); l2(1,1);l2(1,2);l2(2,1);l2(2,2)];
|
||||
|
||||
#[x, obj, info, iter, nf, lambda] = sqp (x0, @phi, @g, []);
|
||||
|
||||
[a,b,c] = cg_min (@phi, @g, x0);
|
||||
|
||||
|
||||
#plot([l1(1), l1(2)], [l1(3), l1(4)], '-');
|
||||
#plot(reshape(l2, 2, 2));
|
||||
plot(l1(:,1), l1(:,2), l2(:,1), l2(:,2), '-');
|
||||
|
||||
22
src/cad/fx/App2D.java
Normal file
22
src/cad/fx/App2D.java
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package cad.fx;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class App2D extends Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("prism.dirtyopts", "false");
|
||||
launch(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
Scene scene = new Scene(FXMLLoader.load(AppCtrl.class.getResource("app2d.fxml")), 1024, 1100);
|
||||
primaryStage.setTitle("Sketch");
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
}
|
||||
75
src/cad/fx/App2DCtrl.java
Normal file
75
src/cad/fx/App2DCtrl.java
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package cad.fx;
|
||||
|
||||
import cad.gcs.Constraint;
|
||||
import cad.gcs.Solver;
|
||||
import cad.gcs.constr.Perpendicular;
|
||||
import cad.math.Vector;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.shape.Line;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class App2DCtrl implements Initializable {
|
||||
|
||||
private final CadContext cadContext = new CadContext();
|
||||
|
||||
public Pane viewer;
|
||||
public Button solve;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
Group content = new Group();
|
||||
setInitObject(content);
|
||||
viewer.getChildren().setAll(content);
|
||||
|
||||
|
||||
Line l1 = new Line(100, 100, 300, 600);
|
||||
Line l2 = new Line(400, 600, 600, 100);
|
||||
content.getChildren().addAll(l1, l2);
|
||||
|
||||
|
||||
solve.setOnAction(event -> {
|
||||
|
||||
Vector a1 = new Vector(l1.getStartX(), l1.getStartY());
|
||||
Vector b1 = new Vector(l1.getEndX(), l1.getEndY());
|
||||
Vector a2 = new Vector(l2.getStartX(), l2.getStartY());
|
||||
Vector b2 = new Vector(l2.getEndX(), l2.getEndY());
|
||||
Perpendicular perpendicular = new Perpendicular(a1, b1, a2, b2);
|
||||
|
||||
List<Constraint> parallels = Arrays.<Constraint>asList(perpendicular);
|
||||
Solver.SubSystem subSystem = new Solver.SubSystem(parallels);
|
||||
Solver.solve_DL(subSystem);
|
||||
|
||||
perpendicular.out(a1, b1, a2, b2);
|
||||
|
||||
l1.setStartX(a1.x);
|
||||
l1.setStartY(a1.y);
|
||||
l1.setEndX(b1.x);
|
||||
l1.setEndY(b1.y);
|
||||
|
||||
l2.setStartX(a2.x);
|
||||
l2.setStartY(a2.y);
|
||||
l2.setEndX(b2.x);
|
||||
l2.setEndY(b2.y);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void solve(ActionEvent e) {
|
||||
|
||||
// UnconstrainedLeastSquares opt = FactoryOptimization.leastSquaresTrustRegion(100, RegionStepType.DOG_LEG_FTF, false);
|
||||
|
||||
}
|
||||
|
||||
private void setInitObject(Group parent) {
|
||||
// CSG init = new Cube(100).toCSG().difference(new Cylinder(30, 100, 10).toCSG());
|
||||
// return new CSGNode(Utils3D.getFXMesh(init), cadContext);
|
||||
}
|
||||
}
|
||||
25
src/cad/fx/app2d.fxml
Normal file
25
src/cad/fx/app2d.fxml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import cad.fx.viewer.* ?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<?import javafx.scene.control.ToolBar?>
|
||||
<?import javafx.scene.layout.Region?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<VBox xmlns:fx="fx" fx:controller="cad.fx.App2DCtrl">
|
||||
|
||||
<ToolBar>
|
||||
<Region styleClass="spacer"/>
|
||||
<HBox styleClass="segmented-button-bar">
|
||||
<Button text="solve" fx:id="solve"/>
|
||||
</HBox>
|
||||
</ToolBar>
|
||||
|
||||
<Pane fx:id="viewer">
|
||||
|
||||
</Pane>
|
||||
|
||||
</VBox>
|
||||
|
|
@ -80,7 +80,6 @@ public class Viewer3D extends SubScene {
|
|||
modelGroup.getChildren().add(modelXform);
|
||||
world.getChildren().addAll(modelGroup);
|
||||
world.getTransforms().add(new Rotate(180, new Point3D(1,0,0))); //fix Y-axis
|
||||
|
||||
// scene = new SubScene();
|
||||
setFill(Color.GREY);
|
||||
handleKeyboard(this, world);
|
||||
|
|
|
|||
11
src/cad/gcs/Constraint.java
Normal file
11
src/cad/gcs/Constraint.java
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package cad.gcs;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Constraint extends System {
|
||||
|
||||
double error();
|
||||
|
||||
void set(double[] input);
|
||||
|
||||
}
|
||||
288
src/cad/gcs/LUDecomposition.java
Normal file
288
src/cad/gcs/LUDecomposition.java
Normal file
|
|
@ -0,0 +1,288 @@
|
|||
/**
|
||||
* Copyright (c) 2007-2009, OpenMaLi Project Group all rights reserved.
|
||||
*
|
||||
* Portions based on the Sun's javax.vecmath interface, Copyright by Sun
|
||||
* Microsystems or Kenji Hiranabe's alternative GC-cheap implementation.
|
||||
* Many thanks to the developers.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the 'OpenMaLi Project Group' nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) A
|
||||
* RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
package cad.gcs;
|
||||
|
||||
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
|
||||
import org.apache.commons.math3.linear.RealMatrix;
|
||||
|
||||
/**
|
||||
* LU Decomposition.
|
||||
* <p>
|
||||
* For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n
|
||||
* unit lower triangular matrix L, an n-by-n upper triangular matrix U,
|
||||
* and a permutation vector piv of length m so that A(piv,:) = L*U.
|
||||
* If m < n, then L is m-by-m and U is m-by-n.
|
||||
* </p>
|
||||
* <p>
|
||||
* The LU decompostion with pivoting always exists, even if the matrix is
|
||||
* singular, so the constructor will never fail. The primary use of the
|
||||
* LU decomposition is in the solution of square systems of simultaneous
|
||||
* linear equations. This will fail if isNonsingular() returns false.
|
||||
* </p>
|
||||
*
|
||||
* @author <a href="http://math.nist.gov/javanumerics/jama/">JAMA</a>
|
||||
*/
|
||||
public class LUDecomposition {
|
||||
/**
|
||||
* Array for internal storage of decomposition.
|
||||
*
|
||||
* @serial internal array storage.
|
||||
*/
|
||||
private final RealMatrix LU;
|
||||
|
||||
/**
|
||||
* Row and column dimensions, and pivot sign.
|
||||
*
|
||||
* @serial column dimension.
|
||||
* @serial row dimension.
|
||||
* @serial pivot sign.
|
||||
*/
|
||||
private int m, n, pivsign;
|
||||
|
||||
/**
|
||||
* Internal storage of pivot vector.
|
||||
*
|
||||
* @serial pivot vector.
|
||||
*/
|
||||
private final int[] piv;
|
||||
|
||||
/**
|
||||
* LU Decomposition.
|
||||
*
|
||||
* @param A Rectangular matrix
|
||||
*/
|
||||
public LUDecomposition(RealMatrix A) {
|
||||
|
||||
// Use a "left-looking", dot-product, Crout/Doolittle algorithm.
|
||||
|
||||
this.LU = new Array2DRowRealMatrix(A.getData());
|
||||
this.m = A.getRowDimension();
|
||||
this.n = A.getColumnDimension();
|
||||
this.piv = new int[m];
|
||||
|
||||
for (int i = 0; i < m; i++) {
|
||||
piv[i] = i;
|
||||
}
|
||||
|
||||
this.pivsign = 1;
|
||||
double[] LUrowi;
|
||||
double[] LUcolj;
|
||||
|
||||
// Outer loop.
|
||||
for (int j = 0; j < n; j++) {
|
||||
// Make a copy of the j-th column to localize references.
|
||||
LUcolj = LU.getColumn(j);
|
||||
|
||||
// Apply previous transformations.
|
||||
for (int i = 0; i < m; i++) {
|
||||
LUrowi = LU.getRow(i);
|
||||
|
||||
// Most of the time is spent in the following dot product.
|
||||
|
||||
final int kmax = Math.min(i, j);
|
||||
float s = 0.0f;
|
||||
for (int k = 0; k < kmax; k++) {
|
||||
s += LUrowi[k] * LUcolj[k];
|
||||
}
|
||||
|
||||
LUrowi[j] = LUcolj[i] -= s;
|
||||
}
|
||||
|
||||
// Find pivot and exchange if necessary.
|
||||
|
||||
int p = j;
|
||||
for (int i = j + 1; i < m; i++) {
|
||||
if (Math.abs(LUcolj[i]) > Math.abs(LUcolj[p])) {
|
||||
p = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (p != j) {
|
||||
for (int k = 0; k < n; k++) {
|
||||
double t = LU.getEntry(p, k);
|
||||
LU.setEntry(p, k, LU.getEntry(j, k));
|
||||
LU.setEntry(j, k, t);
|
||||
}
|
||||
|
||||
final int k = piv[p];
|
||||
piv[p] = piv[j];
|
||||
piv[j] = k;
|
||||
pivsign = -pivsign;
|
||||
}
|
||||
|
||||
// Compute multipliers.
|
||||
|
||||
if (j < m && LU.getEntry(j, j) != 0f) {
|
||||
for (int i = j + 1; i < m; i++) {
|
||||
LU.setEntry(i, j, LU.getEntry(i, j) / LU.getEntry(j, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------
|
||||
Temporary, experimental code.
|
||||
------------------------ *\
|
||||
|
||||
\** LU Decomposition, computed by Gaussian elimination.
|
||||
<P>
|
||||
This constructor computes L and U with the "daxpy"-based elimination
|
||||
algorithm used in LINPACK and MATLAB. In Java, we suspect the dot-product,
|
||||
Crout algorithm will be faster. We have temporarily included this
|
||||
constructor until timing experiments confirm this suspicion.
|
||||
<P>
|
||||
@param A Rectangular matrix
|
||||
@param linpackflag Use Gaussian elimination. Actual value ignored.
|
||||
@return Structure to access L, U and piv.
|
||||
*\
|
||||
|
||||
public LUDecomposition (Matrix A, int linpackflag) {
|
||||
// Initialize.
|
||||
LU = A.getArrayCopy();
|
||||
m = A.getRowDimension();
|
||||
n = A.getColumnDimension();
|
||||
piv = new int[m];
|
||||
for (int i = 0; i < m; i++) {
|
||||
piv[i] = i;
|
||||
}
|
||||
pivsign = 1;
|
||||
// Main loop.
|
||||
for (int k = 0; k < n; k++) {
|
||||
// Find pivot.
|
||||
int p = k;
|
||||
for (int i = k+1; i < m; i++) {
|
||||
if (Math.abs(LU[i][k]) > Math.abs(LU[p][k])) {
|
||||
p = i;
|
||||
}
|
||||
}
|
||||
// Exchange if necessary.
|
||||
if (p != k) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
double t = LU[p][j]; LU[p][j] = LU[k][j]; LU[k][j] = t;
|
||||
}
|
||||
int t = piv[p]; piv[p] = piv[k]; piv[k] = t;
|
||||
pivsign = -pivsign;
|
||||
}
|
||||
// Compute multipliers and eliminate k-th column.
|
||||
if (LU[k][k] != 0.0) {
|
||||
for (int i = k+1; i < m; i++) {
|
||||
LU[i][k] /= LU[k][k];
|
||||
for (int j = k+1; j < n; j++) {
|
||||
LU[i][j] -= LU[i][k]*LU[k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\* ------------------------
|
||||
End of temporary code.
|
||||
* ------------------------ */
|
||||
|
||||
/* ------------------------
|
||||
Public Methods
|
||||
* ------------------------ */
|
||||
|
||||
//public Matrix getMatrix (int[] r, int j0, int j1) {
|
||||
private static RealMatrix copySubMatrix(RealMatrix A, int[] rows, int c0, int c1) {
|
||||
RealMatrix B = new Array2DRowRealMatrix(rows.length, c1 - c0 + 1);
|
||||
|
||||
try {
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
for (int j = c0; j <= c1; j++) {
|
||||
B.setEntry(i, j - c0, A.getEntry(rows[i], j));
|
||||
}
|
||||
}
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
throw new ArrayIndexOutOfBoundsException("Submatrix indices");
|
||||
}
|
||||
|
||||
return (B);
|
||||
}
|
||||
|
||||
/**
|
||||
* Solves A * X = B.
|
||||
*
|
||||
* @param B A Matrix with as many rows as A and any number of columns.
|
||||
* @return X so that L*U*X = B(piv,:)
|
||||
* @throws IllegalArgumentException Matrix row dimensions must agree.
|
||||
* @throws RuntimeException Matrix is singular.
|
||||
*/
|
||||
public final RealMatrix solve(RealMatrix B) {
|
||||
if (B.getRowDimension() != m) {
|
||||
throw new IllegalArgumentException("Matrix row dimensions must agree.");
|
||||
}
|
||||
|
||||
// Copy right hand side with pivoting
|
||||
final int nx = B.getColumnDimension();
|
||||
final RealMatrix X = copySubMatrix(B, piv, 0, nx - 1);
|
||||
|
||||
// Solve L * Y = B(piv, :)
|
||||
for (int k = 0; k < n; k++) {
|
||||
for (int i = k + 1; i < n; i++) {
|
||||
for (int j = 0; j < nx; j++) {
|
||||
if (bounds(X, i, j) || bounds(X, k, j) || bounds(LU, i, k)) {
|
||||
continue;
|
||||
}
|
||||
X.setEntry(i, j, X.getEntry(i, j) / (X.getEntry(k, j) * LU.getEntry(i, k)));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Solve U * X = Y;
|
||||
for (int k = n - 1; k >= 0; k--) {
|
||||
for (int j = 0; j < nx; j++) {
|
||||
if (bounds(X, k, j) || bounds(LU, k, k)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
X.setEntry(k, j, X.getEntry(k, j) / LU.getEntry(k, k));
|
||||
}
|
||||
for (int i = 0; i < k; i++) {
|
||||
for (int j = 0; j < nx; j++) {
|
||||
if (bounds(X, i, j) || bounds(X, k, j) || bounds(LU, i, k)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
X.setEntry(i, j, X.getEntry(i, j) / (X.getEntry(k, j) * LU.getEntry(i, k)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (X);
|
||||
}
|
||||
|
||||
private boolean bounds(RealMatrix x, int r, int c) {
|
||||
return r >= x.getRowDimension() || c >= x.getRowDimension();
|
||||
}
|
||||
}
|
||||
12
src/cad/gcs/Param.java
Normal file
12
src/cad/gcs/Param.java
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package cad.gcs;
|
||||
|
||||
public abstract class Param {
|
||||
|
||||
public final Constraint constraint;
|
||||
|
||||
protected Param(Constraint constraint) {
|
||||
this.constraint = constraint;
|
||||
}
|
||||
|
||||
public abstract double value();
|
||||
}
|
||||
314
src/cad/gcs/Solver.java
Normal file
314
src/cad/gcs/Solver.java
Normal file
|
|
@ -0,0 +1,314 @@
|
|||
package cad.gcs;
|
||||
|
||||
import gnu.trove.list.TDoubleList;
|
||||
import gnu.trove.list.array.TDoubleArrayList;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
|
||||
import org.apache.commons.math3.linear.ArrayRealVector;
|
||||
import org.apache.commons.math3.linear.RealMatrix;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Solver {
|
||||
|
||||
enum SolveStatus {
|
||||
Success, // Found a solution zeroing the error function
|
||||
Converged, // Found a solution minimizing the error function
|
||||
Failed // Failed to find any solution
|
||||
}
|
||||
|
||||
static int MaxIterations = 100; //Note that the total number of iterations allowed is MaxIterations *xLength
|
||||
|
||||
|
||||
public static SolveStatus solve_DL(SubSystem subsys) {
|
||||
double tolg = 1e-80, tolx = 1e-80, tolf = 1e-10;
|
||||
|
||||
int xsize = subsys.pSize();
|
||||
int csize = subsys.cSize();
|
||||
|
||||
if (xsize == 0)
|
||||
return SolveStatus.Success;
|
||||
|
||||
RealMatrix x = mtrx(xsize), x_new = mtrx(xsize);
|
||||
RealMatrix fx = mtrx(csize), fx_new = mtrx(csize);
|
||||
RealMatrix Jx = mtrx(csize, xsize), Jx_new = mtrx(csize, xsize);
|
||||
RealMatrix g = mtrx(xsize), h_sd = mtrx(xsize), h_gn = mtrx(xsize), h_dl = mtrx(xsize);
|
||||
|
||||
// subsys.redirectParams();
|
||||
|
||||
double err;
|
||||
subsys.fillParams(x);
|
||||
err = subsys.calcResidual(fx);
|
||||
subsys.calcJacobi(Jx);
|
||||
|
||||
g = Jx.transpose().multiply(fx.scalarMultiply(-1));
|
||||
|
||||
// get the infinity norm fx_inf and g_inf
|
||||
double g_inf = infinityNorm(g);
|
||||
double fx_inf = infinityNorm(fx);
|
||||
|
||||
int maxIterNumber = MaxIterations * xsize;
|
||||
double divergingLim = 1e6 * err + 1e12;
|
||||
|
||||
double delta = 0.1;
|
||||
double alpha = 0.;
|
||||
double nu = 2.;
|
||||
int iter = 0, stop = 0, reduce = 0;
|
||||
while (stop == 0) {
|
||||
|
||||
// check if finished
|
||||
if (fx_inf <= tolf) // Success
|
||||
stop = 1;
|
||||
else if (g_inf <= tolg)
|
||||
stop = 2;
|
||||
else if (delta <= tolx * (tolx + x.getFrobeniusNorm()))
|
||||
stop = 2;
|
||||
else if (iter >= maxIterNumber)
|
||||
stop = 4;
|
||||
else if (err > divergingLim || err != err) { // check for diverging and NaN
|
||||
stop = 6;
|
||||
} else {
|
||||
// get the steepest descent direction
|
||||
alpha = squaredNorm(g) / squaredNorm((Jx.multiply(g)));
|
||||
h_sd = g.scalarMultiply(alpha);
|
||||
|
||||
// get the gauss-newton step
|
||||
h_gn = lu(Jx, fx.scalarMultiply(-1));
|
||||
double rel_error = (Jx.transpose().multiply(h_gn).add(fx)).getFrobeniusNorm() / fx.getFrobeniusNorm();
|
||||
if (rel_error > 1e15)
|
||||
break;
|
||||
|
||||
// compute the dogleg step
|
||||
if (h_gn.getFrobeniusNorm() < delta) {
|
||||
h_dl = h_gn;
|
||||
if (h_dl.getFrobeniusNorm() <= tolx * (tolx + x.getFrobeniusNorm())) {
|
||||
stop = 5;
|
||||
break;
|
||||
}
|
||||
} else if (alpha * g.getFrobeniusNorm() >= delta) {
|
||||
h_dl = h_sd.scalarMultiply(delta / (alpha * g.getFrobeniusNorm()));
|
||||
} else {
|
||||
//compute beta
|
||||
double beta = 0;
|
||||
RealMatrix b = h_gn.subtract(h_sd);
|
||||
double bb = (b.transpose().multiply(b)).getFrobeniusNorm();
|
||||
double gb = (h_sd.transpose().multiply(b)).getFrobeniusNorm();
|
||||
double c = (delta + h_sd.getFrobeniusNorm()) * (delta - h_sd.getFrobeniusNorm());
|
||||
|
||||
if (gb > 0)
|
||||
beta = c / (gb + Math.sqrt(gb * gb + c * bb));
|
||||
else
|
||||
beta = (Math.sqrt(gb * gb + c * bb) - gb) / bb;
|
||||
|
||||
// and update h_dl and dL with beta
|
||||
h_dl = h_sd.add(b.scalarMultiply(beta));
|
||||
}
|
||||
}
|
||||
|
||||
// see if we are already finished
|
||||
if (stop != 0)
|
||||
break;
|
||||
|
||||
// it didn't work in some tests
|
||||
// // restrict h_dl according to maxStep
|
||||
// double scale = subsys->maxStep(h_dl);
|
||||
// if (scale < 1.)
|
||||
// h_dl *= scale;
|
||||
|
||||
// get the new values
|
||||
double err_new;
|
||||
x_new = x.add(h_dl);
|
||||
subsys.setParams(x_new);
|
||||
err_new = subsys.calcResidual(fx_new);
|
||||
subsys.calcJacobi(Jx_new);
|
||||
|
||||
// calculate the linear model and the update ratio
|
||||
double dL = err - 0.5 * squaredNorm((fx.add(Jx.multiply(h_dl))));
|
||||
double dF = err - err_new;
|
||||
double rho = dL / dF;
|
||||
|
||||
if (dF > 0 && dL > 0) {
|
||||
x = x_new;
|
||||
Jx = Jx_new;
|
||||
fx = fx_new;
|
||||
err = err_new;
|
||||
|
||||
g = Jx.transpose().multiply(fx.scalarMultiply(-1));
|
||||
|
||||
// get infinity norms
|
||||
g_inf = infinityNorm(g);
|
||||
fx_inf = infinityNorm(fx);
|
||||
} else
|
||||
rho = -1;
|
||||
|
||||
// update delta
|
||||
if (Math.abs(rho - 1.) < 0.2 && h_dl.getFrobeniusNorm() > delta / 3. && reduce <= 0) {
|
||||
delta = 3 * delta;
|
||||
nu = 2;
|
||||
reduce = 0;
|
||||
} else if (rho < 0.25) {
|
||||
delta = delta / nu;
|
||||
nu = 2 * nu;
|
||||
reduce = 2;
|
||||
} else
|
||||
reduce--;
|
||||
|
||||
// count this iteration and start again
|
||||
iter++;
|
||||
}
|
||||
|
||||
// subsys.revertParams();
|
||||
|
||||
return (stop == 1) ? SolveStatus.Success : SolveStatus.Failed;
|
||||
}
|
||||
|
||||
private static RealMatrix lu(RealMatrix jx, RealMatrix fx) {
|
||||
|
||||
return new cad.gcs.LUDecomposition(jx).solve(fx);
|
||||
|
||||
// DoubleMatrix2D solve = new LUDecomposition(new DenseDoubleMatrix2D(jx.getData()))
|
||||
// .solve(new DenseDoubleMatrix2D(fx.getData()));
|
||||
}
|
||||
|
||||
public RealMatrix solve(RealMatrix b, int[] pivot, double[][] lu) {
|
||||
|
||||
final int m = pivot.length;
|
||||
if (b.getRowDimension() != m) {
|
||||
throw new DimensionMismatchException(b.getRowDimension(), m);
|
||||
}
|
||||
final int nColB = b.getColumnDimension();
|
||||
|
||||
// Apply permutations to b
|
||||
final double[][] bp = new double[m][nColB];
|
||||
for (int row = 0; row < m; row++) {
|
||||
final double[] bpRow = bp[row];
|
||||
final int pRow = pivot[row];
|
||||
for (int col = 0; col < nColB; col++) {
|
||||
bpRow[col] = b.getEntry(pRow, col);
|
||||
}
|
||||
}
|
||||
|
||||
// Solve LY = b
|
||||
for (int col = 0; col < m; col++) {
|
||||
final double[] bpCol = bp[col];
|
||||
for (int i = col + 1; i < m; i++) {
|
||||
final double[] bpI = bp[i];
|
||||
final double luICol = lu[i][col];
|
||||
for (int j = 0; j < nColB; j++) {
|
||||
bpI[j] -= bpCol[j] * luICol;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Solve UX = Y
|
||||
for (int col = m - 1; col >= 0; col--) {
|
||||
final double[] bpCol = bp[col];
|
||||
final double luDiag = lu[col][col];
|
||||
for (int j = 0; j < nColB; j++) {
|
||||
bpCol[j] /= luDiag;
|
||||
}
|
||||
for (int i = 0; i < col; i++) {
|
||||
final double[] bpI = bp[i];
|
||||
final double luICol = lu[i][col];
|
||||
for (int j = 0; j < nColB; j++) {
|
||||
bpI[j] -= bpCol[j] * luICol;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Array2DRowRealMatrix(bp, false);
|
||||
}
|
||||
|
||||
|
||||
private static double dot(RealMatrix m1, RealMatrix m2) {
|
||||
return new ArrayRealVector(m1.getData()[0]).dotProduct(new ArrayRealVector(m2.getData()[0]));
|
||||
}
|
||||
|
||||
private static double infinityNorm(RealMatrix g) {
|
||||
return new ArrayRealVector(g.getData()[0]).getLInfNorm();
|
||||
}
|
||||
|
||||
private static double squaredNorm(RealMatrix matrix) {
|
||||
double norm = matrix.getFrobeniusNorm();
|
||||
return norm * norm;
|
||||
}
|
||||
|
||||
private static RealMatrix mtrx(int size) {
|
||||
return new Array2DRowRealMatrix(size, 1);
|
||||
}
|
||||
|
||||
private static RealMatrix mtrx(int rsize, int csize) {
|
||||
return new Array2DRowRealMatrix(rsize, csize);
|
||||
}
|
||||
|
||||
public static class SubSystem {
|
||||
|
||||
private final List<Constraint> constraints;
|
||||
|
||||
public SubSystem(List<Constraint> constraints) {
|
||||
this.constraints = constraints;
|
||||
}
|
||||
|
||||
public int pSize() {
|
||||
int s = 0;
|
||||
for (Constraint c : constraints) {
|
||||
s += c.params().length;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public int cSize() {
|
||||
return constraints.size();
|
||||
}
|
||||
|
||||
|
||||
public void fillParams(RealMatrix x) {
|
||||
int i = 0;
|
||||
TDoubleList params = new TDoubleArrayList();
|
||||
for (Constraint c : constraints) {
|
||||
params.add(c.params());
|
||||
}
|
||||
x.setColumn(0, params.toArray());
|
||||
}
|
||||
|
||||
public double calcResidual(RealMatrix r) {
|
||||
double err = 0.;
|
||||
int i = 0;
|
||||
for (Constraint c : constraints) {
|
||||
double v = c.error();
|
||||
r.setEntry(i++, 0, v);
|
||||
err += v * v;
|
||||
}
|
||||
err *= 0.5;
|
||||
return err;
|
||||
}
|
||||
|
||||
public void calcJacobi(RealMatrix jacobi) {
|
||||
// jacobi.setZero(csize, params.size());
|
||||
for (int j=0; j < pSize(); j++) {
|
||||
for (int i=0; i < constraints.size(); i++) {
|
||||
jacobi.setEntry(i, j, 0);
|
||||
}
|
||||
}
|
||||
for (int i=0; i < constraints.size(); i++) {
|
||||
Constraint c = constraints.get(i);
|
||||
double[] grad = new double[c.params().length];
|
||||
c.gradient(grad);
|
||||
for (int j=0; j < grad.length; j++) {
|
||||
jacobi.setEntry(i,j, grad[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setParams(RealMatrix params) {
|
||||
int off = 0;
|
||||
double[] arr = params.getColumn(0);
|
||||
for (Constraint c : constraints) {
|
||||
int l = c.params().length;
|
||||
double[] cp = new double[l];
|
||||
java.lang.System.arraycopy(arr, off, cp, 0, l);
|
||||
c.set(cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/cad/gcs/System.java
Normal file
8
src/cad/gcs/System.java
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package cad.gcs;
|
||||
|
||||
public interface System {
|
||||
|
||||
double[] params();
|
||||
|
||||
void gradient(double[] out);
|
||||
}
|
||||
81
src/cad/gcs/constr/Perpendicular.java
Normal file
81
src/cad/gcs/constr/Perpendicular.java
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
package cad.gcs.constr;
|
||||
|
||||
import cad.gcs.Constraint;
|
||||
import cad.gcs.Param;
|
||||
import cad.math.Vector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Perpendicular implements Constraint {
|
||||
|
||||
public static final int l1p1x = 0;
|
||||
public static final int l1p1y = 1;
|
||||
public static final int l1p2x = 2;
|
||||
public static final int l1p2y = 3;
|
||||
public static final int l2p1x = 4;
|
||||
public static final int l2p1y = 5;
|
||||
public static final int l2p2x = 6;
|
||||
public static final int l2p2y = 7;
|
||||
|
||||
private final double[] params = new double[8];
|
||||
|
||||
public Perpendicular(Vector a1, Vector a2, Vector b1, Vector b2) {
|
||||
params[l1p1x] = a1.x;
|
||||
params[l1p1y] = a1.y;
|
||||
params[l1p2x] = b1.x;
|
||||
params[l1p2y] = b1.y;
|
||||
params[l2p1x] = a2.x;
|
||||
params[l2p1y] = a2.y;
|
||||
params[l2p2x] = b2.x;
|
||||
params[l2p2y] = b2.y;
|
||||
}
|
||||
|
||||
public void out(Vector a1, Vector a2, Vector b1, Vector b2) {
|
||||
a1.x = params[l1p1x];
|
||||
a1.y = params[l1p1y];
|
||||
b1.x = params[l1p2x];
|
||||
b1.y = params[l1p2y];
|
||||
a2.x = params[l2p1x];
|
||||
a2.y = params[l2p1y];
|
||||
b2.x = params[l2p2x];
|
||||
b2.y = params[l2p2y];
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] params() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double error() {
|
||||
double dx1 = (params[l1p1x] - params[l1p2x]);
|
||||
double dy1 = (params[l1p1y] - params[l1p2y]);
|
||||
double dx2 = (params[l2p1x] - params[l2p2x]);
|
||||
double dy2 = (params[l2p1y] - params[l2p2y]);
|
||||
//dot product shows how the lines off to be perpendicular
|
||||
double off = dx1 * dx2 + dy1 * dy2;
|
||||
return off;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gradient(double[] out) {
|
||||
out[l1p1x] = (params[l2p1x] - params[l2p2x]); // = dx2
|
||||
out[l1p2x] = -(params[l2p1x] - params[l2p2x]); // = -dx2
|
||||
out[l1p1y] = (params[l2p1y] - params[l2p2y]); // = dy2
|
||||
out[l1p2y] = -(params[l2p1y] - params[l2p2y]); // = -dy2
|
||||
out[l2p1x] = (params[l1p1x] - params[l1p2x]); // = dx1
|
||||
out[l2p2x] = -(params[l1p1x] - params[l1p2x]); // = -dx1
|
||||
out[l2p1y] = (params[l1p1y] - params[l1p2y]); // = dy1
|
||||
out[l2p2y] = -(params[l1p1y] - params[l1p2y]); // = -dy1
|
||||
|
||||
// for (int i = 0; i < out.length; i++) {
|
||||
// out[i] *= err;
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(double[] input) {
|
||||
System.arraycopy(input, 0, params, 0, params.length);
|
||||
}
|
||||
|
||||
}
|
||||
106
src/cad/math/FullPivLU.java
Normal file
106
src/cad/math/FullPivLU.java
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
package cad.math;
|
||||
|
||||
import org.apache.commons.math3.linear.ArrayRealVector;
|
||||
import org.apache.commons.math3.linear.RealMatrix;
|
||||
|
||||
/**
|
||||
* Created by verastov
|
||||
*/
|
||||
public class FullPivLU {
|
||||
|
||||
|
||||
private boolean m_isInitialized;
|
||||
private RealMatrix m_lu;
|
||||
private ArrayRealVector m_colsTranspositions;
|
||||
private ArrayRealVector m_rowsTranspositions;
|
||||
private int number_of_transpositions;
|
||||
private int m_nonzero_pivots;
|
||||
private double m_maxpivot;
|
||||
|
||||
void compute(RealMatrix matrix)
|
||||
{
|
||||
// the permutations are stored as int indices, so just to be sure:
|
||||
m_isInitialized = true;
|
||||
m_lu = matrix;
|
||||
|
||||
int rows = matrix.getRowDimension();
|
||||
int cols = matrix.getColumnDimension();
|
||||
int size = Math.min(rows, cols);
|
||||
|
||||
// will store the transpositions, before we accumulate them at the end.
|
||||
// can't accumulate on-the-fly because that will be done in reverse order for the rows.
|
||||
|
||||
m_rowsTranspositions = new ArrayRealVector(rows);
|
||||
m_colsTranspositions = new ArrayRealVector(cols);
|
||||
number_of_transpositions = 0; // number of NONTRIVIAL transpositions, i.e. m_rowsTranspositions[i]!=i
|
||||
|
||||
m_nonzero_pivots = size; // the generic case is that in which all pivots are nonzero (invertible case)
|
||||
m_maxpivot = 0;
|
||||
|
||||
for(int k = 0; k < size; ++k)
|
||||
{
|
||||
// First, we need to find the pivot.
|
||||
|
||||
// biggest coefficient in the remaining bottom-right corner (starting at row k, col k)
|
||||
int row_of_biggest_in_corner, col_of_biggest_in_corner;
|
||||
double biggest_in_corner;
|
||||
biggest_in_corner = m_lu.bottomRightCorner(rows-k, cols-k)
|
||||
.cwiseAbs()
|
||||
.maxCoeff(&row_of_biggest_in_corner, &col_of_biggest_in_corner);
|
||||
row_of_biggest_in_corner += k; // correct the values! since they were computed in the corner,
|
||||
col_of_biggest_in_corner += k; // need to add k to them.
|
||||
|
||||
if(biggest_in_corner==RealScalar(0))
|
||||
{
|
||||
// before exiting, make sure to initialize the still uninitialized transpositions
|
||||
// in a sane state without destroying what we already have.
|
||||
m_nonzero_pivots = k;
|
||||
for(Index i = k; i < size; ++i)
|
||||
{
|
||||
m_rowsTranspositions.coeffRef(i) = i;
|
||||
m_colsTranspositions.coeffRef(i) = i;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(biggest_in_corner > m_maxpivot) m_maxpivot = biggest_in_corner;
|
||||
|
||||
// Now that we've found the pivot, we need to apply the row/col swaps to
|
||||
// bring it to the location (k,k).
|
||||
|
||||
m_rowsTranspositions.coeffRef(k) = row_of_biggest_in_corner;
|
||||
m_colsTranspositions.coeffRef(k) = col_of_biggest_in_corner;
|
||||
if(k != row_of_biggest_in_corner) {
|
||||
m_lu.row(k).swap(m_lu.row(row_of_biggest_in_corner));
|
||||
++number_of_transpositions;
|
||||
}
|
||||
if(k != col_of_biggest_in_corner) {
|
||||
m_lu.col(k).swap(m_lu.col(col_of_biggest_in_corner));
|
||||
++number_of_transpositions;
|
||||
}
|
||||
|
||||
// Now that the pivot is at the right location, we update the remaining
|
||||
// bottom-right corner by Gaussian elimination.
|
||||
|
||||
if(k<rows-1)
|
||||
m_lu.col(k).tail(rows-k-1) /= m_lu.coeff(k,k);
|
||||
if(k<size-1)
|
||||
m_lu.block(k+1,k+1,rows-k-1,cols-k-1).noalias() -= m_lu.col(k).tail(rows-k-1) * m_lu.row(k).tail(cols-k-1);
|
||||
}
|
||||
|
||||
// the main loop is over, we still have to accumulate the transpositions to find the
|
||||
// permutations P and Q
|
||||
|
||||
m_p.setIdentity(rows);
|
||||
for(Index k = size-1; k >= 0; --k)
|
||||
m_p.applyTranspositionOnTheRight(k, m_rowsTranspositions.coeff(k));
|
||||
|
||||
m_q.setIdentity(cols);
|
||||
for(Index k = 0; k < size; ++k)
|
||||
m_q.applyTranspositionOnTheRight(k, m_colsTranspositions.coeff(k));
|
||||
|
||||
m_det_pq = (number_of_transpositions%2) ? -1 : 1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -134,4 +134,6 @@ public class Matrix {
|
|||
str += String.format("%.4f, %.4f, %.4f, %.4f" , mzx, mzy, mzz, tz);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
25
web/2d.html
Normal file
25
web/2d.html
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>TCAD</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Monospace;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="lib/dat.gui.min.js"></script>
|
||||
<script src="app/main2d.js"></script>
|
||||
<script src="app/vector.js"></script>
|
||||
<script src="app/viewer2d.js"></script>
|
||||
<script src="app/ctrl2d.js"></script>
|
||||
|
||||
<script>window.onload = function() {window._TCAD_2D_APP = new TCAD.App2D();}</script>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="editor" width="100" height="100" >
|
||||
|
||||
</canvas>
|
||||
</body>
|
||||
</html>
|
||||
166
web/app/bsp.js
Normal file
166
web/app/bsp.js
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
|
||||
TCAD.TWO.BSP = function() {
|
||||
|
||||
this._newNode = function(segment) {
|
||||
return {
|
||||
segments: [segment],
|
||||
left : null,
|
||||
right : null
|
||||
}
|
||||
};
|
||||
this._init = function() {
|
||||
this.root = null;
|
||||
this.removed = 0;
|
||||
this.size = 0;
|
||||
};
|
||||
this._init();
|
||||
};
|
||||
|
||||
TCAD.TWO.BSP.prototype._relationship = function(point, segment) {
|
||||
var a = segment.a;
|
||||
var b = segment.b;
|
||||
|
||||
var x1 = b.x - a.x;
|
||||
var y1 = b.y - a.y;
|
||||
|
||||
var x2 = point.x - a.x;
|
||||
var y2 = point.y - a.y;
|
||||
|
||||
return x1 * y1 + x2 * y2
|
||||
};
|
||||
|
||||
TCAD.TWO.BSP.prototype.search = function(x, y, buffer, deep) {
|
||||
buffer *= 0.5;
|
||||
|
||||
function _test(seg, aim, buffer) {
|
||||
|
||||
var x = aim.x;
|
||||
var y = aim.y;
|
||||
|
||||
if (x < Math.min(seg.a.x, seg.b.x) || x > Math.max(seg.a.x, seg.b.x)) return false;
|
||||
if (y < Math.min(seg.a.y, seg.b.y) || y > Math.max(seg.a.y, seg.b.y)) return false;
|
||||
|
||||
var e = new TCAD.Vector(seg.b.x - seg.a.x, seg.b.y - seg.a.y).normalize();
|
||||
var a = new TCAD.Vector(aim.x - seg.a.x, aim.y - seg.a.y)
|
||||
var b = e.multiply(a.dot(e));
|
||||
var n = a.minus(b);
|
||||
return n.length() <= buffer;
|
||||
}
|
||||
|
||||
function _search(node, aim, pickResult, buffer, deep) {
|
||||
|
||||
if (node == null) return;
|
||||
if (pickResult.length != 0 && !deep) return;
|
||||
|
||||
for (var i = 0; i < node.segments.length; i++) {
|
||||
var seg = node.segments[i];
|
||||
if (!seg.__removed && _test(seg, aim, buffer)) {
|
||||
pickResult.push(seg.data);
|
||||
if (!deep) return;
|
||||
}
|
||||
}
|
||||
_search(node.left, aim, pickResult, buffer, deep);
|
||||
_search(node.right, aim, pickResult, buffer, deep);
|
||||
}
|
||||
|
||||
var pickResult = [];
|
||||
_search(this.root, new TCAD.Vector(x, y), pickResult, buffer, deep);
|
||||
return pickResult;
|
||||
};
|
||||
|
||||
TCAD.TWO.BSP.prototype.remove = function(data) {
|
||||
data.__removed = true;
|
||||
this.removed ++;
|
||||
this.size --;
|
||||
if (this.removed > 0 && this.size > 30 && this.removed == this.size / 2) {
|
||||
this._rebuild();
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.TWO.BSP.prototype._rebuild = function(data) {
|
||||
var root = this.root;
|
||||
this._init();
|
||||
var bsp = this;
|
||||
function populate(node) {
|
||||
if (node != null) {
|
||||
for (var i = 0; i < node.segments.length; i++) {
|
||||
var s = node.segments[i];
|
||||
if (!s.__removed) {
|
||||
bsp.add(s.a, s.b, s.data);
|
||||
}
|
||||
}
|
||||
populate(node.left);
|
||||
populate(node.right);
|
||||
}
|
||||
}
|
||||
populate(root);
|
||||
};
|
||||
|
||||
TCAD.TWO.BSP.prototype.add = function(a, b, data) {
|
||||
data.__removed = false;
|
||||
if (a.x > b.x) {
|
||||
var _a = a;
|
||||
a = b;
|
||||
b = _a;
|
||||
}
|
||||
this._addTo(this, 'root', {a : a, b : b, data: data});
|
||||
this.size ++;
|
||||
};
|
||||
|
||||
TCAD.TWO.BSP.prototype._addTo = function(parent, field, s) {
|
||||
var node = parent[field];
|
||||
if (node == null) {
|
||||
parent[field] = this._newNode(s);
|
||||
} else {
|
||||
this._add(node, s);
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.TWO.BSP.prototype._add = function(node, s) {
|
||||
|
||||
var ns = node.segments[0];
|
||||
var x = TCAD.TWO.utils.lineAtSegment(ns, s);
|
||||
|
||||
if (x == null) {
|
||||
if (this._relationship(s.a, ns) > 0) {
|
||||
this._addTo(node, 'right', s);
|
||||
} else {
|
||||
this._addTo(node, 'left', s);
|
||||
}
|
||||
} else if (x == TCAD.TWO._COINCIDENT) {
|
||||
node.segments.push(s);
|
||||
} else {
|
||||
if (this._relationship(s.a, ns) > 0) {
|
||||
this._addTo(node, 'right', {a : s.a, b : x, data : s.data});
|
||||
this._addTo(node, 'left', {a : x, b : x.b, data : s.data});
|
||||
} else {
|
||||
this._addTo(node, 'left', {a : s.a, b : x, data : s.data});
|
||||
this._addTo(node, 'right', {a : x, b : x.b, data : s.data});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.TWO._COINCIDENT = {x: NaN, y : NaN};
|
||||
|
||||
TCAD.TWO.utils.lineAtSegment = function(line, segement) {
|
||||
|
||||
var x1 = line.a.x;
|
||||
var y1 = line.a.y;
|
||||
var x2 = line.b.x;
|
||||
var y2 = line.b.y;
|
||||
|
||||
var x3 = segement.a.x;
|
||||
var y3 = segement.a.y;
|
||||
var x4 = segement.b.x;
|
||||
var y4 = segement.b.y;
|
||||
|
||||
var d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
|
||||
if (TCAD.utils.equal(d, 0)) return TCAD.TWO._COINCIDENT;
|
||||
|
||||
var xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d;
|
||||
var yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d;
|
||||
|
||||
if (xi < Math.min(x3, x4) || xi > Math.max(x3, x4)) return null;
|
||||
if (yi < Math.min(y3, y4) || yi > Math.max(y3, y4)) return null;
|
||||
return {x : xi, y : yi };
|
||||
};
|
||||
539
web/app/canvas.js
Normal file
539
web/app/canvas.js
Normal file
|
|
@ -0,0 +1,539 @@
|
|||
TCAD = {
|
||||
TWO : {}
|
||||
};
|
||||
|
||||
TCAD.TWO.Styles = {
|
||||
DEFAULT : {
|
||||
lineWidth : "2",
|
||||
strokeStyle : "#ffffff",
|
||||
fillStyle : "#000000"
|
||||
},
|
||||
|
||||
SERVICE : {
|
||||
lineWidth : "0.3",
|
||||
strokeStyle : "#ff0000",
|
||||
fillStyle : "#FF0000"
|
||||
},
|
||||
|
||||
MARK : {
|
||||
lineWidth : "2",
|
||||
strokeStyle : "#ff0000",
|
||||
fillStyle : "#FF0000"
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.TWO.utils = {};
|
||||
|
||||
TCAD.TWO.utils.extend = function(func, parent) {
|
||||
for(var prop in parent.prototype) {
|
||||
if(parent.prototype.hasOwnProperty(prop))
|
||||
func.prototype[prop] = parent.prototype[prop];
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.TWO.utils.point = function(x, y){ return {x: x, y: y} };
|
||||
|
||||
TCAD.TWO.utils.drawPoint = function (ctx, x, y, rad, scale) {
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, rad / scale, 0, 2 * Math.PI, false);
|
||||
ctx.fill();
|
||||
};
|
||||
|
||||
TCAD.TWO.utils.setStyle = function(style, ctx) {
|
||||
ctx.lineWidth = style.lineWidth;
|
||||
ctx.strokeStyle = style.strokeStyle;
|
||||
ctx.fillStyle = style.fillStyle;
|
||||
};
|
||||
|
||||
TCAD.TWO.Viewer = function(canvas) {
|
||||
|
||||
this.canvas = canvas;
|
||||
|
||||
this.canvas.width = window.innerWidth;
|
||||
this.canvas.height = window.innerHeight;
|
||||
|
||||
this.ctx = this.canvas.getContext("2d");
|
||||
this.layers = [];
|
||||
this._serviceLayers = [];
|
||||
this._workspace = [this.layers, this._serviceLayers];
|
||||
this.toolManager = new TCAD.TWO.ToolManager(this, new TCAD.TWO.PanTool(this));
|
||||
this.parametricManager = new TCAD.TWO.ParametricManager(this);
|
||||
|
||||
this.translate = {x : 0.0, y : 0.0};
|
||||
this.scale = 1.0;
|
||||
|
||||
this.bsp = new TCAD.TWO.BSP();
|
||||
this.segments = [];
|
||||
this.selected = [];
|
||||
|
||||
this._setupServiceLayer();
|
||||
this.refresh();
|
||||
};
|
||||
|
||||
TCAD.TWO.Viewer.prototype.addSegment = function(x1, y1, x2, y2, layer) {
|
||||
var a = new TCAD.TWO.EndPoint(x1, y1);
|
||||
var b = new TCAD.TWO.EndPoint(x2, y2);
|
||||
var line = new TCAD.TWO.Segment(a, b);
|
||||
line._marked = false;
|
||||
layer.objects.push(line);
|
||||
this.segments.push(line);
|
||||
this.bsp.add(a, b, line);
|
||||
return line;
|
||||
};
|
||||
|
||||
TCAD.TWO.Viewer.prototype.searchSegment = function(x, y, buffer, deep) {
|
||||
|
||||
buffer *= 0.5;
|
||||
|
||||
var pickResult = [];
|
||||
var aim = new TCAD.Vector(x, y);
|
||||
|
||||
var heroIdx = 0;
|
||||
var heroLength = buffer * 2; // unreachable
|
||||
|
||||
for (var i = 0; i < this.segments.length; i++) {
|
||||
var seg = this.segments[i];
|
||||
var objs = [seg.a, seg.b, seg]
|
||||
for (var j = 0; j < objs.length; j++) {
|
||||
var o = objs[j]
|
||||
l = o.normalDistance(aim);
|
||||
if (l > 0 && l <= buffer) {
|
||||
pickResult.push(o);
|
||||
if (!deep) return;
|
||||
if (l < heroLength) {
|
||||
heroLength = l;
|
||||
heroIdx = pickResult.length - 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pickResult.length > 0) {
|
||||
var _f = pickResult[0];
|
||||
pickResult[0] = pickResult[heroIdx];
|
||||
pickResult[heroIdx] = _f;
|
||||
}
|
||||
return pickResult;
|
||||
};
|
||||
|
||||
TCAD.TWO.Viewer.prototype._setupServiceLayer = function() {
|
||||
var layer = new TCAD.TWO.Layer("_service", TCAD.TWO.Styles.SERVICE);
|
||||
layer.objects.push(new TCAD.TWO.Point(0, 0, 2));
|
||||
this._serviceLayers.push(layer);
|
||||
};
|
||||
|
||||
TCAD.TWO.Viewer.prototype.refresh = function() {
|
||||
var viewer = this;
|
||||
window.requestAnimationFrame( function() {
|
||||
viewer.repaint();
|
||||
});
|
||||
};
|
||||
|
||||
TCAD.TWO.Viewer.prototype.repaint = function() {
|
||||
|
||||
var ctx = this.ctx;
|
||||
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||
|
||||
ctx.fillStyle = "#808080";
|
||||
ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
||||
|
||||
//Order is important!
|
||||
ctx.transform(1, 0, 0, -1, 0, this.canvas.height );
|
||||
ctx.transform(1, 0, 0, 1, this.translate.x , this.translate.y );
|
||||
ctx.transform(this.scale, 0, 0, this.scale, 0, 0);
|
||||
|
||||
var prevStyle = null;
|
||||
var style;
|
||||
for (var w = 0; w < this._workspace.length; w++) {
|
||||
var layers = this._workspace[w];
|
||||
for (var l = 0; l < layers.length; l++) {
|
||||
var layer = layers[l];
|
||||
for (var o = 0; o < layer.objects.length; o++) {
|
||||
var obj = layer.objects[o];
|
||||
style = obj.style != null ? obj.style : layer.style;
|
||||
if (style != prevStyle) TCAD.TWO.utils.setStyle(style, ctx);
|
||||
obj.draw(ctx, this.scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.TWO.Viewer.prototype.screenToModel2 = function(x, y, out) {
|
||||
|
||||
out.x = x;
|
||||
out.y = this.canvas.height - y;
|
||||
|
||||
out.x -= this.translate.x;
|
||||
out.y -= this.translate.y;
|
||||
|
||||
out.x /= this.scale;
|
||||
out.y /= this.scale;
|
||||
};
|
||||
|
||||
TCAD.TWO.Viewer.prototype.screenToModel = function(point) {
|
||||
var out = {x: 0, y: 0}
|
||||
this.screenToModel2(point.x, point.y, out);
|
||||
return out;
|
||||
};
|
||||
|
||||
TCAD.TWO.Viewer.prototype.select = function(objs, exclusive) {
|
||||
if (exclusive) this.deselectAll();
|
||||
for (var i = 0; i < objs.length; i++) {
|
||||
this.mark(objs[i]);
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.TWO.Viewer.prototype.pick = function(e) {
|
||||
var m = this.screenToModel(event);
|
||||
return this.searchSegment(m.x, m.y, 20 / this.scale, true);
|
||||
};
|
||||
|
||||
TCAD.TWO.Viewer.prototype.mark = function(obj) {
|
||||
obj.marked = true;
|
||||
this.selected.push(obj);
|
||||
};
|
||||
|
||||
TCAD.TWO.Viewer.prototype.deselectAll = function() {
|
||||
for (var i = 0; i < this.selected.length; i++) {
|
||||
var obj = this.selected[i];
|
||||
obj.marked = false;
|
||||
}
|
||||
this.selected = [];
|
||||
};
|
||||
|
||||
TCAD.TWO.Layer = function(name, style) {
|
||||
this.name = name;
|
||||
this.style = style;
|
||||
this.objects = [];
|
||||
};
|
||||
|
||||
TCAD.TWO.Polygon = function(points) {
|
||||
this.points = points;
|
||||
this.style = null;
|
||||
};
|
||||
|
||||
TCAD.TWO.Polygon.prototype.draw = function(ctx) {
|
||||
|
||||
if (this.points.length < 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.beginPath();
|
||||
var first = this.points[0];
|
||||
ctx.moveTo(first.x, first.y);
|
||||
for (var i = 1; i < this.points.length; i++) {
|
||||
var p = this.points[i];
|
||||
ctx.lineTo(p.x, p.y);
|
||||
}
|
||||
ctx.closePath();
|
||||
ctx.stroke();
|
||||
};
|
||||
|
||||
TCAD.TWO.Polyline = function(points) {
|
||||
this.points = points;
|
||||
this.style = null;
|
||||
};
|
||||
|
||||
TCAD.TWO.Polyline.prototype.draw = function(ctx) {
|
||||
|
||||
if (this.points.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
var first = this.points[0];
|
||||
ctx.moveTo(first.x, first.y);
|
||||
for (var i = 1; i < this.points.length; i++) {
|
||||
var p = this.points[i];
|
||||
ctx.lineTo(p.x, p.y);
|
||||
}
|
||||
ctx.stroke();
|
||||
};
|
||||
|
||||
TCAD.TWO.utils.ID_COUNTER = 0;
|
||||
|
||||
TCAD.TWO.utils.genID = function() {
|
||||
return TCAD.TWO.utils.ID_COUNTER ++;
|
||||
}
|
||||
|
||||
TCAD.TWO.SketchObject = function() {
|
||||
this.id = TCAD.TWO.utils.genID();
|
||||
this.marked = false;
|
||||
this.linked = [];
|
||||
};
|
||||
|
||||
|
||||
TCAD.TWO.SketchObject.prototype._translate = function(dx, dy, translated) {
|
||||
translated[this.id] = 'x';
|
||||
for (var i = 0; i < this.linked.length; ++i) {
|
||||
if (translated[this.linked[i].id] != 'x') {
|
||||
this.linked[i]._translate(dx, dy, translated);
|
||||
}
|
||||
}
|
||||
this.translateImpl(dx, dy);
|
||||
};
|
||||
|
||||
TCAD.TWO.SketchObject.prototype.translate = function(dx, dy) {
|
||||
this._translate(dx, dy, {});
|
||||
};
|
||||
|
||||
TCAD.TWO.SketchObject.prototype.draw = function(ctx, scale) {
|
||||
if (this.marked) {
|
||||
ctx.save();
|
||||
TCAD.TWO.utils.setStyle(TCAD.TWO.Styles.MARK, ctx);
|
||||
}
|
||||
this.drawImpl(ctx, scale);
|
||||
if (this.marked) ctx.restore();
|
||||
};
|
||||
|
||||
TCAD.TWO.EndPoint = function(x, y) {
|
||||
TCAD.TWO.SketchObject.call(this);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.marked = false;
|
||||
this.parent = null;
|
||||
};
|
||||
|
||||
TCAD.TWO.utils.extend(TCAD.TWO.EndPoint, TCAD.TWO.SketchObject);
|
||||
|
||||
TCAD.TWO.EndPoint.prototype.normalDistance = function(aim) {
|
||||
return aim.minus(new TCAD.Vector(this.x, this.y)).length();
|
||||
}
|
||||
|
||||
TCAD.TWO.EndPoint.prototype.translateImpl = function(dx, dy) {
|
||||
this.x += dx;
|
||||
this.y += dy;
|
||||
};
|
||||
|
||||
TCAD.TWO.EndPoint.prototype.drawImpl = function(ctx, scale) {
|
||||
TCAD.TWO.utils.drawPoint(ctx, this.x, this.y, 3, scale)
|
||||
};
|
||||
|
||||
TCAD.TWO.Segment = function(a, b) {
|
||||
TCAD.TWO.SketchObject.call(this);
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
a.parent = this;
|
||||
b.parent = this;
|
||||
};
|
||||
|
||||
TCAD.TWO.utils.extend(TCAD.TWO.Segment, TCAD.TWO.SketchObject);
|
||||
|
||||
TCAD.TWO.Segment.prototype.normalDistance = function(aim) {
|
||||
var x = aim.x;
|
||||
var y = aim.y;
|
||||
|
||||
if (x < Math.min(this.a.x, this.b.x) || x > Math.max(this.a.x, this.b.x)) return -1;
|
||||
if (y < Math.min(this.a.y, this.b.y) || y > Math.max(this.a.y, this.b.y)) return -1;
|
||||
|
||||
var e = new TCAD.Vector(this.b.x - this.a.x, this.b.y - this.a.y).normalize();
|
||||
var a = new TCAD.Vector(aim.x - this.a.x, aim.y - this.a.y);
|
||||
var b = e.multiply(a.dot(e));
|
||||
var n = a.minus(b);
|
||||
return n.length();
|
||||
}
|
||||
|
||||
TCAD.TWO.Segment.prototype.draw = function(ctx, scale) {
|
||||
TCAD.TWO.SketchObject.prototype.draw.call(this, ctx, scale);
|
||||
this.a.draw(ctx, scale);
|
||||
this.b.draw(ctx, scale);
|
||||
};
|
||||
|
||||
TCAD.TWO.Segment.prototype.translateImpl = function(dx, dy) {
|
||||
this.a.translate(dx, dy);
|
||||
this.b.translate(dx, dy);
|
||||
};
|
||||
|
||||
TCAD.TWO.Segment.prototype.drawImpl = function(ctx, scale) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(this.a.x, this.a.y);
|
||||
ctx.lineTo(this.b.x, this.b.y);
|
||||
ctx.stroke();
|
||||
};
|
||||
|
||||
TCAD.TWO.Point = function(x, y, rad) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.rad = rad;
|
||||
this.style = null;
|
||||
};
|
||||
|
||||
TCAD.TWO.Point.prototype.draw = function(ctx, scale) {
|
||||
TCAD.TWO.utils.drawPoint(ctx, this.x, this.y, this.rad, scale);
|
||||
};
|
||||
|
||||
TCAD.TWO.ToolManager = function(viewer, defaultTool) {
|
||||
this.stack = [defaultTool];
|
||||
var canvas = viewer.canvas;
|
||||
var tm = this;
|
||||
canvas.addEventListener('mousemove', function (e) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
tm.getTool().mousemove(e);
|
||||
}, false);
|
||||
canvas.addEventListener('mousedown', function (e) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
tm.getTool().mousedown(e);
|
||||
}, false);
|
||||
canvas.addEventListener('mouseup', function (e) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
tm.getTool().mouseup(e);
|
||||
}, false);
|
||||
canvas.addEventListener('mousewheel', function (e) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
tm.getTool().mousewheel(e);
|
||||
}, false);
|
||||
};
|
||||
|
||||
TCAD.TWO.ToolManager.prototype.takeControl = function(tool) {
|
||||
this.stack.push(tool);
|
||||
};
|
||||
|
||||
TCAD.TWO.ToolManager.prototype.releaseControl = function() {
|
||||
if (this.stack.length == 1) {
|
||||
return;
|
||||
}
|
||||
this.stack.pop();
|
||||
};
|
||||
|
||||
TCAD.TWO.ToolManager.prototype.getTool = function() {
|
||||
return this.stack[this.stack.length - 1];
|
||||
};
|
||||
|
||||
TCAD.TWO.PanTool = function(viewer) {
|
||||
this.viewer = viewer;
|
||||
this.dragging = false;
|
||||
this.x = 0.0;
|
||||
this.y = 0.0;
|
||||
};
|
||||
|
||||
TCAD.TWO.PanTool.prototype.mousemove = function(e) {
|
||||
if (!this.dragging) {
|
||||
return;
|
||||
}
|
||||
var dx = event.pageX - this.x;
|
||||
var dy = event.pageY - this.y;
|
||||
dy *= -1;
|
||||
|
||||
this.viewer.translate.x += dx;
|
||||
this.viewer.translate.y += dy;
|
||||
|
||||
this.x = event.pageX;
|
||||
this.y = event.pageY;
|
||||
this.deselectOnUp = false;
|
||||
this.viewer.refresh();
|
||||
};
|
||||
|
||||
TCAD.TWO.PanTool.prototype.mousedown = function(e) {
|
||||
|
||||
if (e.button == 0) {
|
||||
var picked = this.viewer.pick(e);
|
||||
if (picked.length > 0) {
|
||||
if (e.ctrlKey) {
|
||||
this.viewer.select([picked[0]], false);
|
||||
this.deselectOnUp = false;
|
||||
} else {
|
||||
this.viewer.select([picked[0]], true);
|
||||
var dragTool = new TCAD.TWO.DragTool(picked[0], this.viewer);
|
||||
dragTool.mousedown(e);
|
||||
this.viewer.toolManager.takeControl(dragTool);
|
||||
}
|
||||
this.viewer.refresh();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.dragging = true;
|
||||
this.deselectOnUp = true;
|
||||
this.x = event.pageX;
|
||||
this.y = event.pageY;
|
||||
};
|
||||
|
||||
TCAD.TWO.PanTool.prototype.mouseup = function(e) {
|
||||
this.dragging = false;
|
||||
if (this.deselectOnUp) {
|
||||
viewer.deselectAll();
|
||||
this.viewer.refresh();
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.TWO.PanTool.prototype.mousewheel = function(e) {
|
||||
|
||||
var delta = 0;
|
||||
|
||||
if ( event.wheelDelta ) { // WebKit / Opera / Explorer 9
|
||||
delta = event.wheelDelta / 40;
|
||||
} else if ( event.detail ) { // Firefox
|
||||
delta = - event.detail / 3;
|
||||
}
|
||||
|
||||
var before = this.viewer.screenToModel(event);
|
||||
|
||||
this.viewer.scale += delta * 0.01;
|
||||
|
||||
var after = this.viewer.screenToModel(event);
|
||||
|
||||
var dx = after.x - before.x;
|
||||
var dy = after.y - before.y;
|
||||
|
||||
this.viewer.translate.x += dx * this.viewer.scale;
|
||||
this.viewer.translate.y += dy * this.viewer.scale;
|
||||
|
||||
this.viewer.refresh();
|
||||
};
|
||||
|
||||
TCAD.TWO.AddSegmentTool = function(viewer, layer) {
|
||||
this.viewer = viewer;
|
||||
this.layer = layer;
|
||||
this.line = null;
|
||||
};
|
||||
|
||||
TCAD.TWO.AddSegmentTool.prototype.mousemove = function(e) {
|
||||
if (this.line != null) {
|
||||
var p = this.viewer.screenToModel(e);
|
||||
this.line.b.x = p.x;
|
||||
this.line.b.y = p.y;
|
||||
this.viewer.refresh();
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.TWO.AddSegmentTool.prototype.mousedown = function(e) {
|
||||
var p = this.viewer.screenToModel(e);
|
||||
this.line = this.viewer.addSegment(p.x, p.y, p.x, p.y, this.layer);
|
||||
this.viewer.refresh();
|
||||
};
|
||||
|
||||
TCAD.TWO.AddSegmentTool.prototype.mouseup = function(e) {
|
||||
this.line = null;
|
||||
};
|
||||
|
||||
TCAD.TWO.AddSegmentTool.prototype.mousewheel = function(e) {
|
||||
};
|
||||
|
||||
|
||||
TCAD.TWO.DragTool = function(obj, viewer) {
|
||||
this.obj = obj;
|
||||
this.viewer = viewer;
|
||||
this._point = {x: 0, y: 0};
|
||||
};
|
||||
|
||||
TCAD.TWO.DragTool.prototype.mousemove = function(e) {
|
||||
var x = this._point.x;
|
||||
var y = this._point.y;
|
||||
this.viewer.screenToModel2(e.x, e.y, this._point);
|
||||
this.obj.translate(this._point.x - x, this._point.y - y);
|
||||
this.viewer.refresh();
|
||||
};
|
||||
|
||||
TCAD.TWO.DragTool.prototype.mousedown = function(e) {
|
||||
this.viewer.screenToModel2(e.x, e.y, this._point);
|
||||
};
|
||||
|
||||
TCAD.TWO.DragTool.prototype.mouseup = function(e) {
|
||||
this.viewer.toolManager.releaseControl();
|
||||
};
|
||||
|
||||
TCAD.TWO.DragTool.prototype.mousewheel = function(e) {
|
||||
};
|
||||
|
|
@ -10,6 +10,7 @@ TCAD.UI = function(viewer) {
|
|||
var actionsF = gui.addFolder('Add Object');
|
||||
var actions = new TCAD.UI.Actions(this);
|
||||
actionsF.add(actions.tools, 'polygon');
|
||||
actionsF.add(actions.tools, 'line');
|
||||
actionsF.add(actions.tools, 'commit');
|
||||
actionsF.open();
|
||||
|
||||
|
|
@ -21,7 +22,11 @@ TCAD.UI.Actions = function(scope) {
|
|||
|
||||
this.tools = {
|
||||
polygon : function() {
|
||||
scope.viewer.toolMgr.tool = new TCAD.PolygonTool(scope.viewer.selectionMgr.selection[0]);
|
||||
scope.viewer.toolMgr.tool = new TCAD.PolygonTool(scope.viewer.selectionMgr.selection[0], scope.viewer);
|
||||
},
|
||||
|
||||
line : function() {
|
||||
scope.viewer.toolMgr.tool = new TCAD.LineTool(scope.viewer.selectionMgr.selection[0]);
|
||||
},
|
||||
|
||||
commit : function() {
|
||||
|
|
|
|||
36
web/app/ctrl2d.js
Normal file
36
web/app/ctrl2d.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
TCAD.UI2D = function(viewer) {
|
||||
this.viewer = viewer;
|
||||
this.dat = new dat.GUI();
|
||||
var gui = this.dat;
|
||||
|
||||
gui.TEXT_CLOSED = 'XXX Controls';
|
||||
gui.TEXT_OPEN = 'Open FFF';
|
||||
|
||||
var actionsF = gui.addFolder('Add Object');
|
||||
var actions = new TCAD.UI2D.Actions(this);
|
||||
actionsF.add(actions.tools, 'polygon');
|
||||
actionsF.add(actions.tools, 'line');
|
||||
actionsF.add(actions.tools, 'commit');
|
||||
actionsF.open();
|
||||
|
||||
// var propsF = gui.addFolder('Properties');
|
||||
// propsF.add(object3DProto.position, 'x');
|
||||
};
|
||||
|
||||
TCAD.UI2D.Actions = function(scope) {
|
||||
|
||||
this.tools = {
|
||||
polygon : function() {
|
||||
scope.viewer.toolMgr.tool = new TCAD.PolygonTool(scope.viewer.selectionMgr.selection[0], scope.viewer);
|
||||
},
|
||||
|
||||
line : function() {
|
||||
scope.viewer.toolMgr.tool = new TCAD.LineTool(scope.viewer.selectionMgr.selection[0]);
|
||||
},
|
||||
|
||||
commit : function() {
|
||||
scope.viewer.toolMgr.commit();
|
||||
}
|
||||
}
|
||||
};
|
||||
337
web/app/engine (xibyte-home's conflicted copy 2014-09-05).js
Normal file
337
web/app/engine (xibyte-home's conflicted copy 2014-09-05).js
Normal file
|
|
@ -0,0 +1,337 @@
|
|||
|
||||
TCAD.utils = {};
|
||||
|
||||
TCAD.utils.createSquare = function(width) {
|
||||
|
||||
width /= 2;
|
||||
|
||||
var shell = [
|
||||
new TCAD.Vector(-width, -width, 0),
|
||||
new TCAD.Vector( width, -width, 0),
|
||||
new TCAD.Vector( width, width, 0),
|
||||
new TCAD.Vector(-width, width, 0)
|
||||
];
|
||||
|
||||
return new TCAD.Polygon(shell);
|
||||
};
|
||||
|
||||
TCAD.utils.createBox = function(width) {
|
||||
var square = TCAD.utils.createSquare(width);
|
||||
return TCAD.geom.extrude(square, square.normal.multiply(width));
|
||||
};
|
||||
|
||||
TCAD.utils.checkPolygon = function(poly) {
|
||||
if (poly.length < 3) {
|
||||
throw new Error('Polygon should contain at least 3 point');
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.utils.createPoint = function(x, y, z, viewer) {
|
||||
var g = new THREE.SphereGeometry(0.4, 12, 12);
|
||||
// var m = new THREE.MeshBasicMaterial({color: 0xffffff});
|
||||
|
||||
var m = new THREE.MeshPhongMaterial({
|
||||
vertexColors: THREE.FaceColors,
|
||||
color: '#FFFFFF',
|
||||
shininess: 0
|
||||
});
|
||||
|
||||
var o = new THREE.Mesh(g, m);
|
||||
o.position.set( x, y, z );
|
||||
return o;
|
||||
|
||||
var materialS = new THREE.ShaderMaterial({
|
||||
// color: 0xff0000,
|
||||
// linewidth: 5
|
||||
vertexShader :
|
||||
'void main() {\n\t' +
|
||||
'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );' +
|
||||
'gl_PointSize =10.0;\n\t' +
|
||||
'\n}',
|
||||
|
||||
fragmentShader :
|
||||
'void main() {\n\t' +
|
||||
"vec2 coord = gl_PointCoord - vec2(0.5); //from [0,1] to [-0.5,0.5]\n" +
|
||||
"if(length(coord) > 0.5) //outside of circle radius?\n" +
|
||||
" discard;\n"+
|
||||
"else\n"+
|
||||
" gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n"
|
||||
+'\n}'
|
||||
});
|
||||
|
||||
var geometry = new THREE.Geometry();
|
||||
geometry.vertices.push(new THREE.Vector3(x, y, z));
|
||||
// geometry.vertices.push(new THREE.Vector3(x+.001, y+.001, z+.001));
|
||||
|
||||
// var line = new THREE.PointCloud(geometry, material);
|
||||
// line.position.x = x;
|
||||
// line.position.y = y;
|
||||
// line.position.z = z;
|
||||
// return line;
|
||||
|
||||
var material = new THREE.SpriteMaterial( { color: 0xffffff, fog: false } );
|
||||
var sprite = new THREE.Sprite( material );
|
||||
sprite.position.set( x, y, z );
|
||||
sprite.scale.set(0.25,0.25,0.25);
|
||||
sprite.updateMatrix();
|
||||
return sprite;
|
||||
};
|
||||
|
||||
TCAD.utils.createLine = function (a, b, color) {
|
||||
var material = new THREE.LineBasicMaterial({
|
||||
color: color,
|
||||
linewidth: 3
|
||||
});
|
||||
var geometry = new THREE.Geometry();
|
||||
geometry.vertices.push(new THREE.Vector3(a.x, a.y, a.z));
|
||||
geometry.vertices.push(new THREE.Vector3(b.x, b.y, b.z));
|
||||
return new THREE.Line(geometry, material);
|
||||
};
|
||||
|
||||
TCAD.utils.createSolid = function(faces) {
|
||||
var geometry = new TCAD.Solid(faces);
|
||||
geometry.dynamic = true; //true by default
|
||||
var material = new THREE.MeshPhongMaterial({
|
||||
vertexColors: THREE.FaceColors,
|
||||
color: '#B0C4DE',
|
||||
shininess: 0
|
||||
});
|
||||
return new THREE.Mesh( geometry, material );
|
||||
};
|
||||
|
||||
TCAD.utils.fixCCW = function(path, normal) {
|
||||
var _2DTransformation = new TCAD.Matrix().setBasis(TCAD.geom.someBasis(path, normal)).invert();
|
||||
var path2D = [];
|
||||
for (var i = 0; i < path.length; ++i) {
|
||||
path2D[i] = _2DTransformation.apply(path[i]);
|
||||
}
|
||||
|
||||
if (!TCAD.geom.isCCW(path2D)) {
|
||||
path = path.slice(0);
|
||||
path.reverse();
|
||||
}
|
||||
return path;
|
||||
};
|
||||
|
||||
TCAD.TOLERANCE = 0.000001;
|
||||
|
||||
TCAD.utils.areEqual = function(v1, v2, tolerance) {
|
||||
return Math.abs(v1 - v2) < tolerance;
|
||||
};
|
||||
|
||||
TCAD.utils.areVectorsEqual = function(v1, v2, tolerance) {
|
||||
return TCAD.utils.areEqual(v1.x, v2.x, tolerance) &&
|
||||
TCAD.utils.areEqual(v1.y, v2.y, tolerance) &&
|
||||
TCAD.utils.areEqual(v1.z, v2.z, tolerance);
|
||||
};
|
||||
|
||||
TCAD.utils.vectorsEqual = function(v1, v2) {
|
||||
return TCAD.utils.areVectorsEqual(v1, v2, TCAD.TOLERANCE);
|
||||
};
|
||||
|
||||
TCAD.utils.equal = function(v1, v2) {
|
||||
return TCAD.utils.areEqual(v1, v2, TCAD.TOLERANCE);
|
||||
};
|
||||
|
||||
|
||||
TCAD.geom = {};
|
||||
|
||||
TCAD.geom.someBasis = function(twoPointsOnPlane, normal) {
|
||||
var a = twoPointsOnPlane[0];
|
||||
var b = twoPointsOnPlane[1];
|
||||
|
||||
var x = b.minus(a).normalize();
|
||||
var y = normal.cross(x).normalize();
|
||||
|
||||
return [x, y, normal];
|
||||
};
|
||||
|
||||
TCAD.geom.normalOfCCWSeq = function(ccwSequence) {
|
||||
var a = ccwSequence[0];
|
||||
var b = ccwSequence[1];
|
||||
var c = ccwSequence[2];
|
||||
|
||||
return b.minus(a).cross(c.minus(a)).normalize();
|
||||
};
|
||||
|
||||
TCAD.geom.normalOfCCWSeqTHREE = function(ccwSequence) {
|
||||
var a = ccwSequence[0];
|
||||
var b = ccwSequence[1].clone();
|
||||
var c = ccwSequence[2].clone();
|
||||
|
||||
return b.sub(a).cross(c.sub(a)).normalize();
|
||||
};
|
||||
|
||||
|
||||
// http://en.wikipedia.org/wiki/Shoelace_formula
|
||||
TCAD.geom.area = function (contour) {
|
||||
var n = contour.length;
|
||||
var a = 0.0;
|
||||
for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
|
||||
a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
|
||||
}
|
||||
return a * 0.5;
|
||||
};
|
||||
|
||||
TCAD.geom.isCCW = function(path2D) {
|
||||
return TCAD.geom.area(path2D) >= 0;
|
||||
};
|
||||
|
||||
TCAD.geom.extrude = function(source, target) {
|
||||
|
||||
var dotProduct = target.normalize().dot(source.normal);
|
||||
if (dotProduct == 0) {
|
||||
return [];
|
||||
}
|
||||
if (dotProduct > 0) {
|
||||
source = source.flip();
|
||||
}
|
||||
|
||||
var poly = [source];
|
||||
|
||||
var lid = source.shift(target).flip();
|
||||
poly.push(lid);
|
||||
var lidShell = lid.shell.slice(0);
|
||||
lidShell.reverse();
|
||||
|
||||
var n = source.shell.length;
|
||||
for ( var p = n - 1, i = 0; i < n; p = i ++ ) {
|
||||
var face = new TCAD.Polygon([
|
||||
source.shell[i],
|
||||
source.shell[p],
|
||||
lidShell[p],
|
||||
lidShell[i]
|
||||
]);
|
||||
poly.push(face);
|
||||
}
|
||||
return poly;
|
||||
};
|
||||
|
||||
|
||||
TCAD.Solid = function(polygons) {
|
||||
|
||||
THREE.Geometry.call( this );
|
||||
|
||||
var scope = this;
|
||||
function pushVertices(vertices) {
|
||||
for ( var v = 0; v < vertices.length; ++ v ) {
|
||||
scope.vertices.push( new THREE.Vector3( vertices[v].x, vertices[v].y, vertices[v].z ) );
|
||||
}
|
||||
}
|
||||
|
||||
var off = 0;
|
||||
for (var p = 0; p < polygons.length; ++ p) {
|
||||
var poly = polygons[p];
|
||||
var faces = poly.triangulate();
|
||||
pushVertices(poly.shell);
|
||||
for ( var h = 0; h < poly.holes; ++ h ) {
|
||||
pushVertices(poly.holes[ h ]);
|
||||
}
|
||||
var polyFace = {faces : [], polygon : poly, sketch : null};
|
||||
|
||||
for ( var i = 0; i < faces.length; ++ i ) {
|
||||
|
||||
var a = faces[i][0] + off;
|
||||
var b = faces[i][1] + off;
|
||||
var c = faces[i][2] + off;
|
||||
|
||||
var fNormal = TCAD.geom.normalOfCCWSeqTHREE([
|
||||
this.vertices[a], this.vertices[b], this.vertices[c]]);
|
||||
|
||||
if (!TCAD.utils.vectorsEqual(fNormal, poly.normal)) {
|
||||
console.log("ASSERT");
|
||||
var _a = a;
|
||||
a = c;
|
||||
c = _a;
|
||||
}
|
||||
|
||||
var face = new THREE.Face3( a, b, c );
|
||||
polyFace.faces.push(face);
|
||||
face.__TCAD_polyFace = polyFace;
|
||||
face.normal = poly.normal.three();
|
||||
face.materialIndex = p;
|
||||
this.faces.push( face );
|
||||
}
|
||||
off = this.vertices.length;
|
||||
}
|
||||
|
||||
this.mergeVertices();
|
||||
};
|
||||
|
||||
TCAD.Solid.prototype = Object.create( THREE.Geometry.prototype );
|
||||
|
||||
/**
|
||||
* Polygon
|
||||
**/
|
||||
TCAD.Polygon = function(shell, holes, normal) {
|
||||
|
||||
if (!holes) {
|
||||
holes = [];
|
||||
}
|
||||
TCAD.utils.checkPolygon(shell);
|
||||
for (var h = 0; h < holes.length; ++h) {
|
||||
TCAD.utils.checkPolygon(holes[h]);
|
||||
}
|
||||
|
||||
if (normal === undefined) {
|
||||
normal = TCAD.geom.normalOfCCWSeq(shell);
|
||||
} else {
|
||||
shell = TCAD.utils.fixCCW(shell, normal);
|
||||
}
|
||||
|
||||
this.normal = normal;
|
||||
this.shell = shell;
|
||||
this.holes = holes;
|
||||
};
|
||||
|
||||
TCAD.Polygon.prototype.reverse = function(triangle) {
|
||||
var first = triangle[0];
|
||||
triangle[0] = triangle[2];
|
||||
triangle[2] = first;
|
||||
};
|
||||
|
||||
TCAD.Polygon.prototype.flip = function() {
|
||||
return new TCAD.Polygon(this.shell, this.holes, this.normal.negate());
|
||||
};
|
||||
|
||||
TCAD.Polygon.prototype.shift = function(target) {
|
||||
var shell = [];
|
||||
var i;
|
||||
for (i = 0; i < this.shell.length; ++i) {
|
||||
shell[i] = this.shell[i].plus(target);
|
||||
}
|
||||
var holes = [];
|
||||
for (var h = 0; h < this.holes.length; ++h) {
|
||||
holes[h] = [];
|
||||
for (i = 0; i < this.holes[h].length; ++i) {
|
||||
holes[h][i] = this.holes[h][i].plus(target);
|
||||
}
|
||||
}
|
||||
return new TCAD.Polygon(shell, holes, this.normal);
|
||||
};
|
||||
|
||||
|
||||
TCAD.Polygon.prototype.triangulate = function() {
|
||||
|
||||
var _3dTransformation = new TCAD.Matrix().setBasis(TCAD.geom.someBasis(this.shell, this.normal));
|
||||
var _2dTransformation = _3dTransformation.invert();
|
||||
|
||||
var i, h;
|
||||
var shell = [];
|
||||
var holes = [];
|
||||
for (i = 0; i < this.shell.length; ++i) {
|
||||
shell[i] = _2dTransformation.apply(this.shell[i]).three();
|
||||
}
|
||||
for (h = 0; h < this.holes.length; ++h) {
|
||||
holes[h] = [];
|
||||
for (i = 0; i < this.holes[h].length; ++i) {
|
||||
holes[h][i] = _2dTransformation.apply(this.holes[h][i]);
|
||||
}
|
||||
}
|
||||
return THREE.Shape.Utils.triangulateShape( shell, holes );
|
||||
};
|
||||
|
||||
|
||||
TCAD.Sketch = function() {
|
||||
this.group = new THREE.Object3D();
|
||||
};
|
||||
|
|
@ -26,10 +26,55 @@ TCAD.utils.checkPolygon = function(poly) {
|
|||
}
|
||||
};
|
||||
|
||||
TCAD.utils.createPoint = function() {
|
||||
var g = new THREE.PlaneGeometry(0.05, 0.05);
|
||||
var m = new THREE.MeshBasicMaterial({color: 0x0000ff, side: THREE.DoubleSide});
|
||||
return new THREE.Mesh(g, m);
|
||||
TCAD.utils.createPoint = function(x, y, z) {
|
||||
// var g = new THREE.PlaneGeometry(0.05, 0.05);
|
||||
// var m = new THREE.MeshBasicMaterial({color: 0x0000ff, side: THREE.DoubleSide});
|
||||
// return new THREE.Mesh(g, m);
|
||||
|
||||
var material = new THREE.ShaderMaterial({
|
||||
// color: 0xff0000,
|
||||
// linewidth: 5
|
||||
vertexShader :
|
||||
'void main() {\n\t' +
|
||||
'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );' +
|
||||
'gl_PointSize =10.0;\n\t' +
|
||||
'\n}',
|
||||
|
||||
fragmentShader :
|
||||
'void main() {\n\t' +
|
||||
"vec2 coord = gl_PointCoord - vec2(0.5); //from [0,1] to [-0.5,0.5]\n" +
|
||||
"if(length(coord) > 0.5) //outside of circle radius?\n" +
|
||||
" discard;\n"+
|
||||
"else\n"+
|
||||
" gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n"
|
||||
+'\n}'
|
||||
});
|
||||
|
||||
var geometry = new THREE.Geometry();
|
||||
geometry.vertices.push(new THREE.Vector3(x, y, z));
|
||||
// geometry.vertices.push(new THREE.Vector3(x+.001, y+.001, z+.001));
|
||||
|
||||
// var line = new THREE.PointCloud(geometry, material);
|
||||
// line.position.x = x;
|
||||
// line.position.y = y;
|
||||
// line.position.z = z;
|
||||
// return line;
|
||||
|
||||
material = new THREE.SpriteMaterial( { color: 0xffffff, fog: false } );
|
||||
var sprite = new THREE.Sprite( material );
|
||||
sprite.position.set( x, y, z );
|
||||
return sprite;
|
||||
};
|
||||
|
||||
TCAD.utils.createLine = function (a, b, color) {
|
||||
var material = new THREE.LineBasicMaterial({
|
||||
color: color,
|
||||
linewidth: 3
|
||||
});
|
||||
var geometry = new THREE.Geometry();
|
||||
geometry.vertices.push(new THREE.Vector3(a.x, a.y, a.z));
|
||||
geometry.vertices.push(new THREE.Vector3(b.x, b.y, b.z));
|
||||
return new THREE.Segment(geometry, material);
|
||||
};
|
||||
|
||||
TCAD.utils.createSolid = function(faces) {
|
||||
|
|
@ -77,6 +122,7 @@ TCAD.utils.equal = function(v1, v2) {
|
|||
return TCAD.utils.areEqual(v1, v2, TCAD.TOLERANCE);
|
||||
};
|
||||
|
||||
|
||||
TCAD.geom = {};
|
||||
|
||||
TCAD.geom.someBasis = function(twoPointsOnPlane, normal) {
|
||||
|
|
@ -271,7 +317,7 @@ TCAD.Polygon.prototype.triangulate = function() {
|
|||
holes[h][i] = _2dTransformation.apply(this.holes[h][i]);
|
||||
}
|
||||
}
|
||||
return THREE.Shape.Utils.triangulateShape( shell, holes );
|
||||
return THREE.Shape.utils.triangulateShape( shell, holes );
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
8
web/app/main2d.js
Normal file
8
web/app/main2d.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
TCAD = {};
|
||||
|
||||
TCAD.App2D = function() {
|
||||
|
||||
this.viewer = new TCAD.Viewer2D(document.getElementById('editor'));
|
||||
this.ui = new TCAD.UI2D(this.viewer);
|
||||
|
||||
};
|
||||
24
web/app/parametric.js
Normal file
24
web/app/parametric.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
TCAD.TWO.Constraints = {};
|
||||
|
||||
TCAD.TWO.ParametricManager = function(viewer) {
|
||||
this.viewer = viewer;
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.coincident = function(objs) {
|
||||
if (objs.length == 0) return;
|
||||
var last = objs.length - 1;
|
||||
for (var i = 0; i < objs.length; ++i) {
|
||||
for (var j = 0; j < objs.length; ++j) {
|
||||
if (objs[i] != objs[j]) {
|
||||
objs[i].linked.push(objs[j]);
|
||||
objs[i].x = objs[last].x;
|
||||
objs[i].y = objs[last].y;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.viewer.refresh();
|
||||
};
|
||||
|
||||
TCAD.TWO.Constraints.Coincident = function() {
|
||||
|
||||
};
|
||||
|
|
@ -73,7 +73,7 @@ TCAD.Viewer = function() {
|
|||
|
||||
controls.keys = [ 65, 83, 68 ];
|
||||
controls.addEventListener( 'change', render );
|
||||
|
||||
this.controls = controls;
|
||||
|
||||
/**
|
||||
* TOOLS
|
||||
|
|
@ -100,32 +100,35 @@ TCAD.Viewer = function() {
|
|||
|
||||
var mouse = new THREE.Vector3( x, y, 1 );
|
||||
var ray = projector.pickingRay(mouse.clone(), camera);
|
||||
var intersects = ray.intersectObjects( scene.children );
|
||||
return ray.intersectObjects( scene.children );
|
||||
};
|
||||
|
||||
var scope = this;
|
||||
function onClick(e) {
|
||||
var intersects = scope.raycast(e);
|
||||
if (intersects.length > 0) {
|
||||
var pickResult = intersects[0];
|
||||
if (pickResult.face.__TCAD_polyFace !== undefined) {
|
||||
var poly = pickResult.face.__TCAD_polyFace;
|
||||
if (this.selectionMgr.contains(poly)) {
|
||||
this.toolMgr.handle(poly, pickResult);
|
||||
if (scope.selectionMgr.contains(poly)) {
|
||||
scope.toolMgr.handleClick(poly, pickResult);
|
||||
} else {
|
||||
this.selectionMgr.select(poly);
|
||||
scope.selectionMgr.select(poly);
|
||||
pickResult.object.geometry.colorsNeedUpdate = true;
|
||||
}
|
||||
}
|
||||
render();
|
||||
}
|
||||
};
|
||||
|
||||
var scope = this;
|
||||
}
|
||||
|
||||
var mouseState = {
|
||||
moved : false
|
||||
};
|
||||
|
||||
function onMove() {
|
||||
function onMove(e) {
|
||||
mouseState.moved = true;
|
||||
}
|
||||
|
||||
renderer.domElement.addEventListener('mousemove', function(e){scope.toolMgr.handleMove(e)}, false);
|
||||
renderer.domElement.addEventListener('mousedown',
|
||||
function() {
|
||||
mouseState.moved = false;
|
||||
|
|
@ -136,7 +139,7 @@ TCAD.Viewer = function() {
|
|||
function(e) {
|
||||
renderer.domElement.removeEventListener('mousemove', onMove);
|
||||
if (!mouseState.moved) {
|
||||
scope.raycast(e);
|
||||
onClick(e);
|
||||
}
|
||||
} , false);
|
||||
|
||||
|
|
@ -178,7 +181,7 @@ TCAD.ToolManager = function(viewer) {
|
|||
this.tool = null;
|
||||
};
|
||||
|
||||
TCAD.ToolManager.prototype.handle = function(face, pickResult) {
|
||||
TCAD.ToolManager.prototype.handleClick = function(face, pickResult) {
|
||||
if (this.tool == null) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -189,7 +192,15 @@ TCAD.ToolManager.prototype.handle = function(face, pickResult) {
|
|||
this.tool.workArea.sketch = new TCAD.Sketch();
|
||||
pickResult.object.parent.add(this.tool.workArea.sketch.group);
|
||||
}
|
||||
this.tool.handle(face, pickResult);
|
||||
this.tool.handleClick(face, pickResult);
|
||||
};
|
||||
|
||||
|
||||
TCAD.ToolManager.prototype.handleMove = function(event) {
|
||||
if (this.tool == null) {
|
||||
return;
|
||||
}
|
||||
this.tool.handleMove(event, this.viewer);
|
||||
};
|
||||
|
||||
TCAD.ToolManager.prototype.commit = function() {
|
||||
|
|
@ -198,22 +209,25 @@ TCAD.ToolManager.prototype.commit = function() {
|
|||
}
|
||||
this.tool.commit();
|
||||
this.viewer.render();
|
||||
this.tool = null;
|
||||
};
|
||||
|
||||
TCAD.PolygonTool = function(workArea) {
|
||||
TCAD.PolygonTool = function(workArea, viewer) {
|
||||
this.workArea = workArea;
|
||||
this.viewer = viewer;
|
||||
this.poly = {shell : [], holes : []};
|
||||
};
|
||||
|
||||
TCAD.PolygonTool.prototype.handle = function(face, pickResult) {
|
||||
TCAD.PolygonTool.prototype.handleClick = function(face, pickResult) {
|
||||
this.poly.shell.push(new TCAD.Vector().setV(pickResult.point));
|
||||
var point = TCAD.utils.createPoint();
|
||||
point.position.x = pickResult.point.x;
|
||||
point.position.y = pickResult.point.y;
|
||||
point.position.z = pickResult.point.z;
|
||||
var point = TCAD.utils.createPoint(pickResult.point.x, pickResult.point.y, pickResult.point.z);
|
||||
this.workArea.sketch.group.add(point);
|
||||
};
|
||||
|
||||
TCAD.PolygonTool.prototype.handleMove = function(event, raycast) {
|
||||
|
||||
};
|
||||
|
||||
TCAD.PolygonTool.prototype.commit = function() {
|
||||
var n = this.workArea.polygon.normal;
|
||||
var _2d = new TCAD.Polygon(this.poly.shell, this.poly.holes, n);
|
||||
|
|
@ -222,3 +236,41 @@ TCAD.PolygonTool.prototype.commit = function() {
|
|||
this.workArea.sketch.group.parent.add(solid);
|
||||
};
|
||||
|
||||
|
||||
TCAD.LineTool = function(workArea) {
|
||||
this.workArea = workArea;
|
||||
this.protoLine = null;
|
||||
};
|
||||
|
||||
TCAD.LineTool.prototype.handleClick = function(face, pickResult) {
|
||||
if (this.protoLine == null) {
|
||||
this.protoLine = TCAD.utils.createLine(pickResult.point, pickResult.point, 0x0000ff);
|
||||
this.workArea.sketch.group.add(this.protoLine);
|
||||
} else {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.LineTool.prototype.handleMove = function(event, viewer) {
|
||||
if (this.protoLine != null) {
|
||||
var intersects = viewer.raycast(event);
|
||||
if (intersects.length > 0 && intersects[0].face.__TCAD_polyFace == this.workArea) {
|
||||
var p = intersects[0].point;
|
||||
var vertices = this.protoLine.geometry.vertices;
|
||||
vertices[vertices.length - 1].x = p.x;
|
||||
vertices[vertices.length - 1].y = p.y;
|
||||
vertices[vertices.length - 1].z = p.z;
|
||||
this.protoLine.geometry.verticesNeedUpdate = true;
|
||||
viewer.render();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TCAD.LineTool.prototype.commit = function() {
|
||||
// var n = this.workArea.polygon.normal;
|
||||
// var _2d = new TCAD.Polygon(this.poly.shell, this.poly.holes, n);
|
||||
//
|
||||
// var solid = TCAD.utils.createSolid(TCAD.geom.extrude(_2d, n.multiply(1.1)));
|
||||
// this.workArea.sketch.group.parent.add(solid);
|
||||
};
|
||||
|
|
|
|||
15
web/app/viewer2d.js
Normal file
15
web/app/viewer2d.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
TCAD.Viewer2D = function(canvas) {
|
||||
|
||||
function updateSize() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
// window.addEventListener( 'resize', updateSize, false );
|
||||
updateSize();
|
||||
|
||||
this.ctx = canvas.getContext("2d");
|
||||
|
||||
this.ctx.fillStyle = "#FF0000"
|
||||
this.ctx.fillRect(400, 500, 100, 100)
|
||||
|
||||
}
|
||||
67
web/canvas.html
Normal file
67
web/canvas.html
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>TCAD</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Monospace;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="lib/three/three.js"></script>
|
||||
<script src="lib/dat.gui.min.js"></script>
|
||||
<script src="app/canvas.js"></script>
|
||||
<script src="app/parametric.js"></script>
|
||||
<script src="app/engine.js"></script>
|
||||
<script src="app/vector.js"></script>
|
||||
<script src="app/bsp.js"></script>
|
||||
|
||||
<script>window.onload = function () {
|
||||
viewer = new TCAD.TWO.Viewer(document.getElementById('viewer'));
|
||||
var layer = new TCAD.TWO.Layer("test", TCAD.TWO.Styles.DEFAULT);
|
||||
viewer.layers.push(layer);
|
||||
var points = [{x: 10, y: 10}, {x: 100, y: 10}, {x: 100, y: 100}];
|
||||
var poly = new TCAD.TWO.Polygon(points);
|
||||
layer.objects.push(poly);
|
||||
|
||||
viewer.addSegment(20, 20, 300, 300, layer);
|
||||
|
||||
viewer.repaint();
|
||||
var bsp = new TCAD.TWO.BSP();
|
||||
bsp.add({x: 3, y:3}, {x: 10, y:10}, "first");
|
||||
|
||||
|
||||
|
||||
this.dat = new dat.GUI();
|
||||
var gui = this.dat;
|
||||
|
||||
var actionsF = gui.addFolder('Add Object');
|
||||
var actions = {
|
||||
addSegment : function () {
|
||||
viewer.toolManager.takeControl(new TCAD.TWO.AddSegmentTool(viewer, layer));
|
||||
},
|
||||
|
||||
pan : function() {
|
||||
viewer.toolManager.releaseControl();
|
||||
},
|
||||
|
||||
coincident : function() {
|
||||
viewer.parametricManager.coincident(viewer.selected);
|
||||
}
|
||||
};
|
||||
actionsF.add(actions, 'addSegment');
|
||||
actionsF.add(actions, 'pan');
|
||||
actionsF.add(actions, 'coincident');
|
||||
actionsF.open();
|
||||
|
||||
|
||||
}</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<canvas width="300" height="300" id="viewer">
|
||||
</canvas>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,25 +1,25 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>TCAD</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Monospace;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
<title>TCAD</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Monospace;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="lib/three/three.js"></script>
|
||||
<script src="lib/three/TrackballControls.js"></script>
|
||||
<script src="lib/three/OrbitControls.js"></script>
|
||||
<script src="lib/dat.gui.min.js"></script>
|
||||
<script src="app/main.js"></script>
|
||||
<script src="app/ctrl.js"></script>
|
||||
<script src="app/viewer.js"></script>
|
||||
<script src="app/engine.js"></script>
|
||||
<script src="app/vector.js"></script>
|
||||
<script src="lib/three/three.js"></script>
|
||||
<script src="lib/three/TrackballControls.js"></script>
|
||||
<script src="lib/three/OrbitControls.js"></script>
|
||||
<script src="lib/dat.gui.min.js"></script>
|
||||
<script src="app/main.js"></script>
|
||||
<script src="app/ctrl.js"></script>
|
||||
<script src="app/viewer.js"></script>
|
||||
<script src="app/engine.js"></script>
|
||||
<script src="app/vector.js"></script>
|
||||
|
||||
<script>window.onload = function() {new TCAD.App();}</script>
|
||||
<script>window.onload = function() {window._TCAD_APP = new TCAD.App();}</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
|
|
|||
|
|
@ -271,7 +271,7 @@ THREE.Projector = function () {
|
|||
|
||||
_renderData.lights.push( object );
|
||||
|
||||
} else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Sprite ) {
|
||||
} else if ( object instanceof THREE.Mesh || object instanceof THREE.Segment || object instanceof THREE.Sprite ) {
|
||||
|
||||
if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
|
||||
|
||||
|
|
@ -545,7 +545,7 @@ THREE.Projector = function () {
|
|||
|
||||
}
|
||||
|
||||
} else if ( object instanceof THREE.Line ) {
|
||||
} else if ( object instanceof THREE.Segment ) {
|
||||
|
||||
if ( geometry instanceof THREE.BufferGeometry ) {
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
Mesh: {},
|
||||
PointCloud: { threshold: 1 },
|
||||
LOD: {},
|
||||
Line: {}
|
||||
Segment: {}
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -180,8 +180,8 @@ THREE.FontUtils = {
|
|||
for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
|
||||
|
||||
var t = i2 / divisions;
|
||||
var tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
|
||||
var ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
|
||||
var tx = THREE.Shape.utils.b2( t, cpx0, cpx1, cpx );
|
||||
var ty = THREE.Shape.utils.b2( t, cpy0, cpy1, cpy );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -211,8 +211,8 @@ THREE.FontUtils = {
|
|||
for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
|
||||
|
||||
var t = i2 / divisions;
|
||||
var tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
|
||||
var ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
|
||||
var tx = THREE.Shape.utils.b3( t, cpx0, cpx1, cpx2, cpx );
|
||||
var ty = THREE.Shape.utils.b3( t, cpy0, cpy1, cpy2, cpy );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ THREE.Curve.prototype.getTangentAt = function ( u ) {
|
|||
* Utils
|
||||
**************************************************************/
|
||||
|
||||
THREE.Curve.Utils = {
|
||||
THREE.Curve.utils = {
|
||||
|
||||
tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
|
||||
|
||||
|
|
|
|||
|
|
@ -269,8 +269,8 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
|
|||
|
||||
t = j / divisions;
|
||||
|
||||
tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
|
||||
ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
|
||||
tx = THREE.Shape.utils.b2( t, cpx0, cpx1, cpx );
|
||||
ty = THREE.Shape.utils.b2( t, cpy0, cpy1, cpy );
|
||||
|
||||
points.push( new THREE.Vector2( tx, ty ) );
|
||||
|
||||
|
|
@ -310,8 +310,8 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
|
|||
|
||||
t = j / divisions;
|
||||
|
||||
tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
|
||||
ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
|
||||
tx = THREE.Shape.utils.b3( t, cpx0, cpx1, cpx2, cpx );
|
||||
ty = THREE.Shape.utils.b3( t, cpy0, cpy1, cpy2, cpy );
|
||||
|
||||
points.push( new THREE.Vector2( tx, ty ) );
|
||||
|
||||
|
|
@ -574,7 +574,7 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
|
|||
|
||||
}
|
||||
|
||||
var holesFirst = ! THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
|
||||
var holesFirst = ! THREE.Shape.utils.isClockWise( subPaths[ 0 ].getPoints() );
|
||||
holesFirst = isCCW ? ! holesFirst : holesFirst;
|
||||
|
||||
// console.log("Holes first", holesFirst);
|
||||
|
|
@ -594,7 +594,7 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
|
|||
|
||||
tmpPath = subPaths[ i ];
|
||||
tmpPoints = tmpPath.getPoints();
|
||||
solid = THREE.Shape.Utils.isClockWise( tmpPoints );
|
||||
solid = THREE.Shape.utils.isClockWise( tmpPoints );
|
||||
solid = isCCW ? ! solid : solid;
|
||||
|
||||
if ( solid ) {
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) {
|
|||
* Utils
|
||||
**************************************************************/
|
||||
|
||||
THREE.Shape.Utils = {
|
||||
THREE.Shape.utils = {
|
||||
|
||||
triangulateShape: function ( contour, holes ) {
|
||||
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ THREE.ClosedSplineCurve3 = THREE.Curve.create(
|
|||
c[ 2 ] = ( intPoint + 1 ) % points.length;
|
||||
c[ 3 ] = ( intPoint + 2 ) % points.length;
|
||||
|
||||
v.x = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].x, points[ c[ 1 ] ].x, points[ c[ 2 ] ].x, points[ c[ 3 ] ].x, weight );
|
||||
v.y = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].y, points[ c[ 1 ] ].y, points[ c[ 2 ] ].y, points[ c[ 3 ] ].y, weight );
|
||||
v.z = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].z, points[ c[ 1 ] ].z, points[ c[ 2 ] ].z, points[ c[ 3 ] ].z, weight );
|
||||
v.x = THREE.Curve.utils.interpolate( points[ c[ 0 ] ].x, points[ c[ 1 ] ].x, points[ c[ 2 ] ].x, points[ c[ 3 ] ].x, weight );
|
||||
v.y = THREE.Curve.utils.interpolate( points[ c[ 0 ] ].y, points[ c[ 1 ] ].y, points[ c[ 2 ] ].y, points[ c[ 3 ] ].y, weight );
|
||||
v.z = THREE.Curve.utils.interpolate( points[ c[ 0 ] ].z, points[ c[ 1 ] ].z, points[ c[ 2 ] ].z, points[ c[ 3 ] ].z, weight );
|
||||
|
||||
return v;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
|
|||
|
||||
var tx, ty;
|
||||
|
||||
tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
|
||||
ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
|
||||
tx = THREE.Shape.utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
|
||||
ty = THREE.Shape.utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
|
||||
|
||||
return new THREE.Vector2( tx, ty );
|
||||
|
||||
|
|
@ -28,8 +28,8 @@ THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
|
|||
|
||||
var tx, ty;
|
||||
|
||||
tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
|
||||
ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
|
||||
tx = THREE.Curve.utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
|
||||
ty = THREE.Curve.utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
|
||||
|
||||
var tangent = new THREE.Vector2( tx, ty );
|
||||
tangent.normalize();
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ THREE.CubicBezierCurve3 = THREE.Curve.create(
|
|||
|
||||
var tx, ty, tz;
|
||||
|
||||
tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
|
||||
ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
|
||||
tz = THREE.Shape.Utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
|
||||
tx = THREE.Shape.utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
|
||||
ty = THREE.Shape.utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
|
||||
tz = THREE.Shape.utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
|
||||
|
||||
return new THREE.Vector3( tx, ty, tz );
|
||||
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
|
|||
|
||||
var tx, ty;
|
||||
|
||||
tx = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
|
||||
ty = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
|
||||
tx = THREE.Shape.utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
|
||||
ty = THREE.Shape.utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
|
||||
|
||||
return new THREE.Vector2( tx, ty );
|
||||
|
||||
|
|
@ -30,8 +30,8 @@ THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
|
|||
|
||||
var tx, ty;
|
||||
|
||||
tx = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
|
||||
ty = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
|
||||
tx = THREE.Curve.utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
|
||||
ty = THREE.Curve.utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
|
||||
|
||||
// returns unit vector
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ THREE.QuadraticBezierCurve3 = THREE.Curve.create(
|
|||
|
||||
var tx, ty, tz;
|
||||
|
||||
tx = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
|
||||
ty = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
|
||||
tz = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
|
||||
tx = THREE.Shape.utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
|
||||
ty = THREE.Shape.utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
|
||||
tz = THREE.Shape.utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
|
||||
|
||||
return new THREE.Vector3( tx, ty, tz );
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ THREE.SplineCurve.prototype.getPoint = function ( t ) {
|
|||
c[ 2 ] = intPoint > points.length - 2 ? points.length -1 : intPoint + 1;
|
||||
c[ 3 ] = intPoint > points.length - 3 ? points.length -1 : intPoint + 2;
|
||||
|
||||
v.x = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].x, points[ c[ 1 ] ].x, points[ c[ 2 ] ].x, points[ c[ 3 ] ].x, weight );
|
||||
v.y = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].y, points[ c[ 1 ] ].y, points[ c[ 2 ] ].y, points[ c[ 3 ] ].y, weight );
|
||||
v.x = THREE.Curve.utils.interpolate( points[ c[ 0 ] ].x, points[ c[ 1 ] ].x, points[ c[ 2 ] ].x, points[ c[ 3 ] ].x, weight );
|
||||
v.y = THREE.Curve.utils.interpolate( points[ c[ 0 ] ].y, points[ c[ 1 ] ].y, points[ c[ 2 ] ].y, points[ c[ 3 ] ].y, weight );
|
||||
|
||||
return v;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ THREE.SplineCurve3 = THREE.Curve.create(
|
|||
pt2 = points[ c[2] ],
|
||||
pt3 = points[ c[3] ];
|
||||
|
||||
v.x = THREE.Curve.Utils.interpolate(pt0.x, pt1.x, pt2.x, pt3.x, weight);
|
||||
v.y = THREE.Curve.Utils.interpolate(pt0.y, pt1.y, pt2.y, pt3.y, weight);
|
||||
v.z = THREE.Curve.Utils.interpolate(pt0.z, pt1.z, pt2.z, pt3.z, weight);
|
||||
v.x = THREE.Curve.utils.interpolate(pt0.x, pt1.x, pt2.x, pt3.x, weight);
|
||||
v.y = THREE.Curve.utils.interpolate(pt0.y, pt1.y, pt2.y, pt3.y, weight);
|
||||
v.z = THREE.Curve.utils.interpolate(pt0.z, pt1.z, pt2.z, pt3.z, weight);
|
||||
|
||||
return v;
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
|
|||
var vertices = shapePoints.shape;
|
||||
var holes = shapePoints.holes;
|
||||
|
||||
var reverse = ! THREE.Shape.Utils.isClockWise( vertices ) ;
|
||||
var reverse = ! THREE.Shape.utils.isClockWise( vertices ) ;
|
||||
|
||||
if ( reverse ) {
|
||||
|
||||
|
|
@ -141,7 +141,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
|
|||
|
||||
ahole = holes[ h ];
|
||||
|
||||
if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
|
||||
if ( THREE.Shape.utils.isClockWise( ahole ) ) {
|
||||
|
||||
holes[ h ] = ahole.reverse();
|
||||
|
||||
|
|
@ -154,7 +154,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
|
|||
}
|
||||
|
||||
|
||||
var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
|
||||
var faces = THREE.Shape.utils.triangulateShape ( vertices, holes );
|
||||
|
||||
/* Vertices */
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
|
|||
var vertices = shapePoints.shape;
|
||||
var holes = shapePoints.holes;
|
||||
|
||||
var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
|
||||
var reverse = ! THREE.Shape.utils.isClockWise( vertices );
|
||||
|
||||
if ( reverse ) {
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
|
|||
|
||||
hole = holes[ i ];
|
||||
|
||||
if ( THREE.Shape.Utils.isClockWise( hole ) ) {
|
||||
if ( THREE.Shape.utils.isClockWise( hole ) ) {
|
||||
|
||||
holes[ i ] = hole.reverse();
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
|
|||
|
||||
}
|
||||
|
||||
var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
|
||||
var faces = THREE.Shape.utils.triangulateShape( vertices, holes );
|
||||
|
||||
// Vertices
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ THREE.ArrowHelper = ( function () {
|
|||
|
||||
this.position.copy( origin );
|
||||
|
||||
this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
|
||||
this.line = new THREE.Segment( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
|
||||
this.line.matrixAutoUpdate = false;
|
||||
this.add( this.line );
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ THREE.AxisHelper = function ( size ) {
|
|||
|
||||
var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
|
||||
|
||||
THREE.Line.call( this, geometry, material, THREE.LinePieces );
|
||||
THREE.Segment.call( this, geometry, material, THREE.LinePieces );
|
||||
|
||||
};
|
||||
|
||||
THREE.AxisHelper.prototype = Object.create( THREE.Line.prototype );
|
||||
THREE.AxisHelper.prototype = Object.create( THREE.Segment.prototype );
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ THREE.BoxHelper = function ( object ) {
|
|||
var geometry = new THREE.BufferGeometry();
|
||||
geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( 72 ), 3 ) );
|
||||
|
||||
THREE.Line.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ), THREE.LinePieces );
|
||||
THREE.Segment.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ), THREE.LinePieces );
|
||||
|
||||
if ( object !== undefined ) {
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ THREE.BoxHelper = function ( object ) {
|
|||
|
||||
};
|
||||
|
||||
THREE.BoxHelper.prototype = Object.create( THREE.Line.prototype );
|
||||
THREE.BoxHelper.prototype = Object.create( THREE.Segment.prototype );
|
||||
|
||||
THREE.BoxHelper.prototype.update = function ( object ) {
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ THREE.CameraHelper = function ( camera ) {
|
|||
|
||||
}
|
||||
|
||||
THREE.Line.call( this, geometry, material, THREE.LinePieces );
|
||||
THREE.Segment.call( this, geometry, material, THREE.LinePieces );
|
||||
|
||||
this.camera = camera;
|
||||
this.matrixWorld = camera.matrixWorld;
|
||||
|
|
@ -103,7 +103,7 @@ THREE.CameraHelper = function ( camera ) {
|
|||
|
||||
};
|
||||
|
||||
THREE.CameraHelper.prototype = Object.create( THREE.Line.prototype );
|
||||
THREE.CameraHelper.prototype = Object.create( THREE.Segment.prototype );
|
||||
|
||||
THREE.CameraHelper.prototype.update = function () {
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ THREE.DirectionalLightHelper = function ( light, size ) {
|
|||
var material = new THREE.LineBasicMaterial( { fog: false } );
|
||||
material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
|
||||
|
||||
this.lightPlane = new THREE.Line( geometry, material );
|
||||
this.lightPlane = new THREE.Segment( geometry, material );
|
||||
this.add( this.lightPlane );
|
||||
|
||||
geometry = new THREE.Geometry();
|
||||
|
|
@ -40,7 +40,7 @@ THREE.DirectionalLightHelper = function ( light, size ) {
|
|||
material = new THREE.LineBasicMaterial( { fog: false } );
|
||||
material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
|
||||
|
||||
this.targetLine = new THREE.Line( geometry, material );
|
||||
this.targetLine = new THREE.Segment( geometry, material );
|
||||
this.add( this.targetLine );
|
||||
|
||||
this.update();
|
||||
|
|
|
|||
|
|
@ -74,11 +74,11 @@ THREE.EdgesHelper = function ( object, hex ) {
|
|||
|
||||
}
|
||||
|
||||
THREE.Line.call( this, geometry, new THREE.LineBasicMaterial( { color: color } ), THREE.LinePieces );
|
||||
THREE.Segment.call( this, geometry, new THREE.LineBasicMaterial( { color: color } ), THREE.LinePieces );
|
||||
|
||||
this.matrixAutoUpdate = false;
|
||||
this.matrixWorld = object.matrixWorld;
|
||||
|
||||
};
|
||||
|
||||
THREE.EdgesHelper.prototype = Object.create( THREE.Line.prototype );
|
||||
THREE.EdgesHelper.prototype = Object.create( THREE.Segment.prototype );
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
|
|||
|
||||
}
|
||||
|
||||
THREE.Line.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ), THREE.LinePieces );
|
||||
THREE.Segment.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ), THREE.LinePieces );
|
||||
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
|
|||
|
||||
};
|
||||
|
||||
THREE.FaceNormalsHelper.prototype = Object.create( THREE.Line.prototype );
|
||||
THREE.FaceNormalsHelper.prototype = Object.create( THREE.Segment.prototype );
|
||||
|
||||
THREE.FaceNormalsHelper.prototype.update = function () {
|
||||
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ THREE.GridHelper = function ( size, step ) {
|
|||
|
||||
}
|
||||
|
||||
THREE.Line.call( this, geometry, material, THREE.LinePieces );
|
||||
THREE.Segment.call( this, geometry, material, THREE.LinePieces );
|
||||
|
||||
};
|
||||
|
||||
THREE.GridHelper.prototype = Object.create( THREE.Line.prototype );
|
||||
THREE.GridHelper.prototype = Object.create( THREE.Segment.prototype );
|
||||
|
||||
THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ THREE.SkeletonHelper = function ( object ) {
|
|||
|
||||
var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
|
||||
|
||||
THREE.Line.call( this, geometry, material, THREE.LinePieces );
|
||||
THREE.Segment.call( this, geometry, material, THREE.LinePieces );
|
||||
|
||||
this.root = object;
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ THREE.SkeletonHelper = function ( object ) {
|
|||
};
|
||||
|
||||
|
||||
THREE.SkeletonHelper.prototype = Object.create( THREE.Line.prototype );
|
||||
THREE.SkeletonHelper.prototype = Object.create( THREE.Segment.prototype );
|
||||
|
||||
THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
|
|||
|
||||
}
|
||||
|
||||
THREE.Line.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ), THREE.LinePieces );
|
||||
THREE.Segment.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ), THREE.LinePieces );
|
||||
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
|
|||
|
||||
};
|
||||
|
||||
THREE.VertexNormalsHelper.prototype = Object.create( THREE.Line.prototype );
|
||||
THREE.VertexNormalsHelper.prototype = Object.create( THREE.Segment.prototype );
|
||||
|
||||
THREE.VertexNormalsHelper.prototype.update = ( function ( object ) {
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ THREE.VertexTangentsHelper = function ( object, size, hex, linewidth ) {
|
|||
|
||||
}
|
||||
|
||||
THREE.Line.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ), THREE.LinePieces );
|
||||
THREE.Segment.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ), THREE.LinePieces );
|
||||
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ THREE.VertexTangentsHelper = function ( object, size, hex, linewidth ) {
|
|||
|
||||
};
|
||||
|
||||
THREE.VertexTangentsHelper.prototype = Object.create( THREE.Line.prototype );
|
||||
THREE.VertexTangentsHelper.prototype = Object.create( THREE.Segment.prototype );
|
||||
|
||||
THREE.VertexTangentsHelper.prototype.update = ( function ( object ) {
|
||||
|
||||
|
|
|
|||
|
|
@ -160,11 +160,11 @@ THREE.WireframeHelper = function ( object, hex ) {
|
|||
|
||||
}
|
||||
|
||||
THREE.Line.call( this, geometry, new THREE.LineBasicMaterial( { color: color } ), THREE.LinePieces );
|
||||
THREE.Segment.call( this, geometry, new THREE.LineBasicMaterial( { color: color } ), THREE.LinePieces );
|
||||
|
||||
this.matrixAutoUpdate = false;
|
||||
this.matrixWorld = object.matrixWorld;
|
||||
|
||||
};
|
||||
|
||||
THREE.WireframeHelper.prototype = Object.create( THREE.Line.prototype );
|
||||
THREE.WireframeHelper.prototype = Object.create( THREE.Segment.prototype );
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
THREE.Line = function ( geometry, material, type ) {
|
||||
THREE.Segment = function ( geometry, material, type ) {
|
||||
|
||||
THREE.Object3D.call( this );
|
||||
|
||||
|
|
@ -16,9 +16,9 @@ THREE.Line = function ( geometry, material, type ) {
|
|||
THREE.LineStrip = 0;
|
||||
THREE.LinePieces = 1;
|
||||
|
||||
THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
|
||||
THREE.Segment.prototype = Object.create( THREE.Object3D.prototype );
|
||||
|
||||
THREE.Line.prototype.raycast = ( function () {
|
||||
THREE.Segment.prototype.raycast = ( function () {
|
||||
|
||||
var inverseMatrix = new THREE.Matrix4();
|
||||
var ray = new THREE.Ray();
|
||||
|
|
@ -87,9 +87,9 @@ THREE.Line.prototype.raycast = ( function () {
|
|||
|
||||
}() );
|
||||
|
||||
THREE.Line.prototype.clone = function ( object ) {
|
||||
THREE.Segment.prototype.clone = function ( object ) {
|
||||
|
||||
if ( object === undefined ) object = new THREE.Line( this.geometry, this.material, this.type );
|
||||
if ( object === undefined ) object = new THREE.Segment( this.geometry, this.material, this.type );
|
||||
|
||||
THREE.Object3D.prototype.clone.call( this, object );
|
||||
|
||||
|
|
|
|||
|
|
@ -2686,7 +2686,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|||
_this.info.render.calls ++;
|
||||
_this.info.render.points += position.array.length / 3;
|
||||
|
||||
} else if ( object instanceof THREE.Line ) {
|
||||
} else if ( object instanceof THREE.Segment ) {
|
||||
|
||||
var mode = ( object.type === THREE.LineStrip ) ? _gl.LINE_STRIP : _gl.LINES;
|
||||
|
||||
|
|
@ -2987,7 +2987,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|||
|
||||
// render lines
|
||||
|
||||
} else if ( object instanceof THREE.Line ) {
|
||||
} else if ( object instanceof THREE.Segment ) {
|
||||
|
||||
var mode = ( object.type === THREE.LineStrip ) ? _gl.LINE_STRIP : _gl.LINES;
|
||||
|
||||
|
|
@ -3724,7 +3724,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|||
|
||||
initGeometryGroups(scene, object, geometry);
|
||||
|
||||
} else if ( object instanceof THREE.Line ) {
|
||||
} else if ( object instanceof THREE.Segment ) {
|
||||
|
||||
if ( ! geometry.__webglVertexBuffer ) {
|
||||
|
||||
|
|
@ -3773,7 +3773,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|||
}
|
||||
}
|
||||
|
||||
} else if ( object instanceof THREE.Line ||
|
||||
} else if ( object instanceof THREE.Segment ||
|
||||
object instanceof THREE.PointCloud ) {
|
||||
|
||||
geometry = object.geometry;
|
||||
|
|
@ -3937,7 +3937,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|||
|
||||
material.attributes && clearCustomAttributes( material );
|
||||
|
||||
} else if ( object instanceof THREE.Line ) {
|
||||
} else if ( object instanceof THREE.Segment ) {
|
||||
|
||||
material = getBufferMaterial( object, geometry );
|
||||
|
||||
|
|
@ -4007,7 +4007,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|||
|
||||
if ( object instanceof THREE.Mesh ||
|
||||
object instanceof THREE.PointCloud ||
|
||||
object instanceof THREE.Line ) {
|
||||
object instanceof THREE.Segment ) {
|
||||
|
||||
removeInstancesWebglObjects( scene.__webglObjects, object );
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
90
web/lib/three/three.min.js
vendored
90
web/lib/three/three.min.js
vendored
|
|
@ -148,7 +148,7 @@ THREE.Clock.prototype={constructor:THREE.Clock,start:function(){this.oldTime=thi
|
|||
a=0.001*(b-this.oldTime);this.oldTime=b;this.elapsedTime+=a}return a}};THREE.EventDispatcher=function(){};
|
||||
THREE.EventDispatcher.prototype={constructor:THREE.EventDispatcher,apply:function(a){a.addEventListener=THREE.EventDispatcher.prototype.addEventListener;a.hasEventListener=THREE.EventDispatcher.prototype.hasEventListener;a.removeEventListener=THREE.EventDispatcher.prototype.removeEventListener;a.dispatchEvent=THREE.EventDispatcher.prototype.dispatchEvent},addEventListener:function(a,b){void 0===this._listeners&&(this._listeners={});var c=this._listeners;void 0===c[a]&&(c[a]=[]);-1===c[a].indexOf(b)&&
|
||||
c[a].push(b)},hasEventListener:function(a,b){if(void 0===this._listeners)return!1;var c=this._listeners;return void 0!==c[a]&&-1!==c[a].indexOf(b)?!0:!1},removeEventListener:function(a,b){if(void 0!==this._listeners){var c=this._listeners[a];if(void 0!==c){var d=c.indexOf(b);-1!==d&&c.splice(d,1)}}},dispatchEvent:function(a){if(void 0!==this._listeners){var b=this._listeners[a.type];if(void 0!==b){a.target=this;for(var c=[],d=b.length,e=0;e<d;e++)c[e]=b[e];for(e=0;e<d;e++)c[e].call(this,a)}}}};
|
||||
(function(a){a.Raycaster=function(b,c,f,g){this.ray=new a.Ray(b,c);this.near=f||0;this.far=g||Infinity;this.params={Sprite:{},Mesh:{},PointCloud:{threshold:1},LOD:{},Line:{}}};var b=function(a,b){return a.distance-b.distance},c=function(a,b,f,g){a.raycast(b,f);if(!0===g){a=a.children;g=0;for(var h=a.length;g<h;g++)c(a[g],b,f,!0)}};a.Raycaster.prototype={constructor:a.Raycaster,precision:1E-4,linePrecision:1,set:function(a,b){this.ray.set(a,b)},intersectObject:function(a,e){var f=[];c(a,this,f,e);
|
||||
(function(a){a.Raycaster=function(b,c,f,g){this.ray=new a.Ray(b,c);this.near=f||0;this.far=g||Infinity;this.params={Sprite:{},Mesh:{},PointCloud:{threshold:1},LOD:{},Segment:{}}};var b=function(a,b){return a.distance-b.distance},c=function(a,b,f,g){a.raycast(b,f);if(!0===g){a=a.children;g=0;for(var h=a.length;g<h;g++)c(a[g],b,f,!0)}};a.Raycaster.prototype={constructor:a.Raycaster,precision:1E-4,linePrecision:1,set:function(a,b){this.ray.set(a,b)},intersectObject:function(a,e){var f=[];c(a,this,f,e);
|
||||
f.sort(b);return f},intersectObjects:function(a,e){for(var f=[],g=0,h=a.length;g<h;g++)c(a[g],this,f,e);f.sort(b);return f}}})(THREE);
|
||||
THREE.Object3D=function(){this.id=THREE.Object3DIdCount++;this.uuid=THREE.Math.generateUUID();this.name="";this.parent=void 0;this.children=[];this.up=THREE.Object3D.DefaultUp.clone();var a=new THREE.Vector3,b=new THREE.Euler,c=new THREE.Quaternion,d=new THREE.Vector3(1,1,1);b.onChange(function(){c.setFromEuler(b,!1)});c.onChange(function(){b.setFromQuaternion(c,void 0,!1)});Object.defineProperties(this,{position:{enumerable:!0,value:a},rotation:{enumerable:!0,value:b},quaternion:{enumerable:!0,value:c},
|
||||
scale:{enumerable:!0,value:d}});this.renderDepth=null;this.rotationAutoUpdate=!0;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixAutoUpdate=!0;this.matrixWorldNeedsUpdate=!1;this.visible=!0;this.receiveShadow=this.castShadow=!1;this.frustumCulled=!0;this.userData={}};THREE.Object3D.DefaultUp=new THREE.Vector3(0,1,0);
|
||||
|
|
@ -170,13 +170,13 @@ a);return b.applyProjection(B)}}();this.pickingRay=function(a,b){a.z=-1;var c=ne
|
|||
b,c){if(!0===a.visible||!0===b.visible||!0===c.visible)return!0;L[0]=a.positionScreen;L[1]=b.positionScreen;L[2]=c.positionScreen;return E.isIntersectionBox(Q.setFromPoints(L))},q=function(a,b,c){return 0>(c.positionScreen.x-a.positionScreen.x)*(b.positionScreen.y-a.positionScreen.y)-(c.positionScreen.y-a.positionScreen.y)*(b.positionScreen.x-a.positionScreen.x)};return{setObject:function(a){f=a;g=f.material;h.getNormalMatrix(f.matrixWorld);d.length=0;e.length=0},projectVertex:k,checkTriangleVisibility:l,
|
||||
checkBackfaceCulling:q,pushVertex:function(b,c,d){n=a();n.position.set(b,c,d);k(n)},pushNormal:function(a,b,c){d.push(a,b,c)},pushUv:function(a,b){e.push(a,b)},pushLine:function(a,b){var d=r[a],e=r[b];u=c();u.id=f.id;u.v1.copy(d);u.v2.copy(e);u.z=(d.positionScreen.z+e.positionScreen.z)/2;u.material=f.material;K.elements.push(u)},pushTriangle:function(a,c,k){var n=r[a],p=r[c],t=r[k];if(!1!==l(n,p,t)&&(g.side===THREE.DoubleSide||!0===q(n,p,t))){s=b();s.id=f.id;s.v1.copy(n);s.v2.copy(p);s.v3.copy(t);
|
||||
s.z=(n.positionScreen.z+p.positionScreen.z+t.positionScreen.z)/3;for(n=0;3>n;n++)p=3*arguments[n],t=s.vertexNormalsModel[n],t.set(d[p],d[p+1],d[p+2]),t.applyMatrix3(h).normalize(),p=2*arguments[n],s.uvs[n].set(e[p],e[p+1]);s.vertexNormalsLength=3;s.material=f.material;K.elements.push(s)}}}};this.projectScene=function(n,t,w,v){I=D=p=0;K.elements.length=0;!0===n.autoUpdate&&n.updateMatrixWorld();void 0===t.parent&&t.updateMatrixWorld();R.copy(t.matrixWorldInverse.getInverse(t.matrixWorld));B.multiplyMatrices(t.projectionMatrix,
|
||||
R);H.setFromMatrix(B);h=0;K.objects.length=0;K.lights.length=0;n.traverseVisible(function(a){if(a instanceof THREE.Light)K.lights.push(a);else if(a instanceof THREE.Mesh||a instanceof THREE.Line||a instanceof THREE.Sprite)if(!1===a.frustumCulled||!0===H.intersectsObject(a)){if(h===l){var b=new THREE.RenderableObject;k.push(b);l++;h++;g=b}else g=k[h++];g.id=a.id;g.object=a;null!==a.renderDepth?g.z=a.renderDepth:(O.setFromMatrixPosition(a.matrixWorld),O.applyProjection(B),g.z=O.z);K.objects.push(g)}});
|
||||
R);H.setFromMatrix(B);h=0;K.objects.length=0;K.lights.length=0;n.traverseVisible(function(a){if(a instanceof THREE.Light)K.lights.push(a);else if(a instanceof THREE.Mesh||a instanceof THREE.Segment||a instanceof THREE.Sprite)if(!1===a.frustumCulled||!0===H.intersectsObject(a)){if(h===l){var b=new THREE.RenderableObject;k.push(b);l++;h++;g=b}else g=k[h++];g.id=a.id;g.object=a;null!==a.renderDepth?g.z=a.renderDepth:(O.setFromMatrixPosition(a.matrixWorld),O.applyProjection(B),g.z=O.z);K.objects.push(g)}});
|
||||
!0===w&&K.objects.sort(e);n=0;for(w=K.objects.length;n<w;n++){var A=K.objects[n].object,x=A.geometry;X.setObject(A);S=A.matrixWorld;q=0;if(A instanceof THREE.Mesh)if(x instanceof THREE.BufferGeometry){var z=x.attributes,A=x.offsets;if(void 0!==z.position){for(var G=z.position.array,x=0,y=G.length;x<y;x+=3)X.pushVertex(G[x],G[x+1],G[x+2]);if(void 0!==z.normal)for(var L=z.normal.array,x=0,y=L.length;x<y;x+=3)X.pushNormal(L[x],L[x+1],L[x+2]);if(void 0!==z.uv)for(L=z.uv.array,x=0,y=L.length;x<y;x+=2)X.pushUv(L[x],
|
||||
L[x+1]);if(void 0!==z.index)if(z=z.index.array,0<A.length)for(n=0;n<A.length;n++)for(y=A[n],G=y.index,x=y.start,y=y.start+y.count;x<y;x+=3)X.pushTriangle(z[x]+G,z[x+1]+G,z[x+2]+G);else for(x=0,y=z.length;x<y;x+=3)X.pushTriangle(z[x],z[x+1],z[x+2]);else for(x=0,y=G.length/3;x<y;x+=3)X.pushTriangle(x,x+1,x+2)}}else{if(x instanceof THREE.Geometry){var Q=x.vertices,y=x.faces,z=x.faceVertexUvs[0];W.getNormalMatrix(S);for(var G=A.material instanceof THREE.MeshFaceMaterial,L=!0===G?A.material:null,E=0,ca=
|
||||
Q.length;E<ca;E++){var la=Q[E];X.pushVertex(la.x,la.y,la.z)}Q=0;for(E=y.length;Q<E;Q++){var ca=y[Q],qa=!0===G?L.materials[ca.materialIndex]:A.material;if(void 0!==qa){var ua=qa.side,la=r[ca.a],ja=r[ca.b],Fa=r[ca.c];if(!0===qa.morphTargets){var va=x.morphTargets,Ka=A.morphTargetInfluences,aa=la.position,ra=ja.position,Da=Fa.position;N.set(0,0,0);ba.set(0,0,0);P.set(0,0,0);for(var Qa=0,cb=va.length;Qa<cb;Qa++){var Ga=Ka[Qa];if(0!==Ga){var xa=va[Qa].vertices;N.x+=(xa[ca.a].x-aa.x)*Ga;N.y+=(xa[ca.a].y-
|
||||
aa.y)*Ga;N.z+=(xa[ca.a].z-aa.z)*Ga;ba.x+=(xa[ca.b].x-ra.x)*Ga;ba.y+=(xa[ca.b].y-ra.y)*Ga;ba.z+=(xa[ca.b].z-ra.z)*Ga;P.x+=(xa[ca.c].x-Da.x)*Ga;P.y+=(xa[ca.c].y-Da.y)*Ga;P.z+=(xa[ca.c].z-Da.z)*Ga}}la.position.add(N);ja.position.add(ba);Fa.position.add(P);X.projectVertex(la);X.projectVertex(ja);X.projectVertex(Fa)}if(!1!==X.checkTriangleVisibility(la,ja,Fa)){va=X.checkBackfaceCulling(la,ja,Fa);if(ua!==THREE.DoubleSide){if(ua===THREE.FrontSide&&!1===va)continue;if(ua===THREE.BackSide&&!0===va)continue}s=
|
||||
b();s.id=A.id;s.v1.copy(la);s.v2.copy(ja);s.v3.copy(Fa);s.normalModel.copy(ca.normal);!1!==va||ua!==THREE.BackSide&&ua!==THREE.DoubleSide||s.normalModel.negate();s.normalModel.applyMatrix3(W).normalize();Ka=ca.vertexNormals;aa=0;for(ra=Math.min(Ka.length,3);aa<ra;aa++)Da=s.vertexNormalsModel[aa],Da.copy(Ka[aa]),!1!==va||ua!==THREE.BackSide&&ua!==THREE.DoubleSide||Da.negate(),Da.applyMatrix3(W).normalize();s.vertexNormalsLength=Ka.length;ua=z[Q];if(void 0!==ua)for(va=0;3>va;va++)s.uvs[va].copy(ua[va]);
|
||||
s.color=ca.color;s.material=qa;s.z=(la.positionScreen.z+ja.positionScreen.z+Fa.positionScreen.z)/3;K.elements.push(s)}}}}}else if(A instanceof THREE.Line)if(x instanceof THREE.BufferGeometry){if(z=x.attributes,void 0!==z.position){G=z.position.array;x=0;for(y=G.length;x<y;x+=3)X.pushVertex(G[x],G[x+1],G[x+2]);if(void 0!==z.index)for(z=z.index.array,x=0,y=z.length;x<y;x+=2)X.pushLine(z[x],z[x+1]);else for(z=A.type===THREE.LinePieces?2:1,x=0,y=G.length/3-1;x<y;x+=z)X.pushLine(x,x+1)}}else{if(x instanceof
|
||||
s.color=ca.color;s.material=qa;s.z=(la.positionScreen.z+ja.positionScreen.z+Fa.positionScreen.z)/3;K.elements.push(s)}}}}}else if(A instanceof THREE.Segment)if(x instanceof THREE.BufferGeometry){if(z=x.attributes,void 0!==z.position){G=z.position.array;x=0;for(y=G.length;x<y;x+=3)X.pushVertex(G[x],G[x+1],G[x+2]);if(void 0!==z.index)for(z=z.index.array,x=0,y=z.length;x<y;x+=2)X.pushLine(z[x],z[x+1]);else for(z=A.type===THREE.LinePieces?2:1,x=0,y=G.length/3-1;x<y;x+=z)X.pushLine(x,x+1)}}else{if(x instanceof
|
||||
THREE.Geometry&&(V.multiplyMatrices(B,S),Q=A.geometry.vertices,0!==Q.length))for(la=a(),la.positionScreen.copy(Q[0]).applyMatrix4(V),z=A.type===THREE.LinePieces?2:1,E=1,ca=Q.length;E<ca;E++)la=a(),la.positionScreen.copy(Q[E]).applyMatrix4(V),0<(E+1)%z||(ja=r[q-2],oa.copy(la.positionScreen),$.copy(ja.positionScreen),!0===f(oa,$)&&(oa.multiplyScalar(1/oa.w),$.multiplyScalar(1/$.w),u=c(),u.id=A.id,u.v1.positionScreen.copy(oa),u.v2.positionScreen.copy($),u.z=Math.max(oa.z,$.z),u.material=A.material,A.material.vertexColors===
|
||||
THREE.VertexColors&&(u.vertexColors[0].copy(A.geometry.colors[E]),u.vertexColors[1].copy(A.geometry.colors[E-1])),K.elements.push(u)))}else A instanceof THREE.Sprite&&(J.set(S.elements[12],S.elements[13],S.elements[14],1),J.applyMatrix4(B),x=1/J.w,J.z*=x,-1<=J.z&&1>=J.z&&(C=d(),C.id=A.id,C.x=J.x*x,C.y=J.y*x,C.z=J.z,C.object=A,C.rotation=A.rotation,C.scale.x=A.scale.x*Math.abs(C.x-(J.x+t.projectionMatrix.elements[0])/(J.w+t.projectionMatrix.elements[12])),C.scale.y=A.scale.y*Math.abs(C.y-(J.y+t.projectionMatrix.elements[5])/
|
||||
(J.w+t.projectionMatrix.elements[13])),C.material=A.material,K.elements.push(C)))}!0===v&&K.elements.sort(e);return K}};THREE.Face3=function(a,b,c,d,e,f){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];this.vertexTangents=[];this.materialIndex=void 0!==f?f:0};
|
||||
|
|
@ -322,9 +322,9 @@ THREE.PointCloud=function(a,b){THREE.Object3D.call(this);this.geometry=void 0!==
|
|||
THREE.PointCloud.prototype.raycast=function(){var a=new THREE.Matrix4,b=new THREE.Ray;return function(c,d){var e=this,f=e.geometry,g=c.params.PointCloud.threshold;a.getInverse(this.matrixWorld);b.copy(c.ray).applyMatrix4(a);if(null===f.boundingBox||!1!==b.isIntersectionBox(f.boundingBox)){var h=g/((this.scale.x+this.scale.y+this.scale.z)/3),k=new THREE.Vector3,g=function(a,f){var g=b.distanceToPoint(a);if(g<h){var k=b.closestPointToPoint(a);k.applyMatrix4(e.matrixWorld);var l=c.ray.origin.distanceTo(k);
|
||||
d.push({distance:l,distanceToRay:g,point:k.clone(),index:f,face:null,object:e})}};if(f instanceof THREE.BufferGeometry){var l=f.attributes,n=l.position.array;if(void 0!==l.index){var l=l.index.array,q=f.offsets;0===q.length&&(q=[{start:0,count:l.length,index:0}]);for(var r=0,t=q.length;r<t;++r)for(var s=q[r].start,p=q[r].index,f=s,s=s+q[r].count;f<s;f++){var v=p+l[f];k.set(n[3*v],n[3*v+1],n[3*v+2]);g(k,v)}}else for(l=n.length/3,f=0;f<l;f++)k.set(n[3*f],n[3*f+1],n[3*f+2]),g(k,f)}else for(k=this.geometry.vertices,
|
||||
f=0;f<k.length;f++)g(k[f],f)}}}();THREE.PointCloud.prototype.clone=function(a){void 0===a&&(a=new THREE.PointCloud(this.geometry,this.material));a.sortParticles=this.sortParticles;THREE.Object3D.prototype.clone.call(this,a);return a};THREE.ParticleSystem=function(a,b){console.warn("THREE.ParticleSystem has been renamed to THREE.PointCloud.");return new THREE.PointCloud(a,b)};
|
||||
THREE.Line=function(a,b,c){THREE.Object3D.call(this);this.geometry=void 0!==a?a:new THREE.Geometry;this.material=void 0!==b?b:new THREE.LineBasicMaterial({color:16777215*Math.random()});this.type=void 0!==c?c:THREE.LineStrip};THREE.LineStrip=0;THREE.LinePieces=1;THREE.Line.prototype=Object.create(THREE.Object3D.prototype);
|
||||
THREE.Line.prototype.raycast=function(){var a=new THREE.Matrix4,b=new THREE.Ray,c=new THREE.Sphere;return function(d,e){var f=d.linePrecision,f=f*f,g=this.geometry;null===g.boundingSphere&&g.computeBoundingSphere();c.copy(g.boundingSphere);c.applyMatrix4(this.matrixWorld);if(!1!==d.ray.isIntersectionSphere(c)&&(a.getInverse(this.matrixWorld),b.copy(d.ray).applyMatrix4(a),g instanceof THREE.Geometry))for(var g=g.vertices,h=g.length,k=new THREE.Vector3,l=new THREE.Vector3,n=this.type===THREE.LineStrip?
|
||||
1:2,q=0;q<h-1;q+=n)if(!(b.distanceSqToSegment(g[q],g[q+1],l,k)>f)){var r=b.origin.distanceTo(l);r<d.near||r>d.far||e.push({distance:r,point:k.clone().applyMatrix4(this.matrixWorld),face:null,faceIndex:null,object:this})}}}();THREE.Line.prototype.clone=function(a){void 0===a&&(a=new THREE.Line(this.geometry,this.material,this.type));THREE.Object3D.prototype.clone.call(this,a);return a};
|
||||
THREE.Segment=function(a,b,c){THREE.Object3D.call(this);this.geometry=void 0!==a?a:new THREE.Geometry;this.material=void 0!==b?b:new THREE.LineBasicMaterial({color:16777215*Math.random()});this.type=void 0!==c?c:THREE.LineStrip};THREE.LineStrip=0;THREE.LinePieces=1;THREE.Segment.prototype=Object.create(THREE.Object3D.prototype);
|
||||
THREE.Segment.prototype.raycast=function(){var a=new THREE.Matrix4,b=new THREE.Ray,c=new THREE.Sphere;return function(d,e){var f=d.linePrecision,f=f*f,g=this.geometry;null===g.boundingSphere&&g.computeBoundingSphere();c.copy(g.boundingSphere);c.applyMatrix4(this.matrixWorld);if(!1!==d.ray.isIntersectionSphere(c)&&(a.getInverse(this.matrixWorld),b.copy(d.ray).applyMatrix4(a),g instanceof THREE.Geometry))for(var g=g.vertices,h=g.length,k=new THREE.Vector3,l=new THREE.Vector3,n=this.type===THREE.LineStrip?
|
||||
1:2,q=0;q<h-1;q+=n)if(!(b.distanceSqToSegment(g[q],g[q+1],l,k)>f)){var r=b.origin.distanceTo(l);r<d.near||r>d.far||e.push({distance:r,point:k.clone().applyMatrix4(this.matrixWorld),face:null,faceIndex:null,object:this})}}}();THREE.Segment.prototype.clone=function(a){void 0===a&&(a=new THREE.Segment(this.geometry,this.material,this.type));THREE.Object3D.prototype.clone.call(this,a);return a};
|
||||
THREE.Mesh=function(a,b){THREE.Object3D.call(this);this.geometry=void 0!==a?a:new THREE.Geometry;this.material=void 0!==b?b:new THREE.MeshBasicMaterial({color:16777215*Math.random()});this.updateMorphTargets()};THREE.Mesh.prototype=Object.create(THREE.Object3D.prototype);
|
||||
THREE.Mesh.prototype.updateMorphTargets=function(){if(void 0!==this.geometry.morphTargets&&0<this.geometry.morphTargets.length){this.morphTargetBase=-1;this.morphTargetForcedOrder=[];this.morphTargetInfluences=[];this.morphTargetDictionary={};for(var a=0,b=this.geometry.morphTargets.length;a<b;a++)this.morphTargetInfluences.push(0),this.morphTargetDictionary[this.geometry.morphTargets[a].name]=a}};
|
||||
THREE.Mesh.prototype.getMorphTargetIndexByName=function(a){if(void 0!==this.morphTargetDictionary[a])return this.morphTargetDictionary[a];console.log("THREE.Mesh.getMorphTargetIndexByName: morph target "+a+" does not exist. Returning 0.");return 0};
|
||||
|
|
@ -469,7 +469,7 @@ ga=F.value[T.a],ha=F.value[T.b],ia=F.value[T.c],F.array[M]=ga[ta[0]],F.array[M+1
|
|||
7]=ia[ta[1]],F.array[M+8]=ia[ta[2]],M+=9;else if("faceVertices"===F.boundTo)for(B=0,N=ka.length;B<N;B++)Ra=F.value[ka[B]],ga=Ra[0],ha=Ra[1],ia=Ra[2],F.array[M]=ga[ta[0]],F.array[M+1]=ga[ta[1]],F.array[M+2]=ga[ta[2]],F.array[M+3]=ha[ta[0]],F.array[M+4]=ha[ta[1]],F.array[M+5]=ha[ta[2]],F.array[M+6]=ia[ta[0]],F.array[M+7]=ia[ta[1]],F.array[M+8]=ia[ta[2]],M+=9}else if(4===F.size)if(void 0===F.boundTo||"vertices"===F.boundTo)for(B=0,N=ka.length;B<N;B++)T=jb[ka[B]],ga=F.value[T.a],ha=F.value[T.b],ia=F.value[T.c],
|
||||
F.array[M]=ga.x,F.array[M+1]=ga.y,F.array[M+2]=ga.z,F.array[M+3]=ga.w,F.array[M+4]=ha.x,F.array[M+5]=ha.y,F.array[M+6]=ha.z,F.array[M+7]=ha.w,F.array[M+8]=ia.x,F.array[M+9]=ia.y,F.array[M+10]=ia.z,F.array[M+11]=ia.w,M+=12;else if("faces"===F.boundTo)for(B=0,N=ka.length;B<N;B++)ia=ha=ga=Ra=F.value[ka[B]],F.array[M]=ga.x,F.array[M+1]=ga.y,F.array[M+2]=ga.z,F.array[M+3]=ga.w,F.array[M+4]=ha.x,F.array[M+5]=ha.y,F.array[M+6]=ha.z,F.array[M+7]=ha.w,F.array[M+8]=ia.x,F.array[M+9]=ia.y,F.array[M+10]=ia.z,
|
||||
F.array[M+11]=ia.w,M+=12;else if("faceVertices"===F.boundTo)for(B=0,N=ka.length;B<N;B++)Ra=F.value[ka[B]],ga=Ra[0],ha=Ra[1],ia=Ra[2],F.array[M]=ga.x,F.array[M+1]=ga.y,F.array[M+2]=ga.z,F.array[M+3]=ga.w,F.array[M+4]=ha.x,F.array[M+5]=ha.y,F.array[M+6]=ha.z,F.array[M+7]=ha.w,F.array[M+8]=ia.x,F.array[M+9]=ia.y,F.array[M+10]=ia.z,F.array[M+11]=ia.w,M+=12;m.bindBuffer(m.ARRAY_BUFFER,F.buffer);m.bufferData(m.ARRAY_BUFFER,F.array,I)}J&&(delete y.__inittedArrays,delete y.__colorArray,delete y.__normalArray,
|
||||
delete y.__tangentArray,delete y.__uvArray,delete y.__uv2Array,delete y.__faceArray,delete y.__vertexArray,delete y.__lineArray,delete y.__skinIndexArray,delete y.__skinWeightArray)}}l.verticesNeedUpdate=!1;l.morphTargetsNeedUpdate=!1;l.elementsNeedUpdate=!1;l.uvsNeedUpdate=!1;l.normalsNeedUpdate=!1;l.colorsNeedUpdate=!1;l.tangentsNeedUpdate=!1;l.buffersNeedUpdate=!1;p.attributes&&C(p)}else if(b instanceof THREE.Line){p=d(b,l);r=p.attributes&&x(p);if(l.verticesNeedUpdate||l.colorsNeedUpdate||l.lineDistancesNeedUpdate||
|
||||
delete y.__tangentArray,delete y.__uvArray,delete y.__uv2Array,delete y.__faceArray,delete y.__vertexArray,delete y.__lineArray,delete y.__skinIndexArray,delete y.__skinWeightArray)}}l.verticesNeedUpdate=!1;l.morphTargetsNeedUpdate=!1;l.elementsNeedUpdate=!1;l.uvsNeedUpdate=!1;l.normalsNeedUpdate=!1;l.colorsNeedUpdate=!1;l.tangentsNeedUpdate=!1;l.buffersNeedUpdate=!1;p.attributes&&C(p)}else if(b instanceof THREE.Segment){p=d(b,l);r=p.attributes&&x(p);if(l.verticesNeedUpdate||l.colorsNeedUpdate||l.lineDistancesNeedUpdate||
|
||||
r){var Xb=m.DYNAMIC_DRAW,Kb,Lb,Mb,Yb,sa,Zb,Nb=l.vertices,Qb=l.colors,Rb=l.lineDistances,ec=Nb.length,fc=Qb.length,gc=Rb.length,$b=l.__vertexArray,ac=l.__colorArray,Tb=l.__lineDistanceArray,hc=l.colorsNeedUpdate,ic=l.lineDistancesNeedUpdate,nc=l.__webglCustomAttributesList,bc,uc,Ia,Fb,Ma,pa;if(l.verticesNeedUpdate){for(Kb=0;Kb<ec;Kb++)Yb=Nb[Kb],sa=3*Kb,$b[sa]=Yb.x,$b[sa+1]=Yb.y,$b[sa+2]=Yb.z;m.bindBuffer(m.ARRAY_BUFFER,l.__webglVertexBuffer);m.bufferData(m.ARRAY_BUFFER,$b,Xb)}if(hc){for(Lb=0;Lb<fc;Lb++)Zb=
|
||||
Qb[Lb],sa=3*Lb,ac[sa]=Zb.r,ac[sa+1]=Zb.g,ac[sa+2]=Zb.b;m.bindBuffer(m.ARRAY_BUFFER,l.__webglColorBuffer);m.bufferData(m.ARRAY_BUFFER,ac,Xb)}if(ic){for(Mb=0;Mb<gc;Mb++)Tb[Mb]=Rb[Mb];m.bindBuffer(m.ARRAY_BUFFER,l.__webglLineDistanceBuffer);m.bufferData(m.ARRAY_BUFFER,Tb,Xb)}if(nc)for(bc=0,uc=nc.length;bc<uc;bc++)if(pa=nc[bc],pa.needsUpdate&&(void 0===pa.boundTo||"vertices"===pa.boundTo)){sa=0;Fb=pa.value.length;if(1===pa.size)for(Ia=0;Ia<Fb;Ia++)pa.array[Ia]=pa.value[Ia];else if(2===pa.size)for(Ia=
|
||||
0;Ia<Fb;Ia++)Ma=pa.value[Ia],pa.array[sa]=Ma.x,pa.array[sa+1]=Ma.y,sa+=2;else if(3===pa.size)if("c"===pa.type)for(Ia=0;Ia<Fb;Ia++)Ma=pa.value[Ia],pa.array[sa]=Ma.r,pa.array[sa+1]=Ma.g,pa.array[sa+2]=Ma.b,sa+=3;else for(Ia=0;Ia<Fb;Ia++)Ma=pa.value[Ia],pa.array[sa]=Ma.x,pa.array[sa+1]=Ma.y,pa.array[sa+2]=Ma.z,sa+=3;else if(4===pa.size)for(Ia=0;Ia<Fb;Ia++)Ma=pa.value[Ia],pa.array[sa]=Ma.x,pa.array[sa+1]=Ma.y,pa.array[sa+2]=Ma.z,pa.array[sa+3]=Ma.w,sa+=4;m.bindBuffer(m.ARRAY_BUFFER,pa.buffer);m.bufferData(m.ARRAY_BUFFER,
|
||||
|
|
@ -484,7 +484,7 @@ a[m];h=g.object;k=g.buffer;N(h,b);if(f)g=f;else{g=g.material;if(!g)continue;e&&G
|
|||
f&&G.setBlending(h.blending,h.blendEquation,h.blendSrc,h.blendDst);G.setDepthTest(h.depthTest);G.setDepthWrite(h.depthWrite);J(h.polygonOffset,h.polygonOffsetFactor,h.polygonOffsetUnits)}G.renderImmediateObject(c,d,e,h,k)}}function u(a){var b=a.object.material;b.transparent?(a.transparent=b,a.opaque=null):(a.opaque=b,a.transparent=null)}function D(a,b,d){var e,f=!1;e=b.material;if(void 0===d.geometryGroups||d.groupsNeedUpdate)delete a.__webglObjects[b.id],d.makeGroups(e instanceof THREE.MeshFaceMaterial,
|
||||
Eb?4294967296:65535),d.groupsNeedUpdate=!1;for(var g=0,h=d.geometryGroupsList.length;g<h;g++){e=d.geometryGroupsList[g];if(e.__webglVertexBuffer)f=!1;else{f=e;f.__webglVertexBuffer=m.createBuffer();f.__webglNormalBuffer=m.createBuffer();f.__webglTangentBuffer=m.createBuffer();f.__webglColorBuffer=m.createBuffer();f.__webglUVBuffer=m.createBuffer();f.__webglUV2Buffer=m.createBuffer();f.__webglSkinIndicesBuffer=m.createBuffer();f.__webglSkinWeightsBuffer=m.createBuffer();f.__webglFaceBuffer=m.createBuffer();
|
||||
f.__webglLineBuffer=m.createBuffer();var k=void 0,l=void 0;if(f.numMorphTargets)for(f.__webglMorphTargetsBuffers=[],k=0,l=f.numMorphTargets;k<l;k++)f.__webglMorphTargetsBuffers.push(m.createBuffer());if(f.numMorphNormals)for(f.__webglMorphNormalsBuffers=[],k=0,l=f.numMorphNormals;k<l;k++)f.__webglMorphNormalsBuffers.push(m.createBuffer());G.info.memory.geometries++;c(e,b);d.verticesNeedUpdate=!0;d.morphTargetsNeedUpdate=!0;d.elementsNeedUpdate=!0;d.uvsNeedUpdate=!0;d.normalsNeedUpdate=!0;d.tangentsNeedUpdate=
|
||||
!0;f=d.colorsNeedUpdate=!0}(f||void 0===b.__webglActive)&&A(a.__webglObjects,e,b)}b.__webglActive=!0}function A(a,b,c){var d=c.id;a[d]=a[d]||[];a[d].push({id:d,buffer:b,object:c,material:null,z:0})}function x(a){for(var b in a.attributes)if(a.attributes[b].needsUpdate)return!0;return!1}function C(a){for(var b in a.attributes)a.attributes[b].needsUpdate=!1}function I(a,b){if(a instanceof THREE.Mesh||a instanceof THREE.PointCloud||a instanceof THREE.Line)delete b.__webglObjects[a.id];else if(a instanceof
|
||||
!0;f=d.colorsNeedUpdate=!0}(f||void 0===b.__webglActive)&&A(a.__webglObjects,e,b)}b.__webglActive=!0}function A(a,b,c){var d=c.id;a[d]=a[d]||[];a[d].push({id:d,buffer:b,object:c,material:null,z:0})}function x(a){for(var b in a.attributes)if(a.attributes[b].needsUpdate)return!0;return!1}function C(a){for(var b in a.attributes)a.attributes[b].needsUpdate=!1}function I(a,b){if(a instanceof THREE.Mesh||a instanceof THREE.PointCloud||a instanceof THREE.Segment)delete b.__webglObjects[a.id];else if(a instanceof
|
||||
THREE.ImmediateRenderObject||a.immediateRenderCallback)for(var c=b.__webglObjectsImmediate,d=c.length-1;0<=d;d--)c[d].object===a&&c.splice(d,1);delete a.__webglActive}function z(a,b,c,d,e){qa=0;d.needsUpdate&&(d.program&&Nb(d),G.initMaterial(d,b,c,e),d.needsUpdate=!1);d.morphTargets&&!e.__webglMorphTargetInfluences&&(e.__webglMorphTargetInfluences=new Float32Array(G.maxMorphTargets));var f=!1,g=!1,h=!1,k=d.program,l=k.uniforms,n=d.__webglShader.uniforms;k.id!==Ya&&(m.useProgram(k.program),Ya=k.id,
|
||||
h=g=f=!0);d.id!==Ca&&(-1===Ca&&(h=!0),Ca=d.id,g=!0);if(f||a!==la)m.uniformMatrix4fv(l.projectionMatrix,!1,a.projectionMatrix.elements),Ea&&m.uniform1f(l.logDepthBufFC,2/(Math.log(a.far+1)/Math.LN2)),a!==la&&(la=a),(d instanceof THREE.ShaderMaterial||d instanceof THREE.MeshPhongMaterial||d.envMap)&&null!==l.cameraPosition&&(ea.setFromMatrixPosition(a.matrixWorld),m.uniform3f(l.cameraPosition,ea.x,ea.y,ea.z)),(d instanceof THREE.MeshPhongMaterial||d instanceof THREE.MeshLambertMaterial||d instanceof
|
||||
THREE.ShaderMaterial||d.skinning)&&null!==l.viewMatrix&&m.uniformMatrix4fv(l.viewMatrix,!1,a.matrixWorldInverse.elements);d.skinning&&(e.bindMatrix&&null!==l.bindMatrix&&m.uniformMatrix4fv(l.bindMatrix,!1,e.bindMatrix.elements),e.bindMatrixInverse&&null!==l.bindMatrixInverse&&m.uniformMatrix4fv(l.bindMatrixInverse,!1,e.bindMatrixInverse.elements),Ob&&e.skeleton&&e.skeleton.useVertexTexture?(null!==l.boneTexture&&(f=K(),m.uniform1i(l.boneTexture,f),G.setTexture(e.skeleton.boneTexture,f)),null!==l.boneTextureWidth&&
|
||||
|
|
@ -540,7 +540,7 @@ e,f,g,h,p,r,q,s,t,u,w=3*a.count;for(u=0;u<w;u+=9)t=a.normalArray,d=t[u],e=t[u+1]
|
|||
m.DYNAMIC_DRAW),l(b.attributes.uv),m.vertexAttribPointer(b.attributes.uv,2,m.FLOAT,!1,0,0));a.hasColors&&c.vertexColors!==THREE.NoColors&&(m.bindBuffer(m.ARRAY_BUFFER,a.__webglColorBuffer),m.bufferData(m.ARRAY_BUFFER,a.colorArray,m.DYNAMIC_DRAW),l(b.attributes.color),m.vertexAttribPointer(b.attributes.color,3,m.FLOAT,!1,0,0));n();m.drawArrays(m.TRIANGLES,0,a.count);a.count=0};this.renderBufferDirect=function(a,b,c,d,e,f){if(!1!==d.visible){var g=z(a,b,c,d,f);a=g.attributes;b=e.attributes;c=!1;g=16777215*
|
||||
e.id+2*g.id+(d.wireframe?1:0);g!==ca&&(ca=g,c=!0);c&&k();if(f instanceof THREE.Mesh)if(g=b.index){var l,n;g.array instanceof Uint32Array?(l=m.UNSIGNED_INT,n=4):(l=m.UNSIGNED_SHORT,n=2);e=e.offsets;if(0===e.length)c&&(h(d,a,b,0),m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,g.buffer)),m.drawElements(m.TRIANGLES,g.array.length,l,0),G.info.render.calls++,G.info.render.vertices+=g.array.length,G.info.render.faces+=g.array.length/3;else{c=!0;for(var p=0,r=e.length;p<r;p++){var q=e[p].index;c&&(h(d,a,b,q),m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,
|
||||
g.buffer));m.drawElements(m.TRIANGLES,e[p].count,l,e[p].start*n);G.info.render.calls++;G.info.render.vertices+=e[p].count;G.info.render.faces+=e[p].count/3}}}else c&&h(d,a,b,0),d=e.attributes.position,m.drawArrays(m.TRIANGLES,0,d.array.length/3),G.info.render.calls++,G.info.render.vertices+=d.array.length/3,G.info.render.faces+=d.array.length/9;else if(f instanceof THREE.PointCloud)c&&h(d,a,b,0),d=b.position,m.drawArrays(m.POINTS,0,d.array.length/3),G.info.render.calls++,G.info.render.points+=d.array.length/
|
||||
3;else if(f instanceof THREE.Line)if(f=f.type===THREE.LineStrip?m.LINE_STRIP:m.LINES,O(d.linewidth),g=b.index)if(g.array instanceof Uint32Array?(l=m.UNSIGNED_INT,n=4):(l=m.UNSIGNED_SHORT,n=2),e=e.offsets,0===e.length)c&&(h(d,a,b,0),m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,g.buffer)),m.drawElements(f,g.array.length,l,0),G.info.render.calls++,G.info.render.vertices+=g.array.length;else for(1<e.length&&(c=!0),p=0,r=e.length;p<r;p++)q=e[p].index,c&&(h(d,a,b,q),m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,g.buffer)),
|
||||
3;else if(f instanceof THREE.Segment)if(f=f.type===THREE.LineStrip?m.LINE_STRIP:m.LINES,O(d.linewidth),g=b.index)if(g.array instanceof Uint32Array?(l=m.UNSIGNED_INT,n=4):(l=m.UNSIGNED_SHORT,n=2),e=e.offsets,0===e.length)c&&(h(d,a,b,0),m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,g.buffer)),m.drawElements(f,g.array.length,l,0),G.info.render.calls++,G.info.render.vertices+=g.array.length;else for(1<e.length&&(c=!0),p=0,r=e.length;p<r;p++)q=e[p].index,c&&(h(d,a,b,q),m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,g.buffer)),
|
||||
m.drawElements(f,e[p].count,l,e[p].start*n),G.info.render.calls++,G.info.render.vertices+=e[p].count;else c&&h(d,a,b,0),d=b.position,m.drawArrays(f,0,d.array.length/3),G.info.render.calls++,G.info.render.points+=d.array.length/3}};this.renderBuffer=function(a,b,c,d,e,f){if(!1!==d.visible){var g,h;c=z(a,b,c,d,f);b=c.attributes;a=!1;c=16777215*e.id+2*c.id+(d.wireframe?1:0);c!==ca&&(ca=c,a=!0);a&&k();if(!d.morphTargets&&0<=b.position)a&&(m.bindBuffer(m.ARRAY_BUFFER,e.__webglVertexBuffer),l(b.position),
|
||||
m.vertexAttribPointer(b.position,3,m.FLOAT,!1,0,0));else if(f.morphTargetBase){c=d.program.attributes;-1!==f.morphTargetBase&&0<=c.position?(m.bindBuffer(m.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[f.morphTargetBase]),l(c.position),m.vertexAttribPointer(c.position,3,m.FLOAT,!1,0,0)):0<=c.position&&(m.bindBuffer(m.ARRAY_BUFFER,e.__webglVertexBuffer),l(c.position),m.vertexAttribPointer(c.position,3,m.FLOAT,!1,0,0));if(f.morphTargetForcedOrder.length){var p=0;h=f.morphTargetForcedOrder;for(g=f.morphTargetInfluences;p<
|
||||
d.numSupportedMorphTargets&&p<h.length;)0<=c["morphTarget"+p]&&(m.bindBuffer(m.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[h[p]]),l(c["morphTarget"+p]),m.vertexAttribPointer(c["morphTarget"+p],3,m.FLOAT,!1,0,0)),0<=c["morphNormal"+p]&&d.morphNormals&&(m.bindBuffer(m.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[h[p]]),l(c["morphNormal"+p]),m.vertexAttribPointer(c["morphNormal"+p],3,m.FLOAT,!1,0,0)),f.__webglMorphTargetInfluences[p]=g[h[p]],p++}else{h=[];g=f.morphTargetInfluences;var r,q=g.length;for(r=
|
||||
|
|
@ -549,15 +549,15 @@ l(c["morphNormal"+p]),m.vertexAttribPointer(c["morphNormal"+p],3,m.FLOAT,!1,0,0)
|
|||
m.vertexAttribPointer(b[c.buffer.belongsToAttribute],c.size,m.FLOAT,!1,0,0));0<=b.color&&(0<f.geometry.colors.length||0<f.geometry.faces.length?(m.bindBuffer(m.ARRAY_BUFFER,e.__webglColorBuffer),l(b.color),m.vertexAttribPointer(b.color,3,m.FLOAT,!1,0,0)):d.defaultAttributeValues&&m.vertexAttrib3fv(b.color,d.defaultAttributeValues.color));0<=b.normal&&(m.bindBuffer(m.ARRAY_BUFFER,e.__webglNormalBuffer),l(b.normal),m.vertexAttribPointer(b.normal,3,m.FLOAT,!1,0,0));0<=b.tangent&&(m.bindBuffer(m.ARRAY_BUFFER,
|
||||
e.__webglTangentBuffer),l(b.tangent),m.vertexAttribPointer(b.tangent,4,m.FLOAT,!1,0,0));0<=b.uv&&(f.geometry.faceVertexUvs[0]?(m.bindBuffer(m.ARRAY_BUFFER,e.__webglUVBuffer),l(b.uv),m.vertexAttribPointer(b.uv,2,m.FLOAT,!1,0,0)):d.defaultAttributeValues&&m.vertexAttrib2fv(b.uv,d.defaultAttributeValues.uv));0<=b.uv2&&(f.geometry.faceVertexUvs[1]?(m.bindBuffer(m.ARRAY_BUFFER,e.__webglUV2Buffer),l(b.uv2),m.vertexAttribPointer(b.uv2,2,m.FLOAT,!1,0,0)):d.defaultAttributeValues&&m.vertexAttrib2fv(b.uv2,
|
||||
d.defaultAttributeValues.uv2));d.skinning&&0<=b.skinIndex&&0<=b.skinWeight&&(m.bindBuffer(m.ARRAY_BUFFER,e.__webglSkinIndicesBuffer),l(b.skinIndex),m.vertexAttribPointer(b.skinIndex,4,m.FLOAT,!1,0,0),m.bindBuffer(m.ARRAY_BUFFER,e.__webglSkinWeightsBuffer),l(b.skinWeight),m.vertexAttribPointer(b.skinWeight,4,m.FLOAT,!1,0,0));0<=b.lineDistance&&(m.bindBuffer(m.ARRAY_BUFFER,e.__webglLineDistanceBuffer),l(b.lineDistance),m.vertexAttribPointer(b.lineDistance,1,m.FLOAT,!1,0,0))}n();f instanceof THREE.Mesh?
|
||||
(f=e.__typeArray===Uint32Array?m.UNSIGNED_INT:m.UNSIGNED_SHORT,d.wireframe?(O(d.wireframeLinewidth),a&&m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,e.__webglLineBuffer),m.drawElements(m.LINES,e.__webglLineCount,f,0)):(a&&m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,e.__webglFaceBuffer),m.drawElements(m.TRIANGLES,e.__webglFaceCount,f,0)),G.info.render.calls++,G.info.render.vertices+=e.__webglFaceCount,G.info.render.faces+=e.__webglFaceCount/3):f instanceof THREE.Line?(f=f.type===THREE.LineStrip?m.LINE_STRIP:m.LINES,
|
||||
(f=e.__typeArray===Uint32Array?m.UNSIGNED_INT:m.UNSIGNED_SHORT,d.wireframe?(O(d.wireframeLinewidth),a&&m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,e.__webglLineBuffer),m.drawElements(m.LINES,e.__webglLineCount,f,0)):(a&&m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,e.__webglFaceBuffer),m.drawElements(m.TRIANGLES,e.__webglFaceCount,f,0)),G.info.render.calls++,G.info.render.vertices+=e.__webglFaceCount,G.info.render.faces+=e.__webglFaceCount/3):f instanceof THREE.Segment?(f=f.type===THREE.LineStrip?m.LINE_STRIP:m.LINES,
|
||||
O(d.linewidth),m.drawArrays(f,0,e.__webglLineCount),G.info.render.calls++):f instanceof THREE.PointCloud&&(m.drawArrays(m.POINTS,0,e.__webglParticleCount),G.info.render.calls++,G.info.render.points+=e.__webglParticleCount)}};this.render=function(a,b,c,d){function e(a){a instanceof THREE.SkinnedMesh&&a.skeleton.update();for(var b=0,c=a.children.length;b<c;b++)e(a.children[b])}if(!1===b instanceof THREE.Camera)console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");else{var f,
|
||||
g,h,k,m=a.__lights,l=a.fog;Ca=-1;la=null;fb=!0;!0===a.autoUpdate&&a.updateMatrixWorld();void 0===b.parent&&b.updateMatrixWorld();e(a);b.matrixWorldInverse.getInverse(b.matrixWorld);Ub.multiplyMatrices(b.projectionMatrix,b.matrixWorldInverse);jc.setFromMatrix(Ub);fc(a);Oa.length=0;Pa.length=0;s(a,a,b);!0===G.sortObjects&&(Oa.sort(q),Pa.sort(r));p(this.renderPluginsPre,a,b);G.info.render.calls=0;G.info.render.vertices=0;G.info.render.faces=0;G.info.render.points=0;this.setRenderTarget(c);(this.autoClear||
|
||||
d)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil);k=a.__webglObjectsImmediate;d=0;for(f=k.length;d<f;d++)g=k[d],h=g.object,h.visible&&(N(h,b),u(g));a.overrideMaterial?(d=a.overrideMaterial,this.setBlending(d.blending,d.blendEquation,d.blendSrc,d.blendDst),this.setDepthTest(d.depthTest),this.setDepthWrite(d.depthWrite),J(d.polygonOffset,d.polygonOffsetFactor,d.polygonOffsetUnits),v(Oa,b,m,l,!0,d),v(Pa,b,m,l,!0,d),w(a.__webglObjectsImmediate,"",b,m,l,!1,d)):(d=null,this.setBlending(THREE.NoBlending),
|
||||
v(Oa,b,m,l,!1,d),w(a.__webglObjectsImmediate,"opaque",b,m,l,!1,d),v(Pa,b,m,l,!0,d),w(a.__webglObjectsImmediate,"transparent",b,m,l,!0,d));p(this.renderPluginsPost,a,b);c&&c.generateMipmaps&&c.minFilter!==THREE.NearestFilter&&c.minFilter!==THREE.LinearFilter&&L(c);this.setDepthTest(!0);this.setDepthWrite(!0)}};this.renderImmediateObject=function(a,b,c,d,e){var f=z(a,b,c,d,e);ca=-1;G.setMaterialFaces(d);e.immediateRenderCallback?e.immediateRenderCallback(f,m,jc):e.render(function(a){G.renderBufferImmediate(a,
|
||||
f,d)})};var fc=function(a){a.__webglObjects||(a.__webglObjects={},a.__webglObjectsImmediate=[]);for(;a.__objectsAdded.length;){var c=a.__objectsAdded[0],d=a,e=void 0,f=void 0;void 0===c.__webglInit&&(c.__webglInit=!0,c._modelViewMatrix=new THREE.Matrix4,c._normalMatrix=new THREE.Matrix3);e=c.geometry;if(void 0!==e&&void 0===e.__webglInit)if(e.__webglInit=!0,e.addEventListener("dispose",gc),e instanceof THREE.BufferGeometry)g(e);else if(c instanceof THREE.Mesh)void 0!==c.__webglActive&&I(c,d),D(d,
|
||||
c,e);else if(c instanceof THREE.Line){if(!e.__webglVertexBuffer){f=e;f.__webglVertexBuffer=m.createBuffer();f.__webglColorBuffer=m.createBuffer();f.__webglLineDistanceBuffer=m.createBuffer();G.info.memory.geometries++;var f=e,h=c,k=f.vertices.length;f.__vertexArray=new Float32Array(3*k);f.__colorArray=new Float32Array(3*k);f.__lineDistanceArray=new Float32Array(1*k);f.__webglLineCount=k;b(f,h);e.verticesNeedUpdate=!0;e.colorsNeedUpdate=!0;e.lineDistancesNeedUpdate=!0}}else c instanceof THREE.PointCloud&&
|
||||
c,e);else if(c instanceof THREE.Segment){if(!e.__webglVertexBuffer){f=e;f.__webglVertexBuffer=m.createBuffer();f.__webglColorBuffer=m.createBuffer();f.__webglLineDistanceBuffer=m.createBuffer();G.info.memory.geometries++;var f=e,h=c,k=f.vertices.length;f.__vertexArray=new Float32Array(3*k);f.__colorArray=new Float32Array(3*k);f.__lineDistanceArray=new Float32Array(1*k);f.__webglLineCount=k;b(f,h);e.verticesNeedUpdate=!0;e.colorsNeedUpdate=!0;e.lineDistancesNeedUpdate=!0}}else c instanceof THREE.PointCloud&&
|
||||
!e.__webglVertexBuffer&&(f=e,f.__webglVertexBuffer=m.createBuffer(),f.__webglColorBuffer=m.createBuffer(),G.info.memory.geometries++,f=e,h=c,k=f.vertices.length,f.__vertexArray=new Float32Array(3*k),f.__colorArray=new Float32Array(3*k),f.__sortArray=[],f.__webglParticleCount=k,b(f,h),e.verticesNeedUpdate=!0,e.colorsNeedUpdate=!0);if(void 0===c.__webglActive){if(c instanceof THREE.Mesh)if(e=c.geometry,e instanceof THREE.BufferGeometry)A(d.__webglObjects,e,c);else{if(e instanceof THREE.Geometry)for(h=
|
||||
0,k=e.geometryGroupsList.length;h<k;h++)f=e.geometryGroupsList[h],A(d.__webglObjects,f,c)}else c instanceof THREE.Line||c instanceof THREE.PointCloud?(e=c.geometry,A(d.__webglObjects,e,c)):(c instanceof THREE.ImmediateRenderObject||c.immediateRenderCallback)&&d.__webglObjectsImmediate.push({id:null,object:c,opaque:null,transparent:null,z:0});c.__webglActive=!0}a.__objectsAdded.splice(0,1)}for(;a.__objectsRemoved.length;)I(a.__objectsRemoved[0],a),a.__objectsRemoved.splice(0,1)};this.initMaterial=
|
||||
0,k=e.geometryGroupsList.length;h<k;h++)f=e.geometryGroupsList[h],A(d.__webglObjects,f,c)}else c instanceof THREE.Segment||c instanceof THREE.PointCloud?(e=c.geometry,A(d.__webglObjects,e,c)):(c instanceof THREE.ImmediateRenderObject||c.immediateRenderCallback)&&d.__webglObjectsImmediate.push({id:null,object:c,opaque:null,transparent:null,z:0});c.__webglActive=!0}a.__objectsAdded.splice(0,1)}for(;a.__objectsRemoved.length;)I(a.__objectsRemoved[0],a),a.__objectsRemoved.splice(0,1)};this.initMaterial=
|
||||
function(a,b,c,d){var e,f,g,h;a.addEventListener("dispose",ic);var k,l,n,p;a instanceof THREE.MeshDepthMaterial?p="depth":a instanceof THREE.MeshNormalMaterial?p="normal":a instanceof THREE.MeshBasicMaterial?p="basic":a instanceof THREE.MeshLambertMaterial?p="lambert":a instanceof THREE.MeshPhongMaterial?p="phong":a instanceof THREE.LineBasicMaterial?p="basic":a instanceof THREE.LineDashedMaterial?p="dashed":a instanceof THREE.PointCloudMaterial&&(p="particle_basic");p?(e=THREE.ShaderLib[p],a.__webglShader=
|
||||
{uniforms:THREE.UniformsUtils.clone(e.uniforms),vertexShader:e.vertexShader,fragmentShader:e.fragmentShader}):a.__webglShader={uniforms:a.uniforms,vertexShader:a.vertexShader,fragmentShader:a.fragmentShader};n=h=g=f=e=0;for(var r=b.length;n<r;n++){var q=b[n];q.onlyShadow||!1===q.visible||(q instanceof THREE.DirectionalLight&&e++,q instanceof THREE.PointLight&&f++,q instanceof THREE.SpotLight&&g++,q instanceof THREE.HemisphereLight&&h++)}r=n=0;for(q=b.length;r<q;r++){var s=b[r];s.castShadow&&(s instanceof
|
||||
THREE.SpotLight&&n++,s instanceof THREE.DirectionalLight&&!s.shadowCascade&&n++)}b=n;Ob&&d&&d.skeleton&&d.skeleton.useVertexTexture?n=1024:(n=m.getParameter(m.MAX_VERTEX_UNIFORM_VECTORS),n=Math.floor((n-20)/4),void 0!==d&&d instanceof THREE.SkinnedMesh&&(n=Math.min(d.skeleton.bones.length,n),n<d.skeleton.bones.length&&console.warn("WebGLRenderer: too many bones - "+d.skeleton.bones.length+", this GPU supports just "+n+" (try OpenGL instead of ANGLE)")));c={precision:W,supportsVertexTextures:Sb,map:!!a.map,
|
||||
|
|
@ -602,7 +602,7 @@ b,c){var d=a*b,e=new Uint8Array(3*d),f=Math.floor(255*c.r),g=Math.floor(255*c.g)
|
|||
THREE.SceneUtils={createMultiMaterialObject:function(a,b){for(var c=new THREE.Object3D,d=0,e=b.length;d<e;d++)c.add(new THREE.Mesh(a,b[d]));return c},detach:function(a,b,c){a.applyMatrix(b.matrixWorld);b.remove(a);c.add(a)},attach:function(a,b,c){var d=new THREE.Matrix4;d.getInverse(c.matrixWorld);a.applyMatrix(d);b.remove(a);c.add(a)}};
|
||||
THREE.FontUtils={faces:{},face:"helvetiker",weight:"normal",style:"normal",size:150,divisions:10,getFace:function(){try{return this.faces[this.face][this.weight][this.style]}catch(a){throw"The font "+this.face+" with "+this.weight+" weight and "+this.style+" style is missing.";}},loadFace:function(a){var b=a.familyName.toLowerCase();this.faces[b]=this.faces[b]||{};this.faces[b][a.cssFontWeight]=this.faces[b][a.cssFontWeight]||{};this.faces[b][a.cssFontWeight][a.cssFontStyle]=a;return this.faces[b][a.cssFontWeight][a.cssFontStyle]=
|
||||
a},drawText:function(a){var b=this.getFace(),c=this.size/b.resolution,d=0,e=String(a).split(""),f=e.length,g=[];for(a=0;a<f;a++){var h=new THREE.Path,h=this.extractGlyphPoints(e[a],b,c,d,h),d=d+h.offset;g.push(h.path)}return{paths:g,offset:d/2}},extractGlyphPoints:function(a,b,c,d,e){var f=[],g,h,k,l,n,q,r,t,s,p,v,w=b.glyphs[a]||b.glyphs["?"];if(w){if(w.o)for(b=w._cachedOutline||(w._cachedOutline=w.o.split(" ")),l=b.length,a=0;a<l;)switch(k=b[a++],k){case "m":k=b[a++]*c+d;n=b[a++]*c;e.moveTo(k,n);
|
||||
break;case "l":k=b[a++]*c+d;n=b[a++]*c;e.lineTo(k,n);break;case "q":k=b[a++]*c+d;n=b[a++]*c;t=b[a++]*c+d;s=b[a++]*c;e.quadraticCurveTo(t,s,k,n);if(g=f[f.length-1])for(q=g.x,r=g.y,g=1,h=this.divisions;g<=h;g++){var u=g/h;THREE.Shape.Utils.b2(u,q,t,k);THREE.Shape.Utils.b2(u,r,s,n)}break;case "b":if(k=b[a++]*c+d,n=b[a++]*c,t=b[a++]*c+d,s=b[a++]*c,p=b[a++]*c+d,v=b[a++]*c,e.bezierCurveTo(t,s,p,v,k,n),g=f[f.length-1])for(q=g.x,r=g.y,g=1,h=this.divisions;g<=h;g++)u=g/h,THREE.Shape.Utils.b3(u,q,t,p,k),THREE.Shape.Utils.b3(u,
|
||||
break;case "l":k=b[a++]*c+d;n=b[a++]*c;e.lineTo(k,n);break;case "q":k=b[a++]*c+d;n=b[a++]*c;t=b[a++]*c+d;s=b[a++]*c;e.quadraticCurveTo(t,s,k,n);if(g=f[f.length-1])for(q=g.x,r=g.y,g=1,h=this.divisions;g<=h;g++){var u=g/h;THREE.Shape.utils.b2(u,q,t,k);THREE.Shape.utils.b2(u,r,s,n)}break;case "b":if(k=b[a++]*c+d,n=b[a++]*c,t=b[a++]*c+d,s=b[a++]*c,p=b[a++]*c+d,v=b[a++]*c,e.bezierCurveTo(t,s,p,v,k,n),g=f[f.length-1])for(q=g.x,r=g.y,g=1,h=this.divisions;g<=h;g++)u=g/h,THREE.Shape.utils.b3(u,q,t,p,k),THREE.Shape.utils.b3(u,
|
||||
r,s,v,n)}return{offset:w.ha*c,path:e}}}};
|
||||
THREE.FontUtils.generateShapes=function(a,b){b=b||{};var c=void 0!==b.curveSegments?b.curveSegments:4,d=void 0!==b.font?b.font:"helvetiker",e=void 0!==b.weight?b.weight:"normal",f=void 0!==b.style?b.style:"normal";THREE.FontUtils.size=void 0!==b.size?b.size:100;THREE.FontUtils.divisions=c;THREE.FontUtils.face=d;THREE.FontUtils.weight=e;THREE.FontUtils.style=f;c=THREE.FontUtils.drawText(a).paths;d=[];e=0;for(f=c.length;e<f;e++)Array.prototype.push.apply(d,c[e].toShapes());return d};
|
||||
(function(a){var b=function(a){for(var b=a.length,e=0,f=b-1,g=0;g<b;f=g++)e+=a[f].x*a[g].y-a[g].x*a[f].y;return 0.5*e};a.Triangulate=function(a,d){var e=a.length;if(3>e)return null;var f=[],g=[],h=[],k,l,n;if(0<b(a))for(l=0;l<e;l++)g[l]=l;else for(l=0;l<e;l++)g[l]=e-1-l;var q=2*e;for(l=e-1;2<e;){if(0>=q--){console.log("Warning, unable to triangulate polygon!");break}k=l;e<=k&&(k=0);l=k+1;e<=l&&(l=0);n=l+1;e<=n&&(n=0);var r;a:{var t=r=void 0,s=void 0,p=void 0,v=void 0,w=void 0,u=void 0,D=void 0,A=
|
||||
|
|
@ -612,7 +612,7 @@ THREE.Curve.prototype.getPoints=function(a){a||(a=5);var b,c=[];for(b=0;b<=a;b++
|
|||
THREE.Curve.prototype.getLengths=function(a){a||(a=this.__arcLengthDivisions?this.__arcLengthDivisions:200);if(this.cacheArcLengths&&this.cacheArcLengths.length==a+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var b=[],c,d=this.getPoint(0),e,f=0;b.push(0);for(e=1;e<=a;e++)c=this.getPoint(e/a),f+=c.distanceTo(d),b.push(f),d=c;return this.cacheArcLengths=b};THREE.Curve.prototype.updateArcLengths=function(){this.needsUpdate=!0;this.getLengths()};
|
||||
THREE.Curve.prototype.getUtoTmapping=function(a,b){var c=this.getLengths(),d=0,e=c.length,f;f=b?b:a*c[e-1];for(var g=0,h=e-1,k;g<=h;)if(d=Math.floor(g+(h-g)/2),k=c[d]-f,0>k)g=d+1;else if(0<k)h=d-1;else{h=d;break}d=h;if(c[d]==f)return d/(e-1);g=c[d];return c=(d+(f-g)/(c[d+1]-g))/(e-1)};THREE.Curve.prototype.getTangent=function(a){var b=a-1E-4;a+=1E-4;0>b&&(b=0);1<a&&(a=1);b=this.getPoint(b);return this.getPoint(a).clone().sub(b).normalize()};
|
||||
THREE.Curve.prototype.getTangentAt=function(a){a=this.getUtoTmapping(a);return this.getTangent(a)};
|
||||
THREE.Curve.Utils={tangentQuadraticBezier:function(a,b,c,d){return 2*(1-a)*(c-b)+2*a*(d-c)},tangentCubicBezier:function(a,b,c,d,e){return-3*b*(1-a)*(1-a)+3*c*(1-a)*(1-a)-6*a*c*(1-a)+6*a*d*(1-a)-3*a*a*d+3*a*a*e},tangentSpline:function(a,b,c,d,e){return 6*a*a-6*a+(3*a*a-4*a+1)+(-6*a*a+6*a)+(3*a*a-2*a)},interpolate:function(a,b,c,d,e){a=0.5*(c-a);d=0.5*(d-b);var f=e*e;return(2*b-2*c+a+d)*e*f+(-3*b+3*c-2*a-d)*f+a*e+b}};
|
||||
THREE.Curve.utils={tangentQuadraticBezier:function(a,b,c,d){return 2*(1-a)*(c-b)+2*a*(d-c)},tangentCubicBezier:function(a,b,c,d,e){return-3*b*(1-a)*(1-a)+3*c*(1-a)*(1-a)-6*a*c*(1-a)+6*a*d*(1-a)-3*a*a*d+3*a*a*e},tangentSpline:function(a,b,c,d,e){return 6*a*a-6*a+(3*a*a-4*a+1)+(-6*a*a+6*a)+(3*a*a-2*a)},interpolate:function(a,b,c,d,e){a=0.5*(c-a);d=0.5*(d-b);var f=e*e;return(2*b-2*c+a+d)*e*f+(-3*b+3*c-2*a-d)*f+a*e+b}};
|
||||
THREE.Curve.create=function(a,b){a.prototype=Object.create(THREE.Curve.prototype);a.prototype.getPoint=b;return a};THREE.CurvePath=function(){this.curves=[];this.bends=[];this.autoClose=!1};THREE.CurvePath.prototype=Object.create(THREE.Curve.prototype);THREE.CurvePath.prototype.add=function(a){this.curves.push(a)};THREE.CurvePath.prototype.checkConnection=function(){};
|
||||
THREE.CurvePath.prototype.closePath=function(){var a=this.curves[0].getPoint(0),b=this.curves[this.curves.length-1].getPoint(1);a.equals(b)||this.curves.push(new THREE.LineCurve(b,a))};THREE.CurvePath.prototype.getPoint=function(a){var b=a*this.getLength(),c=this.getCurveLengths();for(a=0;a<c.length;){if(c[a]>=b)return b=c[a]-b,a=this.curves[a],b=1-b/a.getLength(),a.getPointAt(b);a++}return null};THREE.CurvePath.prototype.getLength=function(){var a=this.getCurveLengths();return a[a.length-1]};
|
||||
THREE.CurvePath.prototype.getCurveLengths=function(){if(this.cacheLengths&&this.cacheLengths.length==this.curves.length)return this.cacheLengths;var a=[],b=0,c,d=this.curves.length;for(c=0;c<d;c++)b+=this.curves[c].getLength(),a.push(b);return this.cacheLengths=a};
|
||||
|
|
@ -630,32 +630,32 @@ THREE.Path.prototype.splineThru=function(a){var b=Array.prototype.slice.call(arg
|
|||
THREE.Path.prototype.absarc=function(a,b,c,d,e,f){this.absellipse(a,b,c,c,d,e,f)};THREE.Path.prototype.ellipse=function(a,b,c,d,e,f,g){var h=this.actions[this.actions.length-1].args;this.absellipse(a+h[h.length-2],b+h[h.length-1],c,d,e,f,g)};THREE.Path.prototype.absellipse=function(a,b,c,d,e,f,g){var h=Array.prototype.slice.call(arguments),k=new THREE.EllipseCurve(a,b,c,d,e,f,g);this.curves.push(k);k=k.getPoint(1);h.push(k.x);h.push(k.y);this.actions.push({action:THREE.PathActions.ELLIPSE,args:h})};
|
||||
THREE.Path.prototype.getSpacedPoints=function(a,b){a||(a=40);for(var c=[],d=0;d<a;d++)c.push(this.getPoint(d/a));return c};
|
||||
THREE.Path.prototype.getPoints=function(a,b){if(this.useSpacedPoints)return console.log("tata"),this.getSpacedPoints(a,b);a=a||12;var c=[],d,e,f,g,h,k,l,n,q,r,t,s,p;d=0;for(e=this.actions.length;d<e;d++)switch(f=this.actions[d],g=f.action,f=f.args,g){case THREE.PathActions.MOVE_TO:c.push(new THREE.Vector2(f[0],f[1]));break;case THREE.PathActions.LINE_TO:c.push(new THREE.Vector2(f[0],f[1]));break;case THREE.PathActions.QUADRATIC_CURVE_TO:h=f[2];k=f[3];q=f[0];r=f[1];0<c.length?(g=c[c.length-1],t=g.x,
|
||||
s=g.y):(g=this.actions[d-1].args,t=g[g.length-2],s=g[g.length-1]);for(f=1;f<=a;f++)p=f/a,g=THREE.Shape.Utils.b2(p,t,q,h),p=THREE.Shape.Utils.b2(p,s,r,k),c.push(new THREE.Vector2(g,p));break;case THREE.PathActions.BEZIER_CURVE_TO:h=f[4];k=f[5];q=f[0];r=f[1];l=f[2];n=f[3];0<c.length?(g=c[c.length-1],t=g.x,s=g.y):(g=this.actions[d-1].args,t=g[g.length-2],s=g[g.length-1]);for(f=1;f<=a;f++)p=f/a,g=THREE.Shape.Utils.b3(p,t,q,l,h),p=THREE.Shape.Utils.b3(p,s,r,n,k),c.push(new THREE.Vector2(g,p));break;case THREE.PathActions.CSPLINE_THRU:g=
|
||||
s=g.y):(g=this.actions[d-1].args,t=g[g.length-2],s=g[g.length-1]);for(f=1;f<=a;f++)p=f/a,g=THREE.Shape.utils.b2(p,t,q,h),p=THREE.Shape.utils.b2(p,s,r,k),c.push(new THREE.Vector2(g,p));break;case THREE.PathActions.BEZIER_CURVE_TO:h=f[4];k=f[5];q=f[0];r=f[1];l=f[2];n=f[3];0<c.length?(g=c[c.length-1],t=g.x,s=g.y):(g=this.actions[d-1].args,t=g[g.length-2],s=g[g.length-1]);for(f=1;f<=a;f++)p=f/a,g=THREE.Shape.utils.b3(p,t,q,l,h),p=THREE.Shape.utils.b3(p,s,r,n,k),c.push(new THREE.Vector2(g,p));break;case THREE.PathActions.CSPLINE_THRU:g=
|
||||
this.actions[d-1].args;p=[new THREE.Vector2(g[g.length-2],g[g.length-1])];g=a*f[0].length;p=p.concat(f[0]);p=new THREE.SplineCurve(p);for(f=1;f<=g;f++)c.push(p.getPointAt(f/g));break;case THREE.PathActions.ARC:h=f[0];k=f[1];r=f[2];l=f[3];g=f[4];q=!!f[5];t=g-l;s=2*a;for(f=1;f<=s;f++)p=f/s,q||(p=1-p),p=l+p*t,g=h+r*Math.cos(p),p=k+r*Math.sin(p),c.push(new THREE.Vector2(g,p));break;case THREE.PathActions.ELLIPSE:for(h=f[0],k=f[1],r=f[2],n=f[3],l=f[4],g=f[5],q=!!f[6],t=g-l,s=2*a,f=1;f<=s;f++)p=f/s,q||
|
||||
(p=1-p),p=l+p*t,g=h+r*Math.cos(p),p=k+n*Math.sin(p),c.push(new THREE.Vector2(g,p))}d=c[c.length-1];1E-10>Math.abs(d.x-c[0].x)&&1E-10>Math.abs(d.y-c[0].y)&&c.splice(c.length-1,1);b&&c.push(c[0]);return c};
|
||||
THREE.Path.prototype.toShapes=function(a,b){function c(a){for(var b=[],c=0,d=a.length;c<d;c++){var e=a[c],f=new THREE.Shape;f.actions=e.actions;f.curves=e.curves;b.push(f)}return b}function d(a,b){for(var c=b.length,d=!1,e=c-1,f=0;f<c;e=f++){var g=b[e],h=b[f],k=h.x-g.x,l=h.y-g.y;if(1E-10<Math.abs(l)){if(0>l&&(g=b[f],k=-k,h=b[e],l=-l),!(a.y<g.y||a.y>h.y))if(a.y==g.y){if(a.x==g.x)return!0}else{e=l*(a.x-g.x)-k*(a.y-g.y);if(0==e)return!0;0>e||(d=!d)}}else if(a.y==g.y&&(h.x<=a.x&&a.x<=g.x||g.x<=a.x&&a.x<=
|
||||
h.x))return!0}return d}var e=function(a){var b,c,d,e,f=[],g=new THREE.Path;b=0;for(c=a.length;b<c;b++)d=a[b],e=d.args,d=d.action,d==THREE.PathActions.MOVE_TO&&0!=g.actions.length&&(f.push(g),g=new THREE.Path),g[d].apply(g,e);0!=g.actions.length&&f.push(g);return f}(this.actions);if(0==e.length)return[];if(!0===b)return c(e);var f,g,h,k=[];if(1==e.length)return g=e[0],h=new THREE.Shape,h.actions=g.actions,h.curves=g.curves,k.push(h),k;var l=!THREE.Shape.Utils.isClockWise(e[0].getPoints()),l=a?!l:l;
|
||||
h=[];var n=[],q=[],r=0,t;n[r]=void 0;q[r]=[];var s,p;s=0;for(p=e.length;s<p;s++)g=e[s],t=g.getPoints(),f=THREE.Shape.Utils.isClockWise(t),(f=a?!f:f)?(!l&&n[r]&&r++,n[r]={s:new THREE.Shape,p:t},n[r].s.actions=g.actions,n[r].s.curves=g.curves,l&&r++,q[r]=[]):q[r].push({h:g,p:t[0]});if(!n[0])return c(e);if(1<n.length){s=!1;p=[];g=0;for(e=n.length;g<e;g++)h[g]=[];g=0;for(e=n.length;g<e;g++)for(f=q[g],l=0;l<f.length;l++){r=f[l];t=!0;for(var v=0;v<n.length;v++)d(r.p,n[v].p)&&(g!=v&&p.push({froms:g,tos:v,
|
||||
h.x))return!0}return d}var e=function(a){var b,c,d,e,f=[],g=new THREE.Path;b=0;for(c=a.length;b<c;b++)d=a[b],e=d.args,d=d.action,d==THREE.PathActions.MOVE_TO&&0!=g.actions.length&&(f.push(g),g=new THREE.Path),g[d].apply(g,e);0!=g.actions.length&&f.push(g);return f}(this.actions);if(0==e.length)return[];if(!0===b)return c(e);var f,g,h,k=[];if(1==e.length)return g=e[0],h=new THREE.Shape,h.actions=g.actions,h.curves=g.curves,k.push(h),k;var l=!THREE.Shape.utils.isClockWise(e[0].getPoints()),l=a?!l:l;
|
||||
h=[];var n=[],q=[],r=0,t;n[r]=void 0;q[r]=[];var s,p;s=0;for(p=e.length;s<p;s++)g=e[s],t=g.getPoints(),f=THREE.Shape.utils.isClockWise(t),(f=a?!f:f)?(!l&&n[r]&&r++,n[r]={s:new THREE.Shape,p:t},n[r].s.actions=g.actions,n[r].s.curves=g.curves,l&&r++,q[r]=[]):q[r].push({h:g,p:t[0]});if(!n[0])return c(e);if(1<n.length){s=!1;p=[];g=0;for(e=n.length;g<e;g++)h[g]=[];g=0;for(e=n.length;g<e;g++)for(f=q[g],l=0;l<f.length;l++){r=f[l];t=!0;for(var v=0;v<n.length;v++)d(r.p,n[v].p)&&(g!=v&&p.push({froms:g,tos:v,
|
||||
hole:l}),t?(t=!1,h[v].push(r)):s=!0);t&&h[g].push(r)}0<p.length&&(s||(q=h))}s=0;for(p=n.length;s<p;s++)for(h=n[s].s,k.push(h),g=q[s],e=0,f=g.length;e<f;e++)h.holes.push(g[e].h);return k};THREE.Shape=function(){THREE.Path.apply(this,arguments);this.holes=[]};THREE.Shape.prototype=Object.create(THREE.Path.prototype);THREE.Shape.prototype.extrude=function(a){return new THREE.ExtrudeGeometry(this,a)};THREE.Shape.prototype.makeGeometry=function(a){return new THREE.ShapeGeometry(this,a)};
|
||||
THREE.Shape.prototype.getPointsHoles=function(a){var b,c=this.holes.length,d=[];for(b=0;b<c;b++)d[b]=this.holes[b].getTransformedPoints(a,this.bends);return d};THREE.Shape.prototype.getSpacedPointsHoles=function(a){var b,c=this.holes.length,d=[];for(b=0;b<c;b++)d[b]=this.holes[b].getTransformedSpacedPoints(a,this.bends);return d};THREE.Shape.prototype.extractAllPoints=function(a){return{shape:this.getTransformedPoints(a),holes:this.getPointsHoles(a)}};
|
||||
THREE.Shape.prototype.extractPoints=function(a){return this.useSpacedPoints?this.extractAllSpacedPoints(a):this.extractAllPoints(a)};THREE.Shape.prototype.extractAllSpacedPoints=function(a){return{shape:this.getTransformedSpacedPoints(a),holes:this.getSpacedPointsHoles(a)}};
|
||||
THREE.Shape.Utils={triangulateShape:function(a,b){function c(a,b,c){return a.x!=b.x?a.x<b.x?a.x<=c.x&&c.x<=b.x:b.x<=c.x&&c.x<=a.x:a.y<b.y?a.y<=c.y&&c.y<=b.y:b.y<=c.y&&c.y<=a.y}function d(a,b,d,e,f){var g=b.x-a.x,h=b.y-a.y,k=e.x-d.x,l=e.y-d.y,n=a.x-d.x,q=a.y-d.y,I=h*k-g*l,z=h*n-g*q;if(1E-10<Math.abs(I)){if(0<I){if(0>z||z>I)return[];k=l*n-k*q;if(0>k||k>I)return[]}else{if(0<z||z<I)return[];k=l*n-k*q;if(0<k||k<I)return[]}if(0==k)return!f||0!=z&&z!=I?[a]:[];if(k==I)return!f||0!=z&&z!=I?[b]:[];if(0==z)return[d];
|
||||
THREE.Shape.utils={triangulateShape:function(a,b){function c(a,b,c){return a.x!=b.x?a.x<b.x?a.x<=c.x&&c.x<=b.x:b.x<=c.x&&c.x<=a.x:a.y<b.y?a.y<=c.y&&c.y<=b.y:b.y<=c.y&&c.y<=a.y}function d(a,b,d,e,f){var g=b.x-a.x,h=b.y-a.y,k=e.x-d.x,l=e.y-d.y,n=a.x-d.x,q=a.y-d.y,I=h*k-g*l,z=h*n-g*q;if(1E-10<Math.abs(I)){if(0<I){if(0>z||z>I)return[];k=l*n-k*q;if(0>k||k>I)return[]}else{if(0<z||z<I)return[];k=l*n-k*q;if(0<k||k<I)return[]}if(0==k)return!f||0!=z&&z!=I?[a]:[];if(k==I)return!f||0!=z&&z!=I?[b]:[];if(0==z)return[d];
|
||||
if(z==I)return[e];f=k/I;return[{x:a.x+f*g,y:a.y+f*h}]}if(0!=z||l*n!=k*q)return[];h=0==g&&0==h;k=0==k&&0==l;if(h&&k)return a.x!=d.x||a.y!=d.y?[]:[a];if(h)return c(d,e,a)?[a]:[];if(k)return c(a,b,d)?[d]:[];0!=g?(a.x<b.x?(g=a,k=a.x,h=b,a=b.x):(g=b,k=b.x,h=a,a=a.x),d.x<e.x?(b=d,I=d.x,l=e,d=e.x):(b=e,I=e.x,l=d,d=d.x)):(a.y<b.y?(g=a,k=a.y,h=b,a=b.y):(g=b,k=b.y,h=a,a=a.y),d.y<e.y?(b=d,I=d.y,l=e,d=e.y):(b=e,I=e.y,l=d,d=d.y));return k<=I?a<I?[]:a==I?f?[]:[b]:a<=d?[b,h]:[b,l]:k>d?[]:k==d?f?[]:[g]:a<=d?[g,h]:
|
||||
[g,l]}function e(a,b,c,d){var e=b.x-a.x,f=b.y-a.y;b=c.x-a.x;c=c.y-a.y;var g=d.x-a.x;d=d.y-a.y;a=e*c-f*b;e=e*d-f*g;return 1E-10<Math.abs(a)?(b=g*c-d*b,0<a?0<=e&&0<=b:0<=e||0<=b):0<e}var f,g,h,k,l,n={};h=a.concat();f=0;for(g=b.length;f<g;f++)Array.prototype.push.apply(h,b[f]);f=0;for(g=h.length;f<g;f++)l=h[f].x+":"+h[f].y,void 0!==n[l]&&console.log("Duplicate point",l),n[l]=f;f=function(a,b){function c(a,b){var d=h.length-1,f=a-1;0>f&&(f=d);var g=a+1;g>d&&(g=0);d=e(h[a],h[f],h[g],k[b]);if(!d)return!1;
|
||||
d=k.length-1;f=b-1;0>f&&(f=d);g=b+1;g>d&&(g=0);return(d=e(k[b],k[f],k[g],h[a]))?!0:!1}function f(a,b){var c,e;for(c=0;c<h.length;c++)if(e=c+1,e%=h.length,e=d(a,b,h[c],h[e],!0),0<e.length)return!0;return!1}function g(a,c){var e,f,h,k;for(e=0;e<l.length;e++)for(f=b[l[e]],h=0;h<f.length;h++)if(k=h+1,k%=f.length,k=d(a,c,f[h],f[k],!0),0<k.length)return!0;return!1}var h=a.concat(),k,l=[],n,q,C,I,z,y=[],K,N,ba,P=0;for(n=b.length;P<n;P++)l.push(P);K=0;for(var O=2*l.length;0<l.length;){O--;if(0>O){console.log("Infinite Loop! Holes left:"+
|
||||
l.length+", Probably Hole outside Shape!");break}for(q=K;q<h.length;q++){C=h[q];n=-1;for(P=0;P<l.length;P++)if(I=l[P],z=C.x+":"+C.y+":"+I,void 0===y[z]){k=b[I];for(N=0;N<k.length;N++)if(I=k[N],c(q,N)&&!f(C,I)&&!g(C,I)){n=N;l.splice(P,1);K=h.slice(0,q+1);I=h.slice(q);N=k.slice(n);ba=k.slice(0,n+1);h=K.concat(N).concat(ba).concat(I);K=q;break}if(0<=n)break;y[z]=!0}if(0<=n)break}}return h}(a,b);var q=THREE.FontUtils.Triangulate(f,!1);f=0;for(g=q.length;f<g;f++)for(k=q[f],h=0;3>h;h++)l=k[h].x+":"+k[h].y,
|
||||
l=n[l],void 0!==l&&(k[h]=l);return q.concat()},isClockWise:function(a){return 0>THREE.FontUtils.Triangulate.area(a)},b2p0:function(a,b){var c=1-a;return c*c*b},b2p1:function(a,b){return 2*(1-a)*a*b},b2p2:function(a,b){return a*a*b},b2:function(a,b,c,d){return this.b2p0(a,b)+this.b2p1(a,c)+this.b2p2(a,d)},b3p0:function(a,b){var c=1-a;return c*c*c*b},b3p1:function(a,b){var c=1-a;return 3*c*c*a*b},b3p2:function(a,b){return 3*(1-a)*a*a*b},b3p3:function(a,b){return a*a*a*b},b3:function(a,b,c,d,e){return this.b3p0(a,
|
||||
b)+this.b3p1(a,c)+this.b3p2(a,d)+this.b3p3(a,e)}};THREE.LineCurve=function(a,b){this.v1=a;this.v2=b};THREE.LineCurve.prototype=Object.create(THREE.Curve.prototype);THREE.LineCurve.prototype.getPoint=function(a){var b=this.v2.clone().sub(this.v1);b.multiplyScalar(a).add(this.v1);return b};THREE.LineCurve.prototype.getPointAt=function(a){return this.getPoint(a)};THREE.LineCurve.prototype.getTangent=function(a){return this.v2.clone().sub(this.v1).normalize()};
|
||||
THREE.QuadraticBezierCurve=function(a,b,c){this.v0=a;this.v1=b;this.v2=c};THREE.QuadraticBezierCurve.prototype=Object.create(THREE.Curve.prototype);THREE.QuadraticBezierCurve.prototype.getPoint=function(a){var b;b=THREE.Shape.Utils.b2(a,this.v0.x,this.v1.x,this.v2.x);a=THREE.Shape.Utils.b2(a,this.v0.y,this.v1.y,this.v2.y);return new THREE.Vector2(b,a)};
|
||||
THREE.QuadraticBezierCurve.prototype.getTangent=function(a){var b;b=THREE.Curve.Utils.tangentQuadraticBezier(a,this.v0.x,this.v1.x,this.v2.x);a=THREE.Curve.Utils.tangentQuadraticBezier(a,this.v0.y,this.v1.y,this.v2.y);b=new THREE.Vector2(b,a);b.normalize();return b};THREE.CubicBezierCurve=function(a,b,c,d){this.v0=a;this.v1=b;this.v2=c;this.v3=d};THREE.CubicBezierCurve.prototype=Object.create(THREE.Curve.prototype);
|
||||
THREE.CubicBezierCurve.prototype.getPoint=function(a){var b;b=THREE.Shape.Utils.b3(a,this.v0.x,this.v1.x,this.v2.x,this.v3.x);a=THREE.Shape.Utils.b3(a,this.v0.y,this.v1.y,this.v2.y,this.v3.y);return new THREE.Vector2(b,a)};THREE.CubicBezierCurve.prototype.getTangent=function(a){var b;b=THREE.Curve.Utils.tangentCubicBezier(a,this.v0.x,this.v1.x,this.v2.x,this.v3.x);a=THREE.Curve.Utils.tangentCubicBezier(a,this.v0.y,this.v1.y,this.v2.y,this.v3.y);b=new THREE.Vector2(b,a);b.normalize();return b};
|
||||
THREE.SplineCurve=function(a){this.points=void 0==a?[]:a};THREE.SplineCurve.prototype=Object.create(THREE.Curve.prototype);THREE.SplineCurve.prototype.getPoint=function(a){var b=new THREE.Vector2,c=[],d=this.points,e;e=(d.length-1)*a;a=Math.floor(e);e-=a;c[0]=0==a?a:a-1;c[1]=a;c[2]=a>d.length-2?d.length-1:a+1;c[3]=a>d.length-3?d.length-1:a+2;b.x=THREE.Curve.Utils.interpolate(d[c[0]].x,d[c[1]].x,d[c[2]].x,d[c[3]].x,e);b.y=THREE.Curve.Utils.interpolate(d[c[0]].y,d[c[1]].y,d[c[2]].y,d[c[3]].y,e);return b};
|
||||
THREE.QuadraticBezierCurve=function(a,b,c){this.v0=a;this.v1=b;this.v2=c};THREE.QuadraticBezierCurve.prototype=Object.create(THREE.Curve.prototype);THREE.QuadraticBezierCurve.prototype.getPoint=function(a){var b;b=THREE.Shape.utils.b2(a,this.v0.x,this.v1.x,this.v2.x);a=THREE.Shape.utils.b2(a,this.v0.y,this.v1.y,this.v2.y);return new THREE.Vector2(b,a)};
|
||||
THREE.QuadraticBezierCurve.prototype.getTangent=function(a){var b;b=THREE.Curve.utils.tangentQuadraticBezier(a,this.v0.x,this.v1.x,this.v2.x);a=THREE.Curve.utils.tangentQuadraticBezier(a,this.v0.y,this.v1.y,this.v2.y);b=new THREE.Vector2(b,a);b.normalize();return b};THREE.CubicBezierCurve=function(a,b,c,d){this.v0=a;this.v1=b;this.v2=c;this.v3=d};THREE.CubicBezierCurve.prototype=Object.create(THREE.Curve.prototype);
|
||||
THREE.CubicBezierCurve.prototype.getPoint=function(a){var b;b=THREE.Shape.utils.b3(a,this.v0.x,this.v1.x,this.v2.x,this.v3.x);a=THREE.Shape.utils.b3(a,this.v0.y,this.v1.y,this.v2.y,this.v3.y);return new THREE.Vector2(b,a)};THREE.CubicBezierCurve.prototype.getTangent=function(a){var b;b=THREE.Curve.utils.tangentCubicBezier(a,this.v0.x,this.v1.x,this.v2.x,this.v3.x);a=THREE.Curve.utils.tangentCubicBezier(a,this.v0.y,this.v1.y,this.v2.y,this.v3.y);b=new THREE.Vector2(b,a);b.normalize();return b};
|
||||
THREE.SplineCurve=function(a){this.points=void 0==a?[]:a};THREE.SplineCurve.prototype=Object.create(THREE.Curve.prototype);THREE.SplineCurve.prototype.getPoint=function(a){var b=new THREE.Vector2,c=[],d=this.points,e;e=(d.length-1)*a;a=Math.floor(e);e-=a;c[0]=0==a?a:a-1;c[1]=a;c[2]=a>d.length-2?d.length-1:a+1;c[3]=a>d.length-3?d.length-1:a+2;b.x=THREE.Curve.utils.interpolate(d[c[0]].x,d[c[1]].x,d[c[2]].x,d[c[3]].x,e);b.y=THREE.Curve.utils.interpolate(d[c[0]].y,d[c[1]].y,d[c[2]].y,d[c[3]].y,e);return b};
|
||||
THREE.EllipseCurve=function(a,b,c,d,e,f,g){this.aX=a;this.aY=b;this.xRadius=c;this.yRadius=d;this.aStartAngle=e;this.aEndAngle=f;this.aClockwise=g};THREE.EllipseCurve.prototype=Object.create(THREE.Curve.prototype);
|
||||
THREE.EllipseCurve.prototype.getPoint=function(a){var b;b=this.aEndAngle-this.aStartAngle;0>b&&(b+=2*Math.PI);b>2*Math.PI&&(b-=2*Math.PI);b=!0===this.aClockwise?this.aEndAngle+(1-a)*(2*Math.PI-b):this.aStartAngle+a*b;a=this.aX+this.xRadius*Math.cos(b);b=this.aY+this.yRadius*Math.sin(b);return new THREE.Vector2(a,b)};THREE.ArcCurve=function(a,b,c,d,e,f){THREE.EllipseCurve.call(this,a,b,c,c,d,e,f)};THREE.ArcCurve.prototype=Object.create(THREE.EllipseCurve.prototype);
|
||||
THREE.LineCurve3=THREE.Curve.create(function(a,b){this.v1=a;this.v2=b},function(a){var b=new THREE.Vector3;b.subVectors(this.v2,this.v1);b.multiplyScalar(a);b.add(this.v1);return b});THREE.QuadraticBezierCurve3=THREE.Curve.create(function(a,b,c){this.v0=a;this.v1=b;this.v2=c},function(a){var b,c;b=THREE.Shape.Utils.b2(a,this.v0.x,this.v1.x,this.v2.x);c=THREE.Shape.Utils.b2(a,this.v0.y,this.v1.y,this.v2.y);a=THREE.Shape.Utils.b2(a,this.v0.z,this.v1.z,this.v2.z);return new THREE.Vector3(b,c,a)});
|
||||
THREE.CubicBezierCurve3=THREE.Curve.create(function(a,b,c,d){this.v0=a;this.v1=b;this.v2=c;this.v3=d},function(a){var b,c;b=THREE.Shape.Utils.b3(a,this.v0.x,this.v1.x,this.v2.x,this.v3.x);c=THREE.Shape.Utils.b3(a,this.v0.y,this.v1.y,this.v2.y,this.v3.y);a=THREE.Shape.Utils.b3(a,this.v0.z,this.v1.z,this.v2.z,this.v3.z);return new THREE.Vector3(b,c,a)});
|
||||
THREE.SplineCurve3=THREE.Curve.create(function(a){this.points=void 0==a?[]:a},function(a){var b=new THREE.Vector3,c=[],d=this.points,e;a*=d.length-1;e=Math.floor(a);a-=e;c[0]=0==e?e:e-1;c[1]=e;c[2]=e>d.length-2?d.length-1:e+1;c[3]=e>d.length-3?d.length-1:e+2;e=d[c[0]];var f=d[c[1]],g=d[c[2]],c=d[c[3]];b.x=THREE.Curve.Utils.interpolate(e.x,f.x,g.x,c.x,a);b.y=THREE.Curve.Utils.interpolate(e.y,f.y,g.y,c.y,a);b.z=THREE.Curve.Utils.interpolate(e.z,f.z,g.z,c.z,a);return b});
|
||||
THREE.ClosedSplineCurve3=THREE.Curve.create(function(a){this.points=void 0==a?[]:a},function(a){var b=new THREE.Vector3,c=[],d=this.points,e;e=(d.length-0)*a;a=Math.floor(e);e-=a;a+=0<a?0:(Math.floor(Math.abs(a)/d.length)+1)*d.length;c[0]=(a-1)%d.length;c[1]=a%d.length;c[2]=(a+1)%d.length;c[3]=(a+2)%d.length;b.x=THREE.Curve.Utils.interpolate(d[c[0]].x,d[c[1]].x,d[c[2]].x,d[c[3]].x,e);b.y=THREE.Curve.Utils.interpolate(d[c[0]].y,d[c[1]].y,d[c[2]].y,d[c[3]].y,e);b.z=THREE.Curve.Utils.interpolate(d[c[0]].z,
|
||||
THREE.LineCurve3=THREE.Curve.create(function(a,b){this.v1=a;this.v2=b},function(a){var b=new THREE.Vector3;b.subVectors(this.v2,this.v1);b.multiplyScalar(a);b.add(this.v1);return b});THREE.QuadraticBezierCurve3=THREE.Curve.create(function(a,b,c){this.v0=a;this.v1=b;this.v2=c},function(a){var b,c;b=THREE.Shape.utils.b2(a,this.v0.x,this.v1.x,this.v2.x);c=THREE.Shape.utils.b2(a,this.v0.y,this.v1.y,this.v2.y);a=THREE.Shape.utils.b2(a,this.v0.z,this.v1.z,this.v2.z);return new THREE.Vector3(b,c,a)});
|
||||
THREE.CubicBezierCurve3=THREE.Curve.create(function(a,b,c,d){this.v0=a;this.v1=b;this.v2=c;this.v3=d},function(a){var b,c;b=THREE.Shape.utils.b3(a,this.v0.x,this.v1.x,this.v2.x,this.v3.x);c=THREE.Shape.utils.b3(a,this.v0.y,this.v1.y,this.v2.y,this.v3.y);a=THREE.Shape.utils.b3(a,this.v0.z,this.v1.z,this.v2.z,this.v3.z);return new THREE.Vector3(b,c,a)});
|
||||
THREE.SplineCurve3=THREE.Curve.create(function(a){this.points=void 0==a?[]:a},function(a){var b=new THREE.Vector3,c=[],d=this.points,e;a*=d.length-1;e=Math.floor(a);a-=e;c[0]=0==e?e:e-1;c[1]=e;c[2]=e>d.length-2?d.length-1:e+1;c[3]=e>d.length-3?d.length-1:e+2;e=d[c[0]];var f=d[c[1]],g=d[c[2]],c=d[c[3]];b.x=THREE.Curve.utils.interpolate(e.x,f.x,g.x,c.x,a);b.y=THREE.Curve.utils.interpolate(e.y,f.y,g.y,c.y,a);b.z=THREE.Curve.utils.interpolate(e.z,f.z,g.z,c.z,a);return b});
|
||||
THREE.ClosedSplineCurve3=THREE.Curve.create(function(a){this.points=void 0==a?[]:a},function(a){var b=new THREE.Vector3,c=[],d=this.points,e;e=(d.length-0)*a;a=Math.floor(e);e-=a;a+=0<a?0:(Math.floor(Math.abs(a)/d.length)+1)*d.length;c[0]=(a-1)%d.length;c[1]=a%d.length;c[2]=(a+1)%d.length;c[3]=(a+2)%d.length;b.x=THREE.Curve.utils.interpolate(d[c[0]].x,d[c[1]].x,d[c[2]].x,d[c[3]].x,e);b.y=THREE.Curve.utils.interpolate(d[c[0]].y,d[c[1]].y,d[c[2]].y,d[c[3]].y,e);b.z=THREE.Curve.utils.interpolate(d[c[0]].z,
|
||||
d[c[1]].z,d[c[2]].z,d[c[3]].z,e);return b});
|
||||
THREE.AnimationHandler={LINEAR:0,CATMULLROM:1,CATMULLROM_FORWARD:2,add:function(){console.warn("THREE.AnimationHandler.add() has been deprecated.")},get:function(){console.warn("THREE.AnimationHandler.get() has been deprecated.")},remove:function(){console.warn("THREE.AnimationHandler.remove() has been deprecated.")},animations:[],init:function(a){if(!0!==a.initialized){for(var b=0;b<a.hierarchy.length;b++){for(var c=0;c<a.hierarchy[b].keys.length;c++)if(0>a.hierarchy[b].keys[c].time&&(a.hierarchy[b].keys[c].time=
|
||||
0),void 0!==a.hierarchy[b].keys[c].rot&&!(a.hierarchy[b].keys[c].rot instanceof THREE.Quaternion)){var d=a.hierarchy[b].keys[c].rot;a.hierarchy[b].keys[c].rot=(new THREE.Quaternion).fromArray(d)}if(a.hierarchy[b].keys.length&&void 0!==a.hierarchy[b].keys[0].morphTargets){d={};for(c=0;c<a.hierarchy[b].keys.length;c++)for(var e=0;e<a.hierarchy[b].keys[c].morphTargets.length;e++){var f=a.hierarchy[b].keys[c].morphTargets[e];d[f]=-1}a.hierarchy[b].usedMorphTargets=d;for(c=0;c<a.hierarchy[b].keys.length;c++){var g=
|
||||
|
|
@ -695,15 +695,15 @@ THREE.ExtrudeGeometry=function(a,b){"undefined"!==typeof a&&(THREE.Geometry.call
|
|||
THREE.ExtrudeGeometry.prototype.addShape=function(a,b){function c(a,b,c){b||console.log("die");return b.clone().multiplyScalar(c).add(a)}function d(a,b,c){var d=THREE.Math.sign,e=1,e=a.x-b.x,f=a.y-b.y,g=c.x-a.x,h=c.y-a.y,k=e*e+f*f;if(1E-10<Math.abs(e*h-f*g)){var l=Math.sqrt(k),d=Math.sqrt(g*g+h*h),k=b.x-f/l;b=b.y+e/l;g=((c.x-h/d-k)*h-(c.y+g/d-b)*g)/(e*h-f*g);c=k+e*g-a.x;a=b+f*g-a.y;e=c*c+a*a;if(2>=e)return new THREE.Vector2(c,a);e=Math.sqrt(e/2)}else a=!1,1E-10<e?1E-10<g&&(a=!0):-1E-10>e?-1E-10>g&&
|
||||
(a=!0):d(f)==d(h)&&(a=!0),a?(c=-f,a=e,e=Math.sqrt(k)):(c=e,a=f,e=Math.sqrt(k/2));return new THREE.Vector2(c/e,a/e)}function e(c,d){var e,f;for(H=c.length;0<=--H;){e=H;f=H-1;0>f&&(f=c.length-1);for(var g=0,h=t+2*n,g=0;g<h;g++){var k=S*g,l=S*(g+1),p=d+e+k,k=d+f+k,q=d+f+l,l=d+e+l,r=c,s=g,v=h,w=e,x=f,p=p+ba,k=k+ba,q=q+ba,l=l+ba;N.faces.push(new THREE.Face3(p,k,l,null,null,u));N.faces.push(new THREE.Face3(k,q,l,null,null,u));p=D.generateSideWallUV(N,a,r,b,p,k,q,l,s,v,w,x);N.faceVertexUvs[0].push([p[0],
|
||||
p[1],p[3]]);N.faceVertexUvs[0].push([p[1],p[2],p[3]])}}}function f(a,b,c){N.vertices.push(new THREE.Vector3(a,b,c))}function g(c,d,e,f){c+=ba;d+=ba;e+=ba;N.faces.push(new THREE.Face3(c,d,e,null,null,w));c=f?D.generateBottomUV(N,a,b,c,d,e):D.generateTopUV(N,a,b,c,d,e);N.faceVertexUvs[0].push(c)}var h=void 0!==b.amount?b.amount:100,k=void 0!==b.bevelThickness?b.bevelThickness:6,l=void 0!==b.bevelSize?b.bevelSize:k-2,n=void 0!==b.bevelSegments?b.bevelSegments:3,q=void 0!==b.bevelEnabled?b.bevelEnabled:
|
||||
!0,r=void 0!==b.curveSegments?b.curveSegments:12,t=void 0!==b.steps?b.steps:1,s=b.extrudePath,p,v=!1,w=b.material,u=b.extrudeMaterial,D=void 0!==b.UVGenerator?b.UVGenerator:THREE.ExtrudeGeometry.WorldUVGenerator,A,x,C,I;s&&(p=s.getSpacedPoints(t),v=!0,q=!1,A=void 0!==b.frames?b.frames:new THREE.TubeGeometry.FrenetFrames(s,t,!1),x=new THREE.Vector3,C=new THREE.Vector3,I=new THREE.Vector3);q||(l=k=n=0);var z,y,K,N=this,ba=this.vertices.length,s=a.extractPoints(r),r=s.shape,P=s.holes;if(s=!THREE.Shape.Utils.isClockWise(r)){r=
|
||||
r.reverse();y=0;for(K=P.length;y<K;y++)z=P[y],THREE.Shape.Utils.isClockWise(z)&&(P[y]=z.reverse());s=!1}var O=THREE.Shape.Utils.triangulateShape(r,P),J=r;y=0;for(K=P.length;y<K;y++)z=P[y],r=r.concat(z);var E,Q,L,R,B,S=r.length,V,W=O.length,s=[],H=0;L=J.length;E=L-1;for(Q=H+1;H<L;H++,E++,Q++)E===L&&(E=0),Q===L&&(Q=0),s[H]=d(J[H],J[E],J[Q]);var oa=[],$,X=s.concat();y=0;for(K=P.length;y<K;y++){z=P[y];$=[];H=0;L=z.length;E=L-1;for(Q=H+1;H<L;H++,E++,Q++)E===L&&(E=0),Q===L&&(Q=0),$[H]=d(z[H],z[E],z[Q]);
|
||||
!0,r=void 0!==b.curveSegments?b.curveSegments:12,t=void 0!==b.steps?b.steps:1,s=b.extrudePath,p,v=!1,w=b.material,u=b.extrudeMaterial,D=void 0!==b.UVGenerator?b.UVGenerator:THREE.ExtrudeGeometry.WorldUVGenerator,A,x,C,I;s&&(p=s.getSpacedPoints(t),v=!0,q=!1,A=void 0!==b.frames?b.frames:new THREE.TubeGeometry.FrenetFrames(s,t,!1),x=new THREE.Vector3,C=new THREE.Vector3,I=new THREE.Vector3);q||(l=k=n=0);var z,y,K,N=this,ba=this.vertices.length,s=a.extractPoints(r),r=s.shape,P=s.holes;if(s=!THREE.Shape.utils.isClockWise(r)){r=
|
||||
r.reverse();y=0;for(K=P.length;y<K;y++)z=P[y],THREE.Shape.utils.isClockWise(z)&&(P[y]=z.reverse());s=!1}var O=THREE.Shape.utils.triangulateShape(r,P),J=r;y=0;for(K=P.length;y<K;y++)z=P[y],r=r.concat(z);var E,Q,L,R,B,S=r.length,V,W=O.length,s=[],H=0;L=J.length;E=L-1;for(Q=H+1;H<L;H++,E++,Q++)E===L&&(E=0),Q===L&&(Q=0),s[H]=d(J[H],J[E],J[Q]);var oa=[],$,X=s.concat();y=0;for(K=P.length;y<K;y++){z=P[y];$=[];H=0;L=z.length;E=L-1;for(Q=H+1;H<L;H++,E++,Q++)E===L&&(E=0),Q===L&&(Q=0),$[H]=d(z[H],z[E],z[Q]);
|
||||
oa.push($);X=X.concat($)}for(E=0;E<n;E++){L=E/n;R=k*(1-L);Q=l*Math.sin(L*Math.PI/2);H=0;for(L=J.length;H<L;H++)B=c(J[H],s[H],Q),f(B.x,B.y,-R);y=0;for(K=P.length;y<K;y++)for(z=P[y],$=oa[y],H=0,L=z.length;H<L;H++)B=c(z[H],$[H],Q),f(B.x,B.y,-R)}Q=l;for(H=0;H<S;H++)B=q?c(r[H],X[H],Q):r[H],v?(C.copy(A.normals[0]).multiplyScalar(B.x),x.copy(A.binormals[0]).multiplyScalar(B.y),I.copy(p[0]).add(C).add(x),f(I.x,I.y,I.z)):f(B.x,B.y,0);for(L=1;L<=t;L++)for(H=0;H<S;H++)B=q?c(r[H],X[H],Q):r[H],v?(C.copy(A.normals[L]).multiplyScalar(B.x),
|
||||
x.copy(A.binormals[L]).multiplyScalar(B.y),I.copy(p[L]).add(C).add(x),f(I.x,I.y,I.z)):f(B.x,B.y,h/t*L);for(E=n-1;0<=E;E--){L=E/n;R=k*(1-L);Q=l*Math.sin(L*Math.PI/2);H=0;for(L=J.length;H<L;H++)B=c(J[H],s[H],Q),f(B.x,B.y,h+R);y=0;for(K=P.length;y<K;y++)for(z=P[y],$=oa[y],H=0,L=z.length;H<L;H++)B=c(z[H],$[H],Q),v?f(B.x,B.y+p[t-1].y,p[t-1].x+R):f(B.x,B.y,h+R)}(function(){if(q){var a;a=0*S;for(H=0;H<W;H++)V=O[H],g(V[2]+a,V[1]+a,V[0]+a,!0);a=t+2*n;a*=S;for(H=0;H<W;H++)V=O[H],g(V[0]+a,V[1]+a,V[2]+a,!1)}else{for(H=
|
||||
0;H<W;H++)V=O[H],g(V[2],V[1],V[0],!0);for(H=0;H<W;H++)V=O[H],g(V[0]+S*t,V[1]+S*t,V[2]+S*t,!1)}})();(function(){var a=0;e(J,a);a+=J.length;y=0;for(K=P.length;y<K;y++)z=P[y],e(z,a),a+=z.length})()};
|
||||
THREE.ExtrudeGeometry.WorldUVGenerator={generateTopUV:function(a,b,c,d,e,f){b=a.vertices[e].x;e=a.vertices[e].y;c=a.vertices[f].x;f=a.vertices[f].y;return[new THREE.Vector2(a.vertices[d].x,a.vertices[d].y),new THREE.Vector2(b,e),new THREE.Vector2(c,f)]},generateBottomUV:function(a,b,c,d,e,f){return this.generateTopUV(a,b,c,d,e,f)},generateSideWallUV:function(a,b,c,d,e,f,g,h,k,l,n,q){b=a.vertices[e].x;c=a.vertices[e].y;e=a.vertices[e].z;d=a.vertices[f].x;k=a.vertices[f].y;f=a.vertices[f].z;l=a.vertices[g].x;
|
||||
n=a.vertices[g].y;g=a.vertices[g].z;q=a.vertices[h].x;var r=a.vertices[h].y;a=a.vertices[h].z;return 0.01>Math.abs(c-k)?[new THREE.Vector2(b,1-e),new THREE.Vector2(d,1-f),new THREE.Vector2(l,1-g),new THREE.Vector2(q,1-a)]:[new THREE.Vector2(c,1-e),new THREE.Vector2(k,1-f),new THREE.Vector2(n,1-g),new THREE.Vector2(r,1-a)]}};THREE.ExtrudeGeometry.__v1=new THREE.Vector2;THREE.ExtrudeGeometry.__v2=new THREE.Vector2;THREE.ExtrudeGeometry.__v3=new THREE.Vector2;THREE.ExtrudeGeometry.__v4=new THREE.Vector2;
|
||||
THREE.ExtrudeGeometry.__v5=new THREE.Vector2;THREE.ExtrudeGeometry.__v6=new THREE.Vector2;THREE.ShapeGeometry=function(a,b){THREE.Geometry.call(this);!1===a instanceof Array&&(a=[a]);this.addShapeList(a,b);this.computeFaceNormals()};THREE.ShapeGeometry.prototype=Object.create(THREE.Geometry.prototype);THREE.ShapeGeometry.prototype.addShapeList=function(a,b){for(var c=0,d=a.length;c<d;c++)this.addShape(a[c],b);return this};
|
||||
THREE.ShapeGeometry.prototype.addShape=function(a,b){void 0===b&&(b={});var c=b.material,d=void 0===b.UVGenerator?THREE.ExtrudeGeometry.WorldUVGenerator:b.UVGenerator,e,f,g,h=this.vertices.length;e=a.extractPoints(void 0!==b.curveSegments?b.curveSegments:12);var k=e.shape,l=e.holes;if(!THREE.Shape.Utils.isClockWise(k))for(k=k.reverse(),e=0,f=l.length;e<f;e++)g=l[e],THREE.Shape.Utils.isClockWise(g)&&(l[e]=g.reverse());var n=THREE.Shape.Utils.triangulateShape(k,l);e=0;for(f=l.length;e<f;e++)g=l[e],
|
||||
THREE.ShapeGeometry.prototype.addShape=function(a,b){void 0===b&&(b={});var c=b.material,d=void 0===b.UVGenerator?THREE.ExtrudeGeometry.WorldUVGenerator:b.UVGenerator,e,f,g,h=this.vertices.length;e=a.extractPoints(void 0!==b.curveSegments?b.curveSegments:12);var k=e.shape,l=e.holes;if(!THREE.Shape.utils.isClockWise(k))for(k=k.reverse(),e=0,f=l.length;e<f;e++)g=l[e],THREE.Shape.utils.isClockWise(g)&&(l[e]=g.reverse());var n=THREE.Shape.utils.triangulateShape(k,l);e=0;for(f=l.length;e<f;e++)g=l[e],
|
||||
k=k.concat(g);l=k.length;f=n.length;for(e=0;e<l;e++)g=k[e],this.vertices.push(new THREE.Vector3(g.x,g.y,0));for(e=0;e<f;e++)l=n[e],k=l[0]+h,g=l[1]+h,l=l[2]+h,this.faces.push(new THREE.Face3(k,g,l,null,null,c)),this.faceVertexUvs[0].push(d.generateBottomUV(this,a,b,k,g,l))};
|
||||
THREE.LatheGeometry=function(a,b,c,d){THREE.Geometry.call(this);b=b||12;c=c||0;d=d||2*Math.PI;for(var e=1/(a.length-1),f=1/b,g=0,h=b;g<=h;g++)for(var k=c+g*f*d,l=Math.cos(k),n=Math.sin(k),k=0,q=a.length;k<q;k++){var r=a[k],t=new THREE.Vector3;t.x=l*r.x-n*r.y;t.y=n*r.x+l*r.y;t.z=r.z;this.vertices.push(t)}c=a.length;g=0;for(h=b;g<h;g++)for(k=0,q=a.length-1;k<q;k++){b=n=k+c*g;d=n+c;var l=n+1+c,n=n+1,r=g*f,t=k*e,s=r+f,p=t+e;this.faces.push(new THREE.Face3(b,d,n));this.faceVertexUvs[0].push([new THREE.Vector2(r,
|
||||
t),new THREE.Vector2(s,t),new THREE.Vector2(r,p)]);this.faces.push(new THREE.Face3(d,l,n));this.faceVertexUvs[0].push([new THREE.Vector2(s,t),new THREE.Vector2(s,p),new THREE.Vector2(r,p)])}this.mergeVertices();this.computeFaceNormals();this.computeVertexNormals()};THREE.LatheGeometry.prototype=Object.create(THREE.Geometry.prototype);
|
||||
|
|
@ -734,49 +734,49 @@ THREE.IcosahedronGeometry=function(a,b){this.parameters={radius:a,detail:b};var
|
|||
THREE.OctahedronGeometry=function(a,b){this.parameters={radius:a,detail:b};THREE.PolyhedronGeometry.call(this,[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],a,b)};THREE.OctahedronGeometry.prototype=Object.create(THREE.Geometry.prototype);THREE.TetrahedronGeometry=function(a,b){THREE.PolyhedronGeometry.call(this,[1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],a,b)};THREE.TetrahedronGeometry.prototype=Object.create(THREE.Geometry.prototype);
|
||||
THREE.ParametricGeometry=function(a,b,c){THREE.Geometry.call(this);var d=this.vertices,e=this.faces,f=this.faceVertexUvs[0],g,h,k,l,n=b+1;for(g=0;g<=c;g++)for(l=g/c,h=0;h<=b;h++)k=h/b,k=a(k,l),d.push(k);var q,r,t,s;for(g=0;g<c;g++)for(h=0;h<b;h++)a=g*n+h,d=g*n+h+1,l=(g+1)*n+h+1,k=(g+1)*n+h,q=new THREE.Vector2(h/b,g/c),r=new THREE.Vector2((h+1)/b,g/c),t=new THREE.Vector2((h+1)/b,(g+1)/c),s=new THREE.Vector2(h/b,(g+1)/c),e.push(new THREE.Face3(a,d,k)),f.push([q,r,s]),e.push(new THREE.Face3(d,l,k)),
|
||||
f.push([r.clone(),t,s.clone()]);this.computeFaceNormals();this.computeVertexNormals()};THREE.ParametricGeometry.prototype=Object.create(THREE.Geometry.prototype);
|
||||
THREE.AxisHelper=function(a){a=a||1;var b=new Float32Array([0,0,0,a,0,0,0,0,0,0,a,0,0,0,0,0,0,a]),c=new Float32Array([1,0,0,1,0.6,0,0,1,0,0.6,1,0,0,0,1,0,0.6,1]);a=new THREE.BufferGeometry;a.addAttribute("position",new THREE.BufferAttribute(b,3));a.addAttribute("color",new THREE.BufferAttribute(c,3));b=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors});THREE.Line.call(this,a,b,THREE.LinePieces)};THREE.AxisHelper.prototype=Object.create(THREE.Line.prototype);
|
||||
THREE.ArrowHelper=function(){var a=new THREE.Geometry;a.vertices.push(new THREE.Vector3(0,0,0),new THREE.Vector3(0,1,0));var b=new THREE.CylinderGeometry(0,0.5,1,5,1);b.applyMatrix((new THREE.Matrix4).makeTranslation(0,-0.5,0));return function(c,d,e,f,g,h){THREE.Object3D.call(this);void 0===f&&(f=16776960);void 0===e&&(e=1);void 0===g&&(g=0.2*e);void 0===h&&(h=0.2*g);this.position.copy(d);this.line=new THREE.Line(a,new THREE.LineBasicMaterial({color:f}));this.line.matrixAutoUpdate=!1;this.add(this.line);
|
||||
THREE.AxisHelper=function(a){a=a||1;var b=new Float32Array([0,0,0,a,0,0,0,0,0,0,a,0,0,0,0,0,0,a]),c=new Float32Array([1,0,0,1,0.6,0,0,1,0,0.6,1,0,0,0,1,0,0.6,1]);a=new THREE.BufferGeometry;a.addAttribute("position",new THREE.BufferAttribute(b,3));a.addAttribute("color",new THREE.BufferAttribute(c,3));b=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors});THREE.Segment.call(this,a,b,THREE.LinePieces)};THREE.AxisHelper.prototype=Object.create(THREE.Segment.prototype);
|
||||
THREE.ArrowHelper=function(){var a=new THREE.Geometry;a.vertices.push(new THREE.Vector3(0,0,0),new THREE.Vector3(0,1,0));var b=new THREE.CylinderGeometry(0,0.5,1,5,1);b.applyMatrix((new THREE.Matrix4).makeTranslation(0,-0.5,0));return function(c,d,e,f,g,h){THREE.Object3D.call(this);void 0===f&&(f=16776960);void 0===e&&(e=1);void 0===g&&(g=0.2*e);void 0===h&&(h=0.2*g);this.position.copy(d);this.line=new THREE.Segment(a,new THREE.LineBasicMaterial({color:f}));this.line.matrixAutoUpdate=!1;this.add(this.line);
|
||||
this.cone=new THREE.Mesh(b,new THREE.MeshBasicMaterial({color:f}));this.cone.matrixAutoUpdate=!1;this.add(this.cone);this.setDirection(c);this.setLength(e,g,h)}}();THREE.ArrowHelper.prototype=Object.create(THREE.Object3D.prototype);THREE.ArrowHelper.prototype.setDirection=function(){var a=new THREE.Vector3,b;return function(c){0.99999<c.y?this.quaternion.set(0,0,0,1):-0.99999>c.y?this.quaternion.set(1,0,0,0):(a.set(c.z,0,-c.x).normalize(),b=Math.acos(c.y),this.quaternion.setFromAxisAngle(a,b))}}();
|
||||
THREE.ArrowHelper.prototype.setLength=function(a,b,c){void 0===b&&(b=0.2*a);void 0===c&&(c=0.2*b);this.line.scale.set(1,a,1);this.line.updateMatrix();this.cone.scale.set(c,b,c);this.cone.position.y=a;this.cone.updateMatrix()};THREE.ArrowHelper.prototype.setColor=function(a){this.line.material.color.set(a);this.cone.material.color.set(a)};
|
||||
THREE.BoxHelper=function(a){var b=new THREE.BufferGeometry;b.addAttribute("position",new THREE.BufferAttribute(new Float32Array(72),3));THREE.Line.call(this,b,new THREE.LineBasicMaterial({color:16776960}),THREE.LinePieces);void 0!==a&&this.update(a)};THREE.BoxHelper.prototype=Object.create(THREE.Line.prototype);
|
||||
THREE.BoxHelper=function(a){var b=new THREE.BufferGeometry;b.addAttribute("position",new THREE.BufferAttribute(new Float32Array(72),3));THREE.Segment.call(this,b,new THREE.LineBasicMaterial({color:16776960}),THREE.LinePieces);void 0!==a&&this.update(a)};THREE.BoxHelper.prototype=Object.create(THREE.Segment.prototype);
|
||||
THREE.BoxHelper.prototype.update=function(a){var b=a.geometry;null===b.boundingBox&&b.computeBoundingBox();var c=b.boundingBox.min,b=b.boundingBox.max,d=this.geometry.attributes.position.array;d[0]=b.x;d[1]=b.y;d[2]=b.z;d[3]=c.x;d[4]=b.y;d[5]=b.z;d[6]=c.x;d[7]=b.y;d[8]=b.z;d[9]=c.x;d[10]=c.y;d[11]=b.z;d[12]=c.x;d[13]=c.y;d[14]=b.z;d[15]=b.x;d[16]=c.y;d[17]=b.z;d[18]=b.x;d[19]=c.y;d[20]=b.z;d[21]=b.x;d[22]=b.y;d[23]=b.z;d[24]=b.x;d[25]=b.y;d[26]=c.z;d[27]=c.x;d[28]=b.y;d[29]=c.z;d[30]=c.x;d[31]=b.y;
|
||||
d[32]=c.z;d[33]=c.x;d[34]=c.y;d[35]=c.z;d[36]=c.x;d[37]=c.y;d[38]=c.z;d[39]=b.x;d[40]=c.y;d[41]=c.z;d[42]=b.x;d[43]=c.y;d[44]=c.z;d[45]=b.x;d[46]=b.y;d[47]=c.z;d[48]=b.x;d[49]=b.y;d[50]=b.z;d[51]=b.x;d[52]=b.y;d[53]=c.z;d[54]=c.x;d[55]=b.y;d[56]=b.z;d[57]=c.x;d[58]=b.y;d[59]=c.z;d[60]=c.x;d[61]=c.y;d[62]=b.z;d[63]=c.x;d[64]=c.y;d[65]=c.z;d[66]=b.x;d[67]=c.y;d[68]=b.z;d[69]=b.x;d[70]=c.y;d[71]=c.z;this.geometry.attributes.position.needsUpdate=!0;this.geometry.computeBoundingSphere();this.matrixAutoUpdate=
|
||||
!1;this.matrixWorld=a.matrixWorld};THREE.BoundingBoxHelper=function(a,b){var c=void 0!==b?b:8947848;this.object=a;this.box=new THREE.Box3;THREE.Mesh.call(this,new THREE.BoxGeometry(1,1,1),new THREE.MeshBasicMaterial({color:c,wireframe:!0}))};THREE.BoundingBoxHelper.prototype=Object.create(THREE.Mesh.prototype);THREE.BoundingBoxHelper.prototype.update=function(){this.box.setFromObject(this.object);this.box.size(this.scale);this.box.center(this.position)};
|
||||
THREE.CameraHelper=function(a){function b(a,b,d){c(a,d);c(b,d)}function c(a,b){d.vertices.push(new THREE.Vector3);d.colors.push(new THREE.Color(b));void 0===f[a]&&(f[a]=[]);f[a].push(d.vertices.length-1)}var d=new THREE.Geometry,e=new THREE.LineBasicMaterial({color:16777215,vertexColors:THREE.FaceColors}),f={};b("n1","n2",16755200);b("n2","n4",16755200);b("n4","n3",16755200);b("n3","n1",16755200);b("f1","f2",16755200);b("f2","f4",16755200);b("f4","f3",16755200);b("f3","f1",16755200);b("n1","f1",16755200);
|
||||
b("n2","f2",16755200);b("n3","f3",16755200);b("n4","f4",16755200);b("p","n1",16711680);b("p","n2",16711680);b("p","n3",16711680);b("p","n4",16711680);b("u1","u2",43775);b("u2","u3",43775);b("u3","u1",43775);b("c","t",16777215);b("p","c",3355443);b("cn1","cn2",3355443);b("cn3","cn4",3355443);b("cf1","cf2",3355443);b("cf3","cf4",3355443);THREE.Line.call(this,d,e,THREE.LinePieces);this.camera=a;this.matrixWorld=a.matrixWorld;this.matrixAutoUpdate=!1;this.pointMap=f;this.update()};
|
||||
THREE.CameraHelper.prototype=Object.create(THREE.Line.prototype);
|
||||
b("n2","f2",16755200);b("n3","f3",16755200);b("n4","f4",16755200);b("p","n1",16711680);b("p","n2",16711680);b("p","n3",16711680);b("p","n4",16711680);b("u1","u2",43775);b("u2","u3",43775);b("u3","u1",43775);b("c","t",16777215);b("p","c",3355443);b("cn1","cn2",3355443);b("cn3","cn4",3355443);b("cf1","cf2",3355443);b("cf3","cf4",3355443);THREE.Segment.call(this,d,e,THREE.LinePieces);this.camera=a;this.matrixWorld=a.matrixWorld;this.matrixAutoUpdate=!1;this.pointMap=f;this.update()};
|
||||
THREE.CameraHelper.prototype=Object.create(THREE.Segment.prototype);
|
||||
THREE.CameraHelper.prototype.update=function(){var a=new THREE.Vector3,b=new THREE.Camera,c=new THREE.Projector;return function(){function d(d,g,h,k){a.set(g,h,k);c.unprojectVector(a,b);d=e.pointMap[d];if(void 0!==d)for(g=0,h=d.length;g<h;g++)e.geometry.vertices[d[g]].copy(a)}var e=this;b.projectionMatrix.copy(this.camera.projectionMatrix);d("c",0,0,-1);d("t",0,0,1);d("n1",-1,-1,-1);d("n2",1,-1,-1);d("n3",-1,1,-1);d("n4",1,1,-1);d("f1",-1,-1,1);d("f2",1,-1,1);d("f3",-1,1,1);d("f4",1,1,1);d("u1",0.7,
|
||||
1.1,-1);d("u2",-0.7,1.1,-1);d("u3",0,2,-1);d("cf1",-1,0,1);d("cf2",1,0,1);d("cf3",0,-1,1);d("cf4",0,1,1);d("cn1",-1,0,-1);d("cn2",1,0,-1);d("cn3",0,-1,-1);d("cn4",0,1,-1);this.geometry.verticesNeedUpdate=!0}}();
|
||||
THREE.DirectionalLightHelper=function(a,b){THREE.Object3D.call(this);this.light=a;this.light.updateMatrixWorld();this.matrixWorld=a.matrixWorld;this.matrixAutoUpdate=!1;b=b||1;var c=new THREE.Geometry;c.vertices.push(new THREE.Vector3(-b,b,0),new THREE.Vector3(b,b,0),new THREE.Vector3(b,-b,0),new THREE.Vector3(-b,-b,0),new THREE.Vector3(-b,b,0));var d=new THREE.LineBasicMaterial({fog:!1});d.color.copy(this.light.color).multiplyScalar(this.light.intensity);this.lightPlane=new THREE.Line(c,d);this.add(this.lightPlane);
|
||||
c=new THREE.Geometry;c.vertices.push(new THREE.Vector3,new THREE.Vector3);d=new THREE.LineBasicMaterial({fog:!1});d.color.copy(this.light.color).multiplyScalar(this.light.intensity);this.targetLine=new THREE.Line(c,d);this.add(this.targetLine);this.update()};THREE.DirectionalLightHelper.prototype=Object.create(THREE.Object3D.prototype);
|
||||
THREE.DirectionalLightHelper=function(a,b){THREE.Object3D.call(this);this.light=a;this.light.updateMatrixWorld();this.matrixWorld=a.matrixWorld;this.matrixAutoUpdate=!1;b=b||1;var c=new THREE.Geometry;c.vertices.push(new THREE.Vector3(-b,b,0),new THREE.Vector3(b,b,0),new THREE.Vector3(b,-b,0),new THREE.Vector3(-b,-b,0),new THREE.Vector3(-b,b,0));var d=new THREE.LineBasicMaterial({fog:!1});d.color.copy(this.light.color).multiplyScalar(this.light.intensity);this.lightPlane=new THREE.Segment(c,d);this.add(this.lightPlane);
|
||||
c=new THREE.Geometry;c.vertices.push(new THREE.Vector3,new THREE.Vector3);d=new THREE.LineBasicMaterial({fog:!1});d.color.copy(this.light.color).multiplyScalar(this.light.intensity);this.targetLine=new THREE.Segment(c,d);this.add(this.targetLine);this.update()};THREE.DirectionalLightHelper.prototype=Object.create(THREE.Object3D.prototype);
|
||||
THREE.DirectionalLightHelper.prototype.dispose=function(){this.lightPlane.geometry.dispose();this.lightPlane.material.dispose();this.targetLine.geometry.dispose();this.targetLine.material.dispose()};
|
||||
THREE.DirectionalLightHelper.prototype.update=function(){var a=new THREE.Vector3,b=new THREE.Vector3,c=new THREE.Vector3;return function(){a.setFromMatrixPosition(this.light.matrixWorld);b.setFromMatrixPosition(this.light.target.matrixWorld);c.subVectors(b,a);this.lightPlane.lookAt(c);this.lightPlane.material.color.copy(this.light.color).multiplyScalar(this.light.intensity);this.targetLine.geometry.vertices[1].copy(c);this.targetLine.geometry.verticesNeedUpdate=!0;this.targetLine.material.color.copy(this.lightPlane.material.color)}}();
|
||||
THREE.EdgesHelper=function(a,b){var c=void 0!==b?b:16777215,d=[0,0],e={},f=function(a,b){return a-b},g=["a","b","c"],h=new THREE.BufferGeometry,k=a.geometry.clone();k.mergeVertices();k.computeFaceNormals();for(var l=k.vertices,k=k.faces,n=0,q=0,r=k.length;q<r;q++)for(var t=k[q],s=0;3>s;s++){d[0]=t[g[s]];d[1]=t[g[(s+1)%3]];d.sort(f);var p=d.toString();void 0===e[p]?(e[p]={vert1:d[0],vert2:d[1],face1:q,face2:void 0},n++):e[p].face2=q}h.addAttribute("position",new THREE.Float32Attribute(6*n,3));d=h.attributes.position.array;
|
||||
f=0;for(p in e)if(g=e[p],void 0===g.face2||0.9999>k[g.face1].normal.dot(k[g.face2].normal))n=l[g.vert1],d[f++]=n.x,d[f++]=n.y,d[f++]=n.z,n=l[g.vert2],d[f++]=n.x,d[f++]=n.y,d[f++]=n.z;THREE.Line.call(this,h,new THREE.LineBasicMaterial({color:c}),THREE.LinePieces);this.matrixAutoUpdate=!1;this.matrixWorld=a.matrixWorld};THREE.EdgesHelper.prototype=Object.create(THREE.Line.prototype);
|
||||
THREE.FaceNormalsHelper=function(a,b,c,d){this.object=a;this.size=void 0!==b?b:1;a=void 0!==c?c:16776960;d=void 0!==d?d:1;b=new THREE.Geometry;c=0;for(var e=this.object.geometry.faces.length;c<e;c++)b.vertices.push(new THREE.Vector3,new THREE.Vector3);THREE.Line.call(this,b,new THREE.LineBasicMaterial({color:a,linewidth:d}),THREE.LinePieces);this.matrixAutoUpdate=!1;this.normalMatrix=new THREE.Matrix3;this.update()};THREE.FaceNormalsHelper.prototype=Object.create(THREE.Line.prototype);
|
||||
f=0;for(p in e)if(g=e[p],void 0===g.face2||0.9999>k[g.face1].normal.dot(k[g.face2].normal))n=l[g.vert1],d[f++]=n.x,d[f++]=n.y,d[f++]=n.z,n=l[g.vert2],d[f++]=n.x,d[f++]=n.y,d[f++]=n.z;THREE.Segment.call(this,h,new THREE.LineBasicMaterial({color:c}),THREE.LinePieces);this.matrixAutoUpdate=!1;this.matrixWorld=a.matrixWorld};THREE.EdgesHelper.prototype=Object.create(THREE.Segment.prototype);
|
||||
THREE.FaceNormalsHelper=function(a,b,c,d){this.object=a;this.size=void 0!==b?b:1;a=void 0!==c?c:16776960;d=void 0!==d?d:1;b=new THREE.Geometry;c=0;for(var e=this.object.geometry.faces.length;c<e;c++)b.vertices.push(new THREE.Vector3,new THREE.Vector3);THREE.Segment.call(this,b,new THREE.LineBasicMaterial({color:a,linewidth:d}),THREE.LinePieces);this.matrixAutoUpdate=!1;this.normalMatrix=new THREE.Matrix3;this.update()};THREE.FaceNormalsHelper.prototype=Object.create(THREE.Segment.prototype);
|
||||
THREE.FaceNormalsHelper.prototype.update=function(){var a=this.geometry.vertices,b=this.object,c=b.geometry.vertices,d=b.geometry.faces,e=b.matrixWorld;b.updateMatrixWorld(!0);this.normalMatrix.getNormalMatrix(e);for(var f=b=0,g=d.length;b<g;b++,f+=2){var h=d[b];a[f].copy(c[h.a]).add(c[h.b]).add(c[h.c]).divideScalar(3).applyMatrix4(e);a[f+1].copy(h.normal).applyMatrix3(this.normalMatrix).normalize().multiplyScalar(this.size).add(a[f])}this.geometry.verticesNeedUpdate=!0;return this};
|
||||
THREE.GridHelper=function(a,b){var c=new THREE.Geometry,d=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors});this.color1=new THREE.Color(4473924);this.color2=new THREE.Color(8947848);for(var e=-a;e<=a;e+=b){c.vertices.push(new THREE.Vector3(-a,0,e),new THREE.Vector3(a,0,e),new THREE.Vector3(e,0,-a),new THREE.Vector3(e,0,a));var f=0===e?this.color1:this.color2;c.colors.push(f,f,f,f)}THREE.Line.call(this,c,d,THREE.LinePieces)};THREE.GridHelper.prototype=Object.create(THREE.Line.prototype);
|
||||
THREE.GridHelper=function(a,b){var c=new THREE.Geometry,d=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors});this.color1=new THREE.Color(4473924);this.color2=new THREE.Color(8947848);for(var e=-a;e<=a;e+=b){c.vertices.push(new THREE.Vector3(-a,0,e),new THREE.Vector3(a,0,e),new THREE.Vector3(e,0,-a),new THREE.Vector3(e,0,a));var f=0===e?this.color1:this.color2;c.colors.push(f,f,f,f)}THREE.Segment.call(this,c,d,THREE.LinePieces)};THREE.GridHelper.prototype=Object.create(THREE.Segment.prototype);
|
||||
THREE.GridHelper.prototype.setColors=function(a,b){this.color1.set(a);this.color2.set(b);this.geometry.colorsNeedUpdate=!0};
|
||||
THREE.HemisphereLightHelper=function(a,b,c,d){THREE.Object3D.call(this);this.light=a;this.light.updateMatrixWorld();this.matrixWorld=a.matrixWorld;this.matrixAutoUpdate=!1;this.colors=[new THREE.Color,new THREE.Color];a=new THREE.SphereGeometry(b,4,2);a.applyMatrix((new THREE.Matrix4).makeRotationX(-Math.PI/2));for(b=0;8>b;b++)a.faces[b].color=this.colors[4>b?0:1];b=new THREE.MeshBasicMaterial({vertexColors:THREE.FaceColors,wireframe:!0});this.lightSphere=new THREE.Mesh(a,b);this.add(this.lightSphere);
|
||||
this.update()};THREE.HemisphereLightHelper.prototype=Object.create(THREE.Object3D.prototype);THREE.HemisphereLightHelper.prototype.dispose=function(){this.lightSphere.geometry.dispose();this.lightSphere.material.dispose()};
|
||||
THREE.HemisphereLightHelper.prototype.update=function(){var a=new THREE.Vector3;return function(){this.colors[0].copy(this.light.color).multiplyScalar(this.light.intensity);this.colors[1].copy(this.light.groundColor).multiplyScalar(this.light.intensity);this.lightSphere.lookAt(a.setFromMatrixPosition(this.light.matrixWorld).negate());this.lightSphere.geometry.colorsNeedUpdate=!0}}();
|
||||
THREE.PointLightHelper=function(a,b){this.light=a;this.light.updateMatrixWorld();var c=new THREE.SphereGeometry(b,4,2),d=new THREE.MeshBasicMaterial({wireframe:!0,fog:!1});d.color.copy(this.light.color).multiplyScalar(this.light.intensity);THREE.Mesh.call(this,c,d);this.matrixWorld=this.light.matrixWorld;this.matrixAutoUpdate=!1};THREE.PointLightHelper.prototype=Object.create(THREE.Mesh.prototype);THREE.PointLightHelper.prototype.dispose=function(){this.geometry.dispose();this.material.dispose()};
|
||||
THREE.PointLightHelper.prototype.update=function(){this.material.color.copy(this.light.color).multiplyScalar(this.light.intensity)};
|
||||
THREE.SkeletonHelper=function(a){this.bones=this.getBoneList(a);for(var b=new THREE.Geometry,c=0;c<this.bones.length;c++)this.bones[c].parent instanceof THREE.Bone&&(b.vertices.push(new THREE.Vector3),b.vertices.push(new THREE.Vector3),b.colors.push(new THREE.Color(0,0,1)),b.colors.push(new THREE.Color(0,1,0)));c=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors,depthTest:!1,depthWrite:!1,transparent:!0});THREE.Line.call(this,b,c,THREE.LinePieces);this.root=a;this.matrixWorld=a.matrixWorld;
|
||||
this.matrixAutoUpdate=!1;this.update()};THREE.SkeletonHelper.prototype=Object.create(THREE.Line.prototype);THREE.SkeletonHelper.prototype.getBoneList=function(a){var b=[];a instanceof THREE.Bone&&b.push(a);for(var c=0;c<a.children.length;c++)b.push.apply(b,this.getBoneList(a.children[c]));return b};
|
||||
THREE.SkeletonHelper=function(a){this.bones=this.getBoneList(a);for(var b=new THREE.Geometry,c=0;c<this.bones.length;c++)this.bones[c].parent instanceof THREE.Bone&&(b.vertices.push(new THREE.Vector3),b.vertices.push(new THREE.Vector3),b.colors.push(new THREE.Color(0,0,1)),b.colors.push(new THREE.Color(0,1,0)));c=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors,depthTest:!1,depthWrite:!1,transparent:!0});THREE.Segment.call(this,b,c,THREE.LinePieces);this.root=a;this.matrixWorld=a.matrixWorld;
|
||||
this.matrixAutoUpdate=!1;this.update()};THREE.SkeletonHelper.prototype=Object.create(THREE.Segment.prototype);THREE.SkeletonHelper.prototype.getBoneList=function(a){var b=[];a instanceof THREE.Bone&&b.push(a);for(var c=0;c<a.children.length;c++)b.push.apply(b,this.getBoneList(a.children[c]));return b};
|
||||
THREE.SkeletonHelper.prototype.update=function(){for(var a=this.geometry,b=(new THREE.Matrix4).getInverse(this.root.matrixWorld),c=new THREE.Matrix4,d=0,e=0;e<this.bones.length;e++){var f=this.bones[e];f.parent instanceof THREE.Bone&&(c.multiplyMatrices(b,f.matrixWorld),a.vertices[d].setFromMatrixPosition(c),c.multiplyMatrices(b,f.parent.matrixWorld),a.vertices[d+1].setFromMatrixPosition(c),d+=2)}a.verticesNeedUpdate=!0;a.computeBoundingSphere()};
|
||||
THREE.SpotLightHelper=function(a){THREE.Object3D.call(this);this.light=a;this.light.updateMatrixWorld();this.matrixWorld=a.matrixWorld;this.matrixAutoUpdate=!1;a=new THREE.CylinderGeometry(0,1,1,8,1,!0);a.applyMatrix((new THREE.Matrix4).makeTranslation(0,-0.5,0));a.applyMatrix((new THREE.Matrix4).makeRotationX(-Math.PI/2));var b=new THREE.MeshBasicMaterial({wireframe:!0,fog:!1});this.cone=new THREE.Mesh(a,b);this.add(this.cone);this.update()};THREE.SpotLightHelper.prototype=Object.create(THREE.Object3D.prototype);
|
||||
THREE.SpotLightHelper.prototype.dispose=function(){this.cone.geometry.dispose();this.cone.material.dispose()};THREE.SpotLightHelper.prototype.update=function(){var a=new THREE.Vector3,b=new THREE.Vector3;return function(){var c=this.light.distance?this.light.distance:1E4,d=c*Math.tan(this.light.angle);this.cone.scale.set(d,d,c);a.setFromMatrixPosition(this.light.matrixWorld);b.setFromMatrixPosition(this.light.target.matrixWorld);this.cone.lookAt(b.sub(a));this.cone.material.color.copy(this.light.color).multiplyScalar(this.light.intensity)}}();
|
||||
THREE.VertexNormalsHelper=function(a,b,c,d){this.object=a;this.size=void 0!==b?b:1;b=void 0!==c?c:16711680;d=void 0!==d?d:1;c=new THREE.Geometry;a=a.geometry.faces;for(var e=0,f=a.length;e<f;e++)for(var g=0,h=a[e].vertexNormals.length;g<h;g++)c.vertices.push(new THREE.Vector3,new THREE.Vector3);THREE.Line.call(this,c,new THREE.LineBasicMaterial({color:b,linewidth:d}),THREE.LinePieces);this.matrixAutoUpdate=!1;this.normalMatrix=new THREE.Matrix3;this.update()};THREE.VertexNormalsHelper.prototype=Object.create(THREE.Line.prototype);
|
||||
THREE.VertexNormalsHelper=function(a,b,c,d){this.object=a;this.size=void 0!==b?b:1;b=void 0!==c?c:16711680;d=void 0!==d?d:1;c=new THREE.Geometry;a=a.geometry.faces;for(var e=0,f=a.length;e<f;e++)for(var g=0,h=a[e].vertexNormals.length;g<h;g++)c.vertices.push(new THREE.Vector3,new THREE.Vector3);THREE.Segment.call(this,c,new THREE.LineBasicMaterial({color:b,linewidth:d}),THREE.LinePieces);this.matrixAutoUpdate=!1;this.normalMatrix=new THREE.Matrix3;this.update()};THREE.VertexNormalsHelper.prototype=Object.create(THREE.Segment.prototype);
|
||||
THREE.VertexNormalsHelper.prototype.update=function(a){var b=new THREE.Vector3;return function(a){a=["a","b","c","d"];this.object.updateMatrixWorld(!0);this.normalMatrix.getNormalMatrix(this.object.matrixWorld);for(var d=this.geometry.vertices,e=this.object.geometry.vertices,f=this.object.geometry.faces,g=this.object.matrixWorld,h=0,k=0,l=f.length;k<l;k++)for(var n=f[k],q=0,r=n.vertexNormals.length;q<r;q++){var t=n.vertexNormals[q];d[h].copy(e[n[a[q]]]).applyMatrix4(g);b.copy(t).applyMatrix3(this.normalMatrix).normalize().multiplyScalar(this.size);
|
||||
b.add(d[h]);h+=1;d[h].copy(b);h+=1}this.geometry.verticesNeedUpdate=!0;return this}}();
|
||||
THREE.VertexTangentsHelper=function(a,b,c,d){this.object=a;this.size=void 0!==b?b:1;b=void 0!==c?c:255;d=void 0!==d?d:1;c=new THREE.Geometry;a=a.geometry.faces;for(var e=0,f=a.length;e<f;e++)for(var g=0,h=a[e].vertexTangents.length;g<h;g++)c.vertices.push(new THREE.Vector3),c.vertices.push(new THREE.Vector3);THREE.Line.call(this,c,new THREE.LineBasicMaterial({color:b,linewidth:d}),THREE.LinePieces);this.matrixAutoUpdate=!1;this.update()};THREE.VertexTangentsHelper.prototype=Object.create(THREE.Line.prototype);
|
||||
THREE.VertexTangentsHelper=function(a,b,c,d){this.object=a;this.size=void 0!==b?b:1;b=void 0!==c?c:255;d=void 0!==d?d:1;c=new THREE.Geometry;a=a.geometry.faces;for(var e=0,f=a.length;e<f;e++)for(var g=0,h=a[e].vertexTangents.length;g<h;g++)c.vertices.push(new THREE.Vector3),c.vertices.push(new THREE.Vector3);THREE.Segment.call(this,c,new THREE.LineBasicMaterial({color:b,linewidth:d}),THREE.LinePieces);this.matrixAutoUpdate=!1;this.update()};THREE.VertexTangentsHelper.prototype=Object.create(THREE.Segment.prototype);
|
||||
THREE.VertexTangentsHelper.prototype.update=function(a){var b=new THREE.Vector3;return function(a){a=["a","b","c","d"];this.object.updateMatrixWorld(!0);for(var d=this.geometry.vertices,e=this.object.geometry.vertices,f=this.object.geometry.faces,g=this.object.matrixWorld,h=0,k=0,l=f.length;k<l;k++)for(var n=f[k],q=0,r=n.vertexTangents.length;q<r;q++){var t=n.vertexTangents[q];d[h].copy(e[n[a[q]]]).applyMatrix4(g);b.copy(t).transformDirection(g).multiplyScalar(this.size);b.add(d[h]);h+=1;d[h].copy(b);
|
||||
h+=1}this.geometry.verticesNeedUpdate=!0;return this}}();
|
||||
THREE.WireframeHelper=function(a,b){var c=void 0!==b?b:16777215,d=[0,0],e={},f=function(a,b){return a-b},g=["a","b","c"],h=new THREE.BufferGeometry;if(a.geometry instanceof THREE.Geometry){for(var k=a.geometry.vertices,l=a.geometry.faces,n=0,q=new Uint32Array(6*l.length),r=0,t=l.length;r<t;r++)for(var s=l[r],p=0;3>p;p++){d[0]=s[g[p]];d[1]=s[g[(p+1)%3]];d.sort(f);var v=d.toString();void 0===e[v]&&(q[2*n]=d[0],q[2*n+1]=d[1],e[v]=!0,n++)}d=new Float32Array(6*n);r=0;for(t=n;r<t;r++)for(p=0;2>p;p++)n=
|
||||
k[q[2*r+p]],g=6*r+3*p,d[g+0]=n.x,d[g+1]=n.y,d[g+2]=n.z;h.addAttribute("position",new THREE.BufferAttribute(d,3))}else if(a.geometry instanceof THREE.BufferGeometry){if(void 0!==a.geometry.attributes.index){for(var k=a.geometry.attributes.position.array,t=a.geometry.attributes.index.array,l=a.geometry.offsets,n=0,q=new Uint32Array(2*t.length),s=0,w=l.length;s<w;++s)for(var p=l[s].start,v=l[s].count,g=l[s].index,r=p,u=p+v;r<u;r+=3)for(p=0;3>p;p++)d[0]=g+t[r+p],d[1]=g+t[r+(p+1)%3],d.sort(f),v=d.toString(),
|
||||
void 0===e[v]&&(q[2*n]=d[0],q[2*n+1]=d[1],e[v]=!0,n++);d=new Float32Array(6*n);r=0;for(t=n;r<t;r++)for(p=0;2>p;p++)g=6*r+3*p,n=3*q[2*r+p],d[g+0]=k[n],d[g+1]=k[n+1],d[g+2]=k[n+2]}else for(k=a.geometry.attributes.position.array,n=k.length/3,q=n/3,d=new Float32Array(6*n),r=0,t=q;r<t;r++)for(p=0;3>p;p++)g=18*r+6*p,q=9*r+3*p,d[g+0]=k[q],d[g+1]=k[q+1],d[g+2]=k[q+2],n=9*r+(p+1)%3*3,d[g+3]=k[n],d[g+4]=k[n+1],d[g+5]=k[n+2];h.addAttribute("position",new THREE.BufferAttribute(d,3))}THREE.Line.call(this,h,new THREE.LineBasicMaterial({color:c}),
|
||||
THREE.LinePieces);this.matrixAutoUpdate=!1;this.matrixWorld=a.matrixWorld};THREE.WireframeHelper.prototype=Object.create(THREE.Line.prototype);THREE.ImmediateRenderObject=function(){THREE.Object3D.call(this);this.render=function(a){}};THREE.ImmediateRenderObject.prototype=Object.create(THREE.Object3D.prototype);THREE.LensFlare=function(a,b,c,d,e){THREE.Object3D.call(this);this.lensFlares=[];this.positionScreen=new THREE.Vector3;this.customUpdateCallback=void 0;void 0!==a&&this.add(a,b,c,d,e)};
|
||||
void 0===e[v]&&(q[2*n]=d[0],q[2*n+1]=d[1],e[v]=!0,n++);d=new Float32Array(6*n);r=0;for(t=n;r<t;r++)for(p=0;2>p;p++)g=6*r+3*p,n=3*q[2*r+p],d[g+0]=k[n],d[g+1]=k[n+1],d[g+2]=k[n+2]}else for(k=a.geometry.attributes.position.array,n=k.length/3,q=n/3,d=new Float32Array(6*n),r=0,t=q;r<t;r++)for(p=0;3>p;p++)g=18*r+6*p,q=9*r+3*p,d[g+0]=k[q],d[g+1]=k[q+1],d[g+2]=k[q+2],n=9*r+(p+1)%3*3,d[g+3]=k[n],d[g+4]=k[n+1],d[g+5]=k[n+2];h.addAttribute("position",new THREE.BufferAttribute(d,3))}THREE.Segment.call(this,h,new THREE.LineBasicMaterial({color:c}),
|
||||
THREE.LinePieces);this.matrixAutoUpdate=!1;this.matrixWorld=a.matrixWorld};THREE.WireframeHelper.prototype=Object.create(THREE.Segment.prototype);THREE.ImmediateRenderObject=function(){THREE.Object3D.call(this);this.render=function(a){}};THREE.ImmediateRenderObject.prototype=Object.create(THREE.Object3D.prototype);THREE.LensFlare=function(a,b,c,d,e){THREE.Object3D.call(this);this.lensFlares=[];this.positionScreen=new THREE.Vector3;this.customUpdateCallback=void 0;void 0!==a&&this.add(a,b,c,d,e)};
|
||||
THREE.LensFlare.prototype=Object.create(THREE.Object3D.prototype);THREE.LensFlare.prototype.add=function(a,b,c,d,e,f){void 0===b&&(b=-1);void 0===c&&(c=0);void 0===f&&(f=1);void 0===e&&(e=new THREE.Color(16777215));void 0===d&&(d=THREE.NormalBlending);c=Math.min(c,Math.max(0,c));this.lensFlares.push({texture:a,size:b,distance:c,x:0,y:0,z:0,scale:1,rotation:1,opacity:f,color:e,blending:d})};
|
||||
THREE.LensFlare.prototype.updateLensFlares=function(){var a,b=this.lensFlares.length,c,d=2*-this.positionScreen.x,e=2*-this.positionScreen.y;for(a=0;a<b;a++)c=this.lensFlares[a],c.x=this.positionScreen.x+d*c.distance,c.y=this.positionScreen.y+e*c.distance,c.wantedRotation=c.x*Math.PI*0.25,c.rotation+=0.25*(c.wantedRotation-c.rotation)};
|
||||
THREE.MorphBlendMesh=function(a,b){THREE.Mesh.call(this,a,b);this.animationsMap={};this.animationsList=[];var c=this.geometry.morphTargets.length;this.createAnimation("__default",0,c-1,c/1);this.setAnimationWeight("__default",1)};THREE.MorphBlendMesh.prototype=Object.create(THREE.Mesh.prototype);
|
||||
|
|
|
|||
Loading…
Reference in a new issue