Skip to content

Commit 8749e5e

Browse files
committed
edit demos; etc.
1 parent 35da409 commit 8749e5e

10 files changed

+52
-34
lines changed

demos/background.html

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<head><meta name="viewport" content="user-scalable=no,initial-scale=1,maximum-scale=1">
77
<script type="text/javascript" src="../h3du_min.js"></script>
88
<script type="text/javascript" src="demoutil.js"></script>
9-
<script type="text/javascript" src="../extras/meshjson.js"></script>
109
</head>
1110
<body>
1211
<canvas id=canvas></canvas>

demos/clock.html

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<script type="text/javascript" src="../extras/camera.js"></script>
99
<script type="text/javascript" src="../extras/frame.js"></script>
1010
<script type="text/javascript" src="demoutil.js"></script>
11-
<script type="text/javascript" src="../extras/meshjson.js"></script>
1211
<script src="https://peteroupc.github.io/colorpicker/cbox.js"></script>
1312
</head>
1413
<body>

demos/curvesexpr.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<script type="text/javascript" src="../extras/camera.js"></script>
99
<script type="text/javascript" src="../extras/frame.js"></script>
1010
<script type="text/javascript" src="demoutil.js"></script>
11-
<script type="text/javascript" src="../extras/meshjson.js"></script>
1211
<script type="text/javascript" src="../extras/curvetube.js"></script>
1312
<script type="text/javascript" src="expressions.js"></script>
1413
</head>
@@ -52,7 +51,7 @@
5251
"use strict";
5352
var mesh = makeMesh(func, resolution, resolution);
5453
var otherWinding = H3DU.Meshes.reverseWinding(mesh).reverseNormals();
55-
return mesh.merge((otherWinding));
54+
return mesh.merge(otherWinding);
5655
}
5756

