-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
167 lines (145 loc) · 6.52 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Teddy</title>
</head>
<body style="margin:0;padding:0">
<div align="center">
<canvas id="webglCanvas" style="width:100vw; height:100vh;" width=1000 height=1000></canvas>
<div style="position: absolute; bottom:20px; right:20px;">
<button class="button pointer" id="wireframeButton" ><img id="wireframeButtonIcon" width="25" height="25" src="images/th-large-solid.svg" style="fill: #cccccc;" alt="ShowWireframe"></button>
<button class="button pointer" id="clearButton" ><img width="25" height="25" style="fill: #cccccc;" src="images/undo-solid.svg" alt="Clear"></button>
<input class="button pointer" style="width:30px; height:30px; padding: 10px" type="color" id="colorPicker" value="#ff9d1c"/>
</div>
<div style="color: #838383;font-size: 12px; position: absolute; top:20px; left:20px;">
<div style="
font-size: 17px;
padding-bottom: 5px;
display: flex; flex-direction: row; justify-content:flex-start;">
Teddy: Modeling by Freeform Stroke
</div>
<div style="
padding-bottom: 5px;
display: flex; flex-direction: row; justify-content:flex-start;
align-items: center;">
Made by <u class="pointer" id="personalweblink">Zeya Peng</u>.  <img width="12" height="12" style="fill: #cccccc;" src="images/github-brands.svg" alt="Clear">  <u
class="pointer" id="repositorylink">zeyap/teddy</u>
</div>
<div style="
padding-bottom: 5px;
display: flex; flex-direction: row; justify-content:flex-start;">
Based on research of <u id="researchlink"
class="pointer" >Takeo Igarashi</u>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<link rel = "stylesheet" type = "text/css" href = "style.css"/>
<script src="js/gl-matrix-min.js"></script>
<script src="js/preloadjs-0.6.2.min.js"></script>
<script src="js/assetUtils.js"></script>
<script src="js/webGLUtils.js"></script>
<script src="js/algorithms/Delaunay.js"></script>
<script src="js/algorithms/Equalize.js"></script>
<script src="js/algorithms/cut.js"></script>
<script src="js/algorithms/pruneTrianglesAndElevateVertices.js"></script>
<script src="js/algorithms/selfIntersect.js"></script>
<script src="js/algorithm.js"></script>
<script src="js/scene.js"></script>
<script src="js/canvas.js"></script>
<script>
runWebGL();
function runWebGL(){
assetUtils.loadFiles([
{id:'frag',src:'./shaders/fragmentShader.frag'},
{id:'vert',src:'./shaders/vertexShader.vert'},
{id:'frag_line',src:'./shaders/fragmentShader_line.frag'},
{id:'vert_line',src:'./shaders/vertexShader_line.vert'},
{id:'frag_wire',src:'./shaders/fragmentShader_wireframe.frag'},
{id:'vert_wire',src:'./shaders/vertexShader_wireframe.vert'}],
(filesLoaded)=>{
const data = {}
data.fragmentShaderText = filesLoaded[0];
data.vertexShaderText = filesLoaded[1];
data.fragmentShaderLineText = filesLoaded[2];
data.vertexShaderLineText = filesLoaded[3];
data.fragmentShaderWireframeText = filesLoaded[4];
data.vertexShaderWireframeText = filesLoaded[5];
const updateWebGL = getUpdateFunction(data);
window.requestAnimationFrame(updateWebGL);
})
}
function getUpdateFunction(data){
webGLUtils.initializeWegGL('webglCanvas');
webGLUtils.createGlslProgram('program_line', data.vertexShaderLineText, data.fragmentShaderLineText,
{
uniforms:[{name:'color', type:'4fv'},],
attributes:[
{name:'vert_position'},
]
})
webGLUtils.createGlslProgram('program_wireframe', data.vertexShaderWireframeText, data.fragmentShaderWireframeText,
{
uniforms:[
{name:'xform_projMat', type:'Matrix4fv'},
{name:'xform_viewMat', type:'Matrix4fv'},
{name:'xform_modelMat', type:'Matrix4fv'},
{name:'color', type:'4fv'},
],
attributes:[
{name:'vert_position'},
]
})
webGLUtils.createGlslProgram('program0', data.vertexShaderText, data.fragmentShaderText,
{
uniforms:[
{name:'xform_projMat', type:'Matrix4fv'},
{name:'xform_viewMat', type:'Matrix4fv'},
{name:'xform_modelMat', type:'Matrix4fv'},
{name:'lightPos', type:'3fv'},
{name:'color', type:'4fv'},
],
attributes:[
{name:'vert_position'},
{name:'vert_normal'},
]
})
canvas.initializeMouseEvents();
const updateWebGL = ()=>{
scene.initCamera();
scene.initLights();
webGLUtils.clearScreen([0.9,0.9,0.9,1.0]);
//show stroke
webGLUtils.drawLine(canvas.getStroke(),'program_line',{
'color':vec4.fromValues(1.0,1.0,1.0,1.0),
},{
positionAttributeId:'vert_position',
})
webGLUtils.drawDots(canvas.getReferenceDotPositions(),
canvas.getReferenceDotScales(),'program_line',{
'color':vec4.fromValues(1.0,1.0,1.0,1.0),
},{
positionAttributeId:'vert_position',
})
if(canvas.getMode()!=='create'){
const wireframe = canvas.getIfShowWireframe();
// show object
webGLUtils.drawShape(scene.object.vertices, scene.object.indices, {},
wireframe?'program_wireframe':'program0', {
'xform_projMat':scene.view.projMat,
'xform_viewMat':scene.view.viewMat,
'xform_modelMat':scene.view.modelMat,
'lightPos':scene.view.lightPos,
'color':canvas.getColor(),
}, {positionAttributeId:'vert_position',normalAttributeId:'vert_normal'},wireframe)
}
window.requestAnimationFrame(updateWebGL);
}
return updateWebGL;
}
</script>
</body>
</html>