5857
function CustomCurve(x, y, z, minu, maxu) {

demos/demoutil.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function pushSettings(allsettings, shapeGroup, updateMeshFunc, settings) {
193193
}
194194

195195
/* exported makeMesh */
196-
function makeMesh(func, resolutionU, resolutionV) {
196+
function makeMesh(three, func, resolutionU, resolutionV) {
197197
// Default resolution is 50
198198
"use strict";
199199
if(typeof resolutionV === "undefined" || resolutionV === null)resolutionV = resolutionU;
@@ -211,15 +211,15 @@ function makeMesh(func, resolutionU, resolutionV) {
211211
};
212212
return new H3DU.SurfaceBuilder()
213213
.positionNormal(func)
214-
.attribute(colorGradient, H3DU.Semantic.COLOR)
214+
.attribute(colorGradient, "color")
215215
// Evaluate the surface and generate a triangle
216216
// mesh, using resolution+1 different u-coordinates,
217217
// and resolution+1 different v-coordinates.
218218
// Instead of H3DU.Mesh.TRIANGLES, we could use
219219
// H3DU.Mesh.LINES to create a wireframe mesh,
220220
// or H3DU.Mesh.POINTS to create a point mesh.
221221
.evalSurface(H3DU.Mesh.TRIANGLES, resolutionU, resolutionV)
222-
.toMeshBuffer();
222+
.toMeshBuffer(three);
223223
}
224224

225225
window.addEventListener("load", function() {
@@ -283,5 +283,3 @@ function makeAxisLines(width) {
283283
return xyz.addShape(xaxis).addShape(yaxis).addShape(zaxis)
284284
.addShape(xaxis2).addShape(yaxis2).addShape(zaxis2);
285285
}
286-
287-
document.write("<script src='../extras/meshjson.js'></script>");

demos/fallingballs.html

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
</style>
66
<script type="text/javascript" src="../h3du_min.js"></script>
77
<script type="text/javascript" src="demoutil.js"></script>
8-
<script type="text/javascript" src="../extras/meshjson.js"></script>
98
</head>
109
<body>
1110
<canvas id=canvas></canvas>

demos/implicit.html

-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
canvas { width:100%; height:100%; overflow: hidden; }
66
</style>
77
<script type="text/javascript" src="../h3du_min.js"></script>
8-
<script type="text/javascript" src="implicit.js"></script>
98
<script type="text/javascript" src="../extras/camera.js"></script>
109
<script type="text/javascript" src="../extras/frame.js"></script>
1110
<script type="text/javascript" src="demoutil.js"></script>
12-
<script type="text/javascript" src="../extras/meshjson.js"></script>
1311
</head>
1412
<body>
1513
<div style="position:absolute;left:0;top:1em" id=links>

demos/implicit.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@
88
// The following was adapted by Peter O. from public-domain
99
// source code by Cory Gene Bloyd.
1010

11+
function _Mesh() {
12+
this.nx=0
13+
this.ny=0
14+
this.nz=0
15+
this.m=0
16+
this.vertices=[]
17+
this.mode=function(m){
18+
this.m=m
19+
}
20+
this.normal3=function(x,y,z){
21+
this.nx=x
22+
this.ny=y
23+
this.nz=z
24+
}
25+
this.vertex3=function(x,y,z){
26+
this.vertices.push(x,y,z,this.nx,this.ny,this.nz)
27+
}
28+
}
29+
1130
/**
1231
* An evaluator for implicit surfaces.
1332
* @param {Object} func A <b>sampling object</b>. This object contains a single property,
@@ -553,8 +572,7 @@ ImplicitSurface.prototype.findBox = function(xsize, ysize, zsize, xmin, xmax, ym
553572
ImplicitSurface.prototype.evalSurfacePoints = function(mesh, xsize, ysize, zsize, xmin, xmax, ymin, ymax, zmin, zmax) {
554573
"use strict";
555574
if(xsize < 2 || ysize < 2 || zsize < 2)throw new Error();
556-
mesh.mode(H3DU.MeshBuffer.POINTS);
557-
575+
mesh.mode(0); // points
558576
const xstep = (xmax - xmin) / (xsize - 1);
559577
const ystep = (ymax - ymin) / (ysize - 1);
560578
const zstep = (zmax - zmin) / (zsize - 1);
@@ -593,7 +611,7 @@ ImplicitSurface.prototype.evalSurfacePoints = function(mesh, xsize, ysize, zsize
593611
*/
594612
ImplicitSurface.prototype.evalSurface = function(mesh, xsize, ysize, zsize, xmin, xmax, ymin, ymax, zmin, zmax) {
595613
"use strict";
596-
mesh.mode(H3DU.Mesh.TRIANGLES);
614+
mesh.mode(1); // triangles
597615
const tmpobj = {
598616
"asCubePosition":[[], [], [], [], [], [], [], []],
599617
"afCubeValue":[],

demos/surfacesexpr.html

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<script type="text/javascript" src="../extras/camera.js"></script>
99
<script type="text/javascript" src="../extras/frame.js"></script>
1010
<script type="text/javascript" src="demoutil.js"></script>
11-
<script type="text/javascript" src="../extras/meshjson.js"></script>
1211
<script type="text/javascript" src="expressions.js"></script>
1312
</head>
1413
<body>

extras/meshes/arrow.js

+4-18
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,6 @@ export const createArrow = function(three, shaftLength, pointerLength, shaftRadi
3939
return three.BufferGeometryUtils.mergeGeometries([shaft,base,pointer,pointerBase],false)
4040
}
4141

42-
function setColorBuffer(three,buffergeom,r,g,b){
43-
var color=toGLColor(r,g,b)
44-
var ret=[]
45-
var pos=0
46-
for(var i=0;i<buffergeom.index.count;i++,pos+=3){
47-
ret[pos]=color[0]
48-
ret[pos+1]=color[1]
49-
ret[pos+2]=color[2]
50-
}
51-
buffergeom.setAttribute("color",
52-
new three["BufferAttribute"](new Float32Array(ret),3))
53-
return buffergeom
54-
}
55-
5642
/**
5743
* TODO: Not documented yet.
5844
* @param {number} shaftLength
@@ -72,10 +58,10 @@ export const createMultiColoredArrow = function(three,shaftLength, pointerLength
7258
const pointer = Meshes.createCylinder(three,pointerRadius, 0, pointerLength, slices);
7359
const base = Meshes.createDisk(three,0, shaftRadius, slices, 1, true);
7460
const pointerBase = Meshes.createDisk(three,shaftRadius, pointerRadius, slices, 1, true);
75-
setBufferColor(three,shaft,shaftColor);
76-
setBufferColor(three,pointer,pointerColor);
77-
setBufferColor(three,base,shaftColor);
78-
setBufferColor(three,pointerBase,pointerColor);
61+
Meshes.setColor(three,shaft,shaftColor);
62+
Meshes.setColor(three,pointer,pointerColor);
63+
Meshes.setColor(three,base,shaftColor);
64+
Meshes.setColor(three,pointerBase,pointerColor);
7965
// move the pointer base to the top of the shaft
8066
pointerBase.applyMatrix4(matTo4D(three,MathUtil.mat4translated(0, 0, shaftLength)));
8167
// move the pointer to the top of the shaft

h3du-meshes.js

+23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import {MathUtil} from "./h3du-math.js";
7+
import {toGLColor} from "./h3du-misc.js";
78

89
/**
910
* Contains methods that create meshes
@@ -180,6 +181,28 @@ const TriangleFan = function(indices) {
180181
}
181182
};
182183
};
184+
/**
185+
* TODO: Not documented yet.
186+
* @param {*} three TODO: Not documented yet.
187+
* @param {*} buffer TODO: Not documented yet.
188+
* @param {*} r TODO: Not documented yet.
189+
* @param {*} g TODO: Not documented yet.
190+
* @param {*} b TODO: Not documented yet.
191+
* @returns {*} TODO: Not documented yet.
192+
*/
193+
Meshes.setColor=function(three,buffer,r,g,b){
194+
var color=toGLColor(r,g,b)
195+
var ret=[]
196+
var pos=0
197+
for(var i=0;i<buffer.index.count;i++,pos+=3){
198+
ret[pos]=color[0]
199+
ret[pos+1]=color[1]
200+
ret[pos+2]=color[2]
201+
}
202+
buffer.setAttribute("color",
203+
new three["BufferAttribute"](new Float32Array(ret),3))
204+
return buffergeom
205+
}
183206

184207
function normNormals(buffer) {
185208
buffer["normalizeNormals"]();

0 commit comments

Comments
 (0)