How to use boundBox method in taiko

Best JavaScript code snippet using taiko

PrimitiveUtil.js

Source:PrimitiveUtil.js Github

copy

Full Screen

1var createAttribParameter = function(name, count, datas, bufferType, type, normalized, stride, offset)2{3 return { name:name, datas:datas, bufferType:bufferType, count:count, type:type, normalized:normalized, stride:stride, offset:offset };4}5var GenerateNormal = function(vertices)6{7 var normals = [];8 for(var i=0;i<vertices.length/3;++i)9 {10 var curIndex = i * 3;11 var normal = CreateVec3(vertices[curIndex], vertices[curIndex+1], vertices[curIndex+2]).GetNormalize();12 normals.push(normal.x); normals.push(normal.y); normals.push(normal.z);13 }14 return normals;15}16var GenerateColor = function(color, count)17{18 var colors = [];19 for(var i=0;i<count;++i)20 {21 colors.push(color.x); colors.push(color.y); colors.push(color.z); colors.push(color.w);22 }23 return colors;24}25var GenerateBoundBox = function(vertices)26{27 var min = CreateVec3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);28 var max = CreateVec3(Number.MIN_VALUE, Number.MIN_VALUE, Number.MIN_VALUE);29 for(var i=0;i<vertices.length/3;++i)30 {31 var curIndex = i * 3;32 var x = vertices[curIndex];33 var y = vertices[curIndex + 1];34 var z = vertices[curIndex + 2];35 if (max.x < x)36 max.x = x;37 if (max.y < y)38 max.y = y;39 if (max.z < z)40 max.z = z;41 42 if (min.x > x)43 min.x = x;44 if (min.y > y)45 min.y = y;46 if (min.z > z)47 min.z = z;48 }49 return {min:min, max:max};50}51var CreateBoundBox = function(gl, TargetObjectArray, boundBox, color, scale, owner, shaderInfo)52{53 var vertices = [54 // 아래55 boundBox.min.x, boundBox.min.y, boundBox.min.z,56 boundBox.max.x, boundBox.min.y, boundBox.min.z,57 boundBox.max.x, boundBox.min.y, boundBox.min.z,58 boundBox.max.x, boundBox.min.y, boundBox.max.z,59 boundBox.max.x, boundBox.min.y, boundBox.max.z,60 boundBox.min.x, boundBox.min.y, boundBox.max.z,61 boundBox.min.x, boundBox.min.y, boundBox.max.z,62 boundBox.min.x, boundBox.min.y, boundBox.min.z,63 // 위64 boundBox.min.x, boundBox.max.y, boundBox.min.z,65 boundBox.max.x, boundBox.max.y, boundBox.min.z,66 boundBox.max.x, boundBox.max.y, boundBox.min.z,67 boundBox.max.x, boundBox.max.y, boundBox.max.z,68 boundBox.max.x, boundBox.max.y, boundBox.max.z,69 boundBox.min.x, boundBox.max.y, boundBox.max.z,70 boundBox.min.x, boundBox.max.y, boundBox.max.z,71 boundBox.min.x, boundBox.max.y, boundBox.min.z,72 // 옆73 boundBox.min.x, boundBox.min.y, boundBox.min.z,74 boundBox.min.x, boundBox.max.y, boundBox.min.z,75 boundBox.max.x, boundBox.min.y, boundBox.min.z,76 boundBox.max.x, boundBox.max.y, boundBox.min.z,77 boundBox.max.x, boundBox.min.y, boundBox.max.z,78 boundBox.max.x, boundBox.max.y, boundBox.max.z,79 boundBox.min.x, boundBox.max.y, boundBox.max.z,80 boundBox.min.x, boundBox.min.y, boundBox.max.z,81 ];82 var elementCount = vertices.length / 3;83 var attribs = [];84 attribs.push(createAttribParameter('Pos', 3, vertices, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));85 attribs.push(createAttribParameter('Color', 4, GenerateColor(color, elementCount), gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 4, 0));86 87 var newStaticObject = createStaticObject(gl, shaderInfo, attribs, null, 0, elementCount, gl.LINES);88 newStaticObject.pos = CreateVec3(0.0, 30.0, 0.0);89 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);90 newStaticObject.scale = CreateVec3(scale.x, scale.y, scale.z);91 addObject(TargetObjectArray, newStaticObject);92 newStaticObject.updateFunc = function()93 {94 this.pos = owner.pos.CloneVec3();95 this.rot = owner.rot.CloneVec3();96 this.scale = owner.scale.CloneVec3();97 this.hide = owner.hide || !ShowBoundBox || owner.hideBoundInfo;98 };99 newStaticObject.skipShadowMapGeneration = true;100 return newStaticObject; 101}102var GenerateBoundSphere = function(vertices)103{104 var maxDist = Number.MIN_VALUE;105 for(var i=0;i<vertices.length/3;++i)106 {107 var curIndex = i * 3;108 var x = vertices[curIndex];109 var y = vertices[curIndex + 1];110 var z = vertices[curIndex + 2];111 112 var currentPos = CreateVec3(x, y, z);113 const dist = currentPos.GetLength();114 if (maxDist < dist)115 maxDist = dist;116 }117 return {radius:maxDist};118}119var CreateBoundSphere = function(gl, TargetObjectArray, boundSphere, color, scale, owner, shaderInfo)120{121 var slice = 15;122 if (slice % 2)123 ++slice;124 var vertices = [];125 var stepRadian = DegreeToRadian(360.0 / slice);126 var halfSlice = parseInt(slice / 2);127 for(var j=0;j<=halfSlice;++j)128 {129 for(var i=0;i<=slice;++i)130 {131 var x = Math.cos(stepRadian * i) * boundSphere.radius * Math.sin(stepRadian * j);132 var y = Math.cos(stepRadian * j) * boundSphere.radius;133 var z = Math.sin(stepRadian * i) * boundSphere.radius * Math.sin(stepRadian * j);134 vertices.push(x); vertices.push(y); vertices.push(z);135 }136 }137 138 var elementCount = vertices.length / 3;139 var attribs = [];140 attribs.push(createAttribParameter('Pos', 3, vertices, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));141 attribs.push(createAttribParameter('Color', 4, GenerateColor(color, elementCount), gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 4, 0));142 var faces = [];143 var iCount = 0;144 var toNextSlice = slice+1;145 for(var j=0;j<=halfSlice;++j)146 {147 for(var i=0;i<(slice-1);++i, iCount += 1)148 {149 faces.push(iCount); faces.push(iCount + 1); faces.push(iCount + toNextSlice);150 faces.push(iCount + toNextSlice); faces.push(iCount + 1); faces.push(iCount + toNextSlice + 1);151 }152 }153 var newStaticObject = createStaticObject(gl, shaderInfo, attribs, {faces:faces, bufferType:gl.STATIC_DRAW}, 0, elementCount, gl.LINES);154 newStaticObject.pos = CreateVec3(0.0, 30.0, 0.0);155 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);156 newStaticObject.scale = CreateVec3(scale.x, scale.y, scale.z);157 addObject(TargetObjectArray, newStaticObject);158 newStaticObject.updateFunc = function()159 {160 this.pos = owner.pos.CloneVec3();161 this.rot = owner.rot.CloneVec3();162 this.scale = owner.scale.CloneVec3();163 this.hide = owner.hide || !ShowBoundSphere || owner.hideBoundInfo;164 };165 newStaticObject.skipShadowMapGeneration = true;166 return newStaticObject; 167}168var CreateCube = function(gl, TargetObjectArray, pos, size, scale, color, shaderInfo)169{170 var halfSize = size.CloneVec3().Div(2.0);171 var offset = ZeroVec3.CloneVec3();172 var vertices = [173 // z +174 offset.x + (-halfSize.x), offset.y + (halfSize.y), offset.z + (halfSize.z), 175 offset.x + (-halfSize.x), offset.y + (-halfSize.y), offset.z + (halfSize.z), 176 offset.x + (halfSize.x), offset.y + (halfSize.y), offset.z + (halfSize.z), 177 offset.x + (halfSize.x), offset.y + (halfSize.y), offset.z + (halfSize.z), 178 offset.x + (-halfSize.x), offset.y + (-halfSize.y), offset.z + (halfSize.z), 179 offset.x + (halfSize.x), offset.y + (-halfSize.y), offset.z + (halfSize.z), 180 // z -181 offset.x + (-halfSize.x), offset.y + (halfSize.y), offset.z + (-halfSize.z), 182 offset.x + (halfSize.x), offset.y + (halfSize.y), offset.z + (-halfSize.z), 183 offset.x + (-halfSize.x), offset.y + (-halfSize.y), offset.z + (-halfSize.z), 184 offset.x + (halfSize.x), offset.y + (halfSize.y), offset.z + (-halfSize.z), 185 offset.x + (halfSize.x), offset.y + (-halfSize.y), offset.z + (-halfSize.z), 186 offset.x + (-halfSize.x), offset.y + (-halfSize.y), offset.z + (-halfSize.z), 187 // x +188 offset.x + (halfSize.x), offset.y + (halfSize.y), offset.z + (halfSize.z), 189 offset.x + (halfSize.x), offset.y + (-halfSize.y), offset.z + (halfSize.z), 190 offset.x + (halfSize.x), offset.y + (halfSize.y), offset.z + (-halfSize.z), 191 offset.x + (halfSize.x), offset.y + (halfSize.y), offset.z + (-halfSize.z), 192 offset.x + (halfSize.x), offset.y + (-halfSize.y), offset.z + (halfSize.z), 193 offset.x + (halfSize.x), offset.y + (-halfSize.y), offset.z + (-halfSize.z), 194 195 // x -196 offset.x + (-halfSize.x), offset.y + (halfSize.y), offset.z + (-halfSize.z), 197 offset.x + (-halfSize.x), offset.y + (-halfSize.y), offset.z + (-halfSize.z), 198 offset.x + (-halfSize.x), offset.y + (halfSize.y), offset.z + (halfSize.z), 199 offset.x + (-halfSize.x), offset.y + (halfSize.y), offset.z + (halfSize.z), 200 offset.x + (-halfSize.x), offset.y + (-halfSize.y), offset.z + (-halfSize.z), 201 offset.x + (-halfSize.x), offset.y + (-halfSize.y), offset.z + (halfSize.z), 202 // y +203 offset.x + (-halfSize.x), offset.y + (halfSize.y), offset.z + (-halfSize.z), 204 offset.x + (-halfSize.x), offset.y + (halfSize.y), offset.z + (halfSize.z), 205 offset.x + (halfSize.x), offset.y + (halfSize.y), offset.z + (-halfSize.z), 206 offset.x + (halfSize.x), offset.y + (halfSize.y), offset.z + (-halfSize.z), 207 offset.x + (-halfSize.x), offset.y + (halfSize.y), offset.z + (halfSize.z), 208 offset.x + (halfSize.x), offset.y + (halfSize.y), offset.z + (halfSize.z), 209 // y -210 offset.x + (-halfSize.x), offset.y + (-halfSize.y), offset.z + (halfSize.z), 211 offset.x + (-halfSize.x), offset.y + (-halfSize.y), offset.z + (-halfSize.z), 212 offset.x + (halfSize.x), offset.y + (-halfSize.y), offset.z + (halfSize.z), 213 offset.x + (halfSize.x), offset.y + (-halfSize.y), offset.z + (halfSize.z), 214 offset.x + (-halfSize.x), offset.y + (-halfSize.y), offset.z + (-halfSize.z), 215 offset.x + (halfSize.x), offset.y + (-halfSize.y), offset.z + (-halfSize.z), 216 ];217 var elementCount = vertices.length / 3;218 var attribs = [];219 attribs.push(createAttribParameter('Pos', 3, vertices, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));220 attribs.push(createAttribParameter('Color', 4, GenerateColor(color, elementCount), gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 4, 0));221 {222 var normals = [223 0.0, 0.0, 1.0,224 0.0, 0.0, 1.0,225 0.0, 0.0, 1.0,226 0.0, 0.0, 1.0,227 0.0, 0.0, 1.0,228 0.0, 0.0, 1.0,229 230 0.0, 0.0, -1.0,231 0.0, 0.0, -1.0,232 0.0, 0.0, -1.0,233 0.0, 0.0, -1.0,234 0.0, 0.0, -1.0,235 0.0, 0.0, -1.0,236 1.0, 0.0, 0.0,237 1.0, 0.0, 0.0,238 1.0, 0.0, 0.0,239 1.0, 0.0, 0.0,240 1.0, 0.0, 0.0,241 1.0, 0.0, 0.0,242 -1.0, 0.0, 0.0,243 -1.0, 0.0, 0.0,244 -1.0, 0.0, 0.0,245 -1.0, 0.0, 0.0,246 -1.0, 0.0, 0.0,247 -1.0, 0.0, 0.0,248 0.0, 1.0, 0.0,249 0.0, 1.0, 0.0,250 0.0, 1.0, 0.0,251 0.0, 1.0, 0.0,252 0.0, 1.0, 0.0,253 0.0, 1.0, 0.0,254 0.0, -1.0, 0.0,255 0.0, -1.0, 0.0,256 0.0, -1.0, 0.0,257 0.0, -1.0, 0.0,258 0.0, -1.0, 0.0,259 0.0, -1.0, 0.0,260 ];261 attribs.push(createAttribParameter('Normal', 3, normals, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));262 }263 264 var newStaticObject = createStaticObject(gl, shaderInfo, attribs, null, 0, elementCount, gl.TRIANGLES);265 CreateShadowVolume(newStaticObject, vertices, null, TargetObjectArray)266 newStaticObject.pos = CreateVec3(pos.x, pos.y, pos.z);267 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);268 newStaticObject.scale = CreateVec3(scale.x, scale.y, scale.z);269 addObject(TargetObjectArray, newStaticObject);270 CreateBoundBox(gl, TargetObjectArray, GenerateBoundBox(vertices), color, scale, newStaticObject, shaderInfo);271 CreateBoundSphere(gl, TargetObjectArray, GenerateBoundSphere(vertices), color, scale, newStaticObject, shaderInfo);272 return newStaticObject;273}274var CreateQuad = function(gl, TargetObjectArray, pos, size, scale, color, shaderInfo)275{276 var halfSize = size.CloneVec3().Div(2.0);277 var offset = ZeroVec3.CloneVec3();278 var vertices = [279 offset.x + (halfSize.x), 0.0, offset.z + (-halfSize.z),280 offset.x + (-halfSize.x), 0.0, offset.z + (-halfSize.z),281 offset.x + (halfSize.x), 0.0, offset.z + (halfSize.z), 282 offset.x + (halfSize.x), 0.0, offset.z + (halfSize.z), 283 offset.x + (-halfSize.x), 0.0, offset.z + (-halfSize.z),284 offset.x + (-halfSize.x), 0.0, offset.z + (halfSize.z), 285 ];286 var elementCount = vertices.length / 3;287 var attribs = [];288 attribs.push(createAttribParameter('Pos', 3, vertices, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));289 attribs.push(createAttribParameter('Color', 4, GenerateColor(color, elementCount), gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 4, 0));290 {291 var normals = [];292 for(var i=0;i<elementCount;++i)293 {294 normals.push(0.0); normals.push(1.0); normals.push(0.0);295 }296 attribs.push(createAttribParameter('Normal', 3, normals, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));297 }298 var newStaticObject = createStaticObject(gl, shaderInfo, attribs, null, 0, elementCount, gl.TRIANGLES, true);299 CreateShadowVolume(newStaticObject, vertices, null, TargetObjectArray);300 newStaticObject.pos = CreateVec3(pos.x, pos.y, pos.z);301 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);302 newStaticObject.scale = CreateVec3(scale.x, scale.y, scale.z);303 newStaticObject.plane = null;304 newStaticObject.setPlane = function(plane)305 {306 if (!plane)307 return;308 309 this.plane = plane.ClonePlane();310 this.rot = GetEulerAngleFromVec3(plane.n);311 this.pos = plane.n.CloneVec3().Mul(plane.d);312 };313 addObject(TargetObjectArray, newStaticObject);314 CreateBoundBox(gl, TargetObjectArray, GenerateBoundBox(vertices), color, scale, newStaticObject, shaderInfo);315 CreateBoundSphere(gl, TargetObjectArray, GenerateBoundSphere(vertices), color, scale, newStaticObject, shaderInfo);316 return newStaticObject;317}318var CreateTriangle = function(gl, TargetObjectArray, pos, size, scale, color, shaderInfo)319{320 var halfSize = size.CloneVec3().Div(2.0);321 var offset = ZeroVec3.CloneVec3();322 var vertices = [323 offset.x + (halfSize.x), 0.0, offset.z + (-halfSize.z),324 offset.x + (-halfSize.x), 0.0, offset.z + (-halfSize.z),325 offset.x + (halfSize.x), 0.0, offset.z + (halfSize.z), 326 ];327 var elementCount = vertices.length / 3;328 var attribs = [];329 attribs.push(createAttribParameter('Pos', 3, vertices, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));330 attribs.push(createAttribParameter('Color', 4, GenerateColor(color, elementCount), gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 4, 0));331 {332 var normals = [];333 for(var i=0;i<elementCount;++i)334 {335 normals.push(0.0); normals.push(1.0); normals.push(0.0);336 }337 attribs.push(createAttribParameter('Normal', 3, normals, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));338 }339 var newStaticObject = createStaticObject(gl, shaderInfo, attribs, null, 0, elementCount, gl.TRIANGLES, true);340 CreateShadowVolume(newStaticObject, vertices, null, TargetObjectArray);341 newStaticObject.pos = CreateVec3(pos.x, pos.y, pos.z);342 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);343 newStaticObject.scale = CreateVec3(scale.x, scale.y, scale.z);344 addObject(TargetObjectArray, newStaticObject);345 CreateBoundBox(gl, TargetObjectArray, GenerateBoundBox(vertices), color, scale, newStaticObject, shaderInfo);346 CreateBoundSphere(gl, TargetObjectArray, GenerateBoundSphere(vertices), color, scale, newStaticObject, shaderInfo);347 return newStaticObject;348}349var CreateSphere = function(gl, TargetObjectArray, pos, radius, slice, scale, color, shaderInfo, wireframe = false)350{351 var vertices = [];352 var offset = ZeroVec3;353 if (slice % 2)354 ++slice;355 var stepRadian = DegreeToRadian(360.0 / slice);356 var halfSlice = parseInt(slice / 2);357 for(var j=0;j<=halfSlice;++j)358 {359 for(var i=0;i<=slice;++i)360 {361 var x = offset.x + Math.cos(stepRadian * i) * radius * Math.sin(stepRadian * j);362 var y = offset.z + Math.cos(stepRadian * j) * radius;363 var z = offset.y + Math.sin(stepRadian * i) * radius * Math.sin(stepRadian * j);364 vertices.push(x); vertices.push(y); vertices.push(z);365 }366 }367 var elementCount = vertices.length / 3;368 var attribs = [];369 attribs.push(createAttribParameter('Pos', 3, vertices, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));370 attribs.push(createAttribParameter('Color', 4, GenerateColor(color, elementCount), gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 4, 0));371 attribs.push(createAttribParameter('Normal', 3, GenerateNormal(vertices), gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));372 var faces = [];373 var iCount = 0;374 var toNextSlice = slice+1;375 for(var j=0;j<=halfSlice;++j)376 {377 for(var i=0;i<(slice-1);++i, iCount += 1)378 {379 faces.push(iCount); faces.push(iCount + 1); faces.push(iCount + toNextSlice);380 faces.push(iCount + toNextSlice); faces.push(iCount + 1); faces.push(iCount + toNextSlice + 1);381 }382 }383 var newStaticObject = createStaticObject(gl, shaderInfo, attribs, {faces:faces, bufferType:gl.STATIC_DRAW}, 0, elementCount, (wireframe ? gl.LINES : gl.TRIANGLES));384 CreateShadowVolume(newStaticObject, vertices, faces, TargetObjectArray);385 // 잘 그려진다면, 스텐실 버퍼에 operation 연산을 사용해서 volume을 그리고, 스텐실 버퍼 값을 이용해 물체를 그린다.386 newStaticObject.pos = CreateVec3(pos.x, pos.y, pos.z);387 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);388 newStaticObject.scale = CreateVec3(scale.x, scale.y, scale.z);389 addObject(TargetObjectArray, newStaticObject);390 //newStaticObject.hide = true;391 CreateBoundBox(gl, TargetObjectArray, GenerateBoundBox(vertices), color, scale, newStaticObject, shaderInfo);392 CreateBoundSphere(gl, TargetObjectArray, {radius:radius}, color, scale, newStaticObject, shaderInfo);393 return newStaticObject;394}395var CreateTile = function(gl, TargetObjectArray, pos, numOfCol, numOfRow, size, scale, color, shaderInfo)396{397 var vertices = [];398 var offset = ZeroVec3;399 var startPos = CreateVec3(offset.x, offset.y, offset.z);400 for(var i=0;i<numOfRow;++i)401 {402 for(var j=0;j<numOfCol;++j)403 {404 var curOffset = startPos.CloneVec3()405 curOffset.x += (j - numOfRow / 2.0) * size;406 curOffset.z += (i - numOfCol / 2.0) * size;407 var x = curOffset.x;408 var y = curOffset.y;409 var z = curOffset.z;410 vertices.push(x); vertices.push(y); vertices.push(z);411 x = curOffset.x;412 y = curOffset.y;413 z = curOffset.z + size;414 vertices.push(x); vertices.push(y); vertices.push(z);415 x = curOffset.x + size;416 y = curOffset.y;417 z = curOffset.z + size;418 vertices.push(x); vertices.push(y); vertices.push(z);419 x = curOffset.x;420 y = curOffset.y;421 z = curOffset.z;422 vertices.push(x); vertices.push(y); vertices.push(z);423 x = curOffset.x + size;424 y = curOffset.y425 z = curOffset.z + size;426 vertices.push(x); vertices.push(y); vertices.push(z);427 x = curOffset.x + size;428 y = curOffset.y;429 z = curOffset.z;430 vertices.push(x); vertices.push(y); vertices.push(z);431 }432 }433 var elementCount = vertices.length / 3;434 var attribs = [];435 attribs.push(createAttribParameter('Pos', 3, vertices, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));436 attribs.push(createAttribParameter('Color', 4, GenerateColor(color, elementCount), gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 4, 0));437 {438 var normals = [];439 for(var i=0;i<vertices.length;++i)440 {441 normals.push(0.0); normals.push(1.0); normals.push(0.0);442 }443 attribs.push(createAttribParameter('Normal', 3, normals, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));444 }445 var newStaticObject = createStaticObject(gl, shaderInfo, attribs, null, 0, elementCount, gl.TRIANGLES, true);446 CreateShadowVolume(newStaticObject, vertices, null, TargetObjectArray);447 newStaticObject.pos = CreateVec3(pos.x, pos.y, pos.z);448 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);449 newStaticObject.scale = CreateVec3(scale.x, scale.y, scale.z);450 addObject(TargetObjectArray, newStaticObject);451 CreateBoundBox(gl, TargetObjectArray, GenerateBoundBox(vertices), color, scale, newStaticObject, shaderInfo);452 CreateBoundSphere(gl, TargetObjectArray, GenerateBoundSphere(vertices), color, scale, newStaticObject, shaderInfo);453 return newStaticObject;454}455var CreateSegment = function(gl, TargetObjectArray, pos, start, end, time, color, shaderInfo)456{457 var currentEnd = null;458 if (time < 1.0)459 {460 var t = Clamp(time, 0.0, 1.0);461 currentEnd = end.CloneVec3().Sub(start);462 var length = currentEnd.GetLength();463 currentEnd = currentEnd.GetNormalize().Mul(t * length).Add(start);464 }465 else466 {467 currentEnd = end.CloneVec3();468 }469 var vertices = [470 start.x, start.y, start.z,471 currentEnd.x, currentEnd.y, currentEnd.z,472 ];473 var elementCount = vertices.length / 3;474 var attribs = [];475 attribs.push(createAttribParameter('Pos', 3, vertices, gl.DYNAMIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));476 attribs.push(createAttribParameter('Color', 4, GenerateColor(color, elementCount), gl.DYNAMIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 4, 0));477 attribs.push(createAttribParameter('Normal', 3, GenerateNormal(vertices), gl.DYNAMIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));478 var newStaticObject = createStaticObject(gl, shaderInfo, attribs, null, 0, elementCount, gl.LINES);479 480 newStaticObject.pos = CreateVec3(pos.x, pos.y, pos.z);481 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);482 newStaticObject.scale = CreateVec3(1.0, 1.0, 1.0);483 var segmentStaticObject = {};484 segmentStaticObject.__proto__ = newStaticObject;485 segmentStaticObject.start = start.CloneVec3();486 segmentStaticObject.end = end.CloneVec3();487 segmentStaticObject.color = color;488 segmentStaticObject.time = time;489 segmentStaticObject.getCurrentEnd = function()490 {491 var t = Clamp(this.time, 0.0, 1.0);492 var end = this.end.CloneVec3().Sub(this.start);493 return end.GetNormalize().Mul(t * end.GetLength()).Add(this.start);494 };495 segmentStaticObject.getDirectionNormalized = function()496 {497 return this.end.CloneVec3().Sub(this.start).GetNormalize();498 };499 addObject(TargetObjectArray, segmentStaticObject);500 return segmentStaticObject;501}502var UpdateSegmentTime = function(segment, t)503{504 var gl = segment.gl;505 segment.time = t;506 var end = segment.getCurrentEnd();507 var vertices = [508 segment.start.x, segment.start.y, segment.start.z,509 end.x, end.y, end.z,510 ];511 var colors = [512 segment.color.x, segment.color.y, segment.color.z, segment.color.w,513 segment.color.x, segment.color.y, segment.color.z, segment.color.w,514 ];515 gl.bindBuffer(gl.ARRAY_BUFFER, segment.attribs[0].vbo);516 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.DYNAMIC_DRAW);517 518 gl.bindBuffer(gl.ARRAY_BUFFER, segment.attribs[1].vbo);519 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(colors), gl.DYNAMIC_DRAW);520 gl.bindBuffer(gl.ARRAY_BUFFER, null);521};522var CreateCone = function(gl, TargetObjectArray, pos, height, radius, slice, scale, color, shaderInfo, wireframe = false)523{524 var halfHeight = height/2.0;525 var topVert = CreateVec3(0.0, halfHeight, 0.0);526 var bottomVert = CreateVec3(0.0, -halfHeight, 0.0);527 if (slice % 2)528 ++slice;529 var vertices = [];530 var stepRadian = DegreeToRadian(360.0 / slice);531 for(var i=1;i<=slice;++i)532 {533 var rad = i * stepRadian;534 var prevRad = rad - stepRadian;535 // Top536 vertices.push(topVert.x); vertices.push(topVert.y); vertices.push(topVert.z);537 vertices.push(Math.cos(rad)*radius); vertices.push(bottomVert.y); vertices.push(Math.sin(rad)*radius);538 vertices.push(Math.cos(prevRad)*radius); vertices.push(bottomVert.y); vertices.push(Math.sin(prevRad)*radius);539 // Bottom540 vertices.push(bottomVert.x); vertices.push(bottomVert.y); vertices.push(bottomVert.z);541 vertices.push(Math.cos(prevRad)*radius); vertices.push(bottomVert.y); vertices.push(Math.sin(prevRad)*radius);542 vertices.push(Math.cos(rad)*radius); vertices.push(bottomVert.y); vertices.push(Math.sin(rad)*radius);543 }544 var elementCount = vertices.length / 3;545 var attribs = [];546 attribs.push(createAttribParameter('Pos', 3, vertices, gl.DYNAMIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));547 attribs.push(createAttribParameter('Color', 4, GenerateColor(color, elementCount), gl.DYNAMIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 4, 0));548 {549 var normals = [];550 // https://stackoverflow.com/questions/51015286/how-can-i-calculate-the-normal-of-a-cone-face-in-opengl-4-5551 // lenght of the flank of the cone552 var flank_len = Math.sqrt(radius*radius + height*height); 553 // unit vector along the flank of the cone554 var cone_x = radius / flank_len; 555 var cone_y = -height / flank_len;556 557 // Cone Top Normal558 for(var i=1;i<=slice;++i)559 {560 var rad = i * stepRadian;561 var x = -cone_y * Math.cos(rad);562 var y = cone_x;563 var z = -cone_y * Math.sin(rad);564 // Top565 normals.push(x); normals.push(y); normals.push(z);566 normals.push(x); normals.push(y); normals.push(z);567 normals.push(x); normals.push(y); normals.push(z);568 // Bottom569 normals.push(0.0); normals.push(-1.0); normals.push(0.0);570 normals.push(0.0); normals.push(-1.0); normals.push(0.0);571 normals.push(0.0); normals.push(-1.0); normals.push(0.0);572 }573 /////////////////////////////////////////////////////574 attribs.push(createAttribParameter('Normal', 3, normals, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));575 }576 var newStaticObject = createStaticObject(gl, shaderInfo, attribs, null, 0, elementCount, (wireframe ? gl.LINES : gl.TRIANGLES));577 CreateShadowVolume(newStaticObject, vertices, null, TargetObjectArray);578 newStaticObject.pos = CreateVec3(pos.x, pos.y, pos.z);579 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);580 newStaticObject.scale = CreateVec3(scale.x, scale.y, scale.z);581 var coneStaticObject = {};582 coneStaticObject.__proto__ = newStaticObject;583 coneStaticObject.height = height;584 coneStaticObject.radius = radius;585 coneStaticObject.color = color;586 addObject(TargetObjectArray, coneStaticObject);587 CreateBoundBox(gl, TargetObjectArray, GenerateBoundBox(vertices), color, scale, coneStaticObject, shaderInfo);588 CreateBoundSphere(gl, TargetObjectArray, GenerateBoundSphere(vertices), color, scale, coneStaticObject, shaderInfo);589 return coneStaticObject;590}591var CreateCylinder = function(gl, TargetObjectArray, pos, height, radius, slice, scale, color, shaderInfo, wireframe = false)592{593 var halfHeight = height/2.0;594 var topVert = CreateVec3(0.0, halfHeight, 0.0);595 var bottomVert = CreateVec3(0.0, -halfHeight, 0.0);596 if (slice % 2)597 ++slice;598 var vertices = [];599 var stepRadian = DegreeToRadian(360.0 / slice);600 for(var i=0;i<slice;++i)601 {602 var rad = i * stepRadian;603 var prevRad = rad - stepRadian;604 // Top605 vertices.push(topVert.x); vertices.push(topVert.y); vertices.push(topVert.z);606 vertices.push(Math.cos(rad)*radius); vertices.push(topVert.y); vertices.push(Math.sin(rad)*radius);607 vertices.push(Math.cos(prevRad)*radius); vertices.push(topVert.y); vertices.push(Math.sin(prevRad)*radius);608 // Mid609 vertices.push(Math.cos(prevRad)*radius); vertices.push(topVert.y); vertices.push(Math.sin(prevRad)*radius);610 vertices.push(Math.cos(rad)*radius); vertices.push(topVert.y); vertices.push(Math.sin(rad)*radius);611 vertices.push(Math.cos(prevRad)*radius); vertices.push(bottomVert.y); vertices.push(Math.sin(prevRad)*radius);612 vertices.push(Math.cos(prevRad)*radius); vertices.push(bottomVert.y); vertices.push(Math.sin(prevRad)*radius);613 vertices.push(Math.cos(rad)*radius); vertices.push(topVert.y); vertices.push(Math.sin(rad)*radius);614 vertices.push(Math.cos(rad)*radius); vertices.push(bottomVert.y); vertices.push(Math.sin(rad)*radius);615 // Bottom616 vertices.push(bottomVert.x); vertices.push(bottomVert.y); vertices.push(bottomVert.z);617 vertices.push(Math.cos(prevRad)*radius); vertices.push(bottomVert.y); vertices.push(Math.sin(prevRad)*radius);618 vertices.push(Math.cos(rad)*radius); vertices.push(bottomVert.y); vertices.push(Math.sin(rad)*radius);619 }620 var elementCount = vertices.length / 3;621 var attribs = [];622 attribs.push(createAttribParameter('Pos', 3, vertices, gl.DYNAMIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));623 attribs.push(createAttribParameter('Color', 4, GenerateColor(color, elementCount), gl.DYNAMIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 4, 0));624 {625 var normals = [];626 // https://stackoverflow.com/questions/51015286/how-can-i-calculate-the-normal-of-a-cone-face-in-opengl-4-5627 // lenght of the flank of the cone628 var flank_len = Math.sqrt(radius*radius + height*height); 629 // unit vector along the flank of the cone630 var cone_x = radius / flank_len; 631 var cone_y = -height / flank_len;632 633 // Cone Top Normal634 for(var i=0;i<slice;++i)635 {636 var rad = i * stepRadian;637 var prevRad = rad - stepRadian;638 // Top639 normals.push(0.0); normals.push(1.0); normals.push(0.0);640 normals.push(0.0); normals.push(1.0); normals.push(0.0);641 normals.push(0.0); normals.push(1.0); normals.push(0.0);642 // Mid643 normals.push(Math.cos(prevRad)); normals.push(0.0); normals.push(Math.sin(prevRad));644 normals.push(Math.cos(rad)); normals.push(0.0); normals.push(Math.sin(rad));645 normals.push(Math.cos(prevRad)); normals.push(0.0); normals.push(Math.sin(prevRad));646 647 normals.push(Math.cos(prevRad)); normals.push(0.0); normals.push(Math.sin(prevRad));648 normals.push(Math.cos(rad)); normals.push(0.0); normals.push(Math.sin(rad));649 normals.push(Math.cos(rad)); normals.push(0.0); normals.push(Math.sin(rad));650 // Bottom651 normals.push(0.0); normals.push(-1.0); normals.push(0.0);652 normals.push(0.0); normals.push(-1.0); normals.push(0.0);653 normals.push(0.0); normals.push(-1.0); normals.push(0.0);654 }655 /////////////////////////////////////////////////////656 attribs.push(createAttribParameter('Normal', 3, normals, gl.DYNAMIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));657 }658 var newStaticObject = createStaticObject(gl, shaderInfo, attribs, null, 0, elementCount, (wireframe ? gl.LINES : gl.TRIANGLES));659 CreateShadowVolume(newStaticObject, vertices, null, TargetObjectArray);660 newStaticObject.pos = CreateVec3(pos.x, pos.y, pos.z);661 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);662 newStaticObject.scale = CreateVec3(scale.x, scale.y, scale.z);663 var cylinderStaticObject = {};664 cylinderStaticObject.__proto__ = newStaticObject;665 cylinderStaticObject.height = height;666 cylinderStaticObject.radius = radius;667 cylinderStaticObject.color = color;668 addObject(TargetObjectArray, cylinderStaticObject);669 CreateBoundBox(gl, TargetObjectArray, GenerateBoundBox(vertices), color, scale, newStaticObject, shaderInfo);670 CreateBoundSphere(gl, TargetObjectArray, GenerateBoundSphere(vertices), color, scale, newStaticObject, shaderInfo);671 return cylinderStaticObject;672}673var CreateArrowSegment = function(gl, TargetObjectArray, start, end, time, coneHeight, coneRadius, segmentColor, segmentShaderInfo, coneColor, coneShaderInfo)674{675 var segment = CreateSegment(gl, TargetObjectArray, ZeroVec3, start, end, time, segmentColor, segmentShaderInfo, false);676 segment.isDisablePipeLineChange = true;677 678 var cone = CreateCone(gl, TargetObjectArray, ZeroVec3, coneHeight, coneRadius, 100, OneVec3, coneColor, coneShaderInfo, false);679 cone.isDisablePipeLineChange = true;680 var newStaticObject = {updateFunc:null, drawFunc:null, segment:segment, cone:cone};681 newStaticObject.updateFunc = function()682 {683 var pos = null;684 if (this.pos)685 pos = this.pos.CloneVec3();686 else687 pos = OneVec3.CloneVec3();688 689 this.segment.pos = pos;690 this.cone.pos = pos.CloneVec3().Add(this.segment.getCurrentEnd());691 this.cone.rot = GetEulerAngleFromVec3(this.segment.getDirectionNormalized());692 this.cone.updateFunc();693 };694 newStaticObject.setHideBoundInfo = function(hide)695 {696 this.segment.hideBoundInfo = hide;697 this.cone.hideBoundInfo = hide;698 }699 newStaticObject.pos = OneVec3.CloneVec3();700 addObject(TargetObjectArray, newStaticObject);701 return newStaticObject;702}703var CreateCapsule = function(gl, TargetObjectArray, pos, height, radius, slice, scale, color, shaderInfo)704{705 if (height < 0)706 {707 height = 0.0;708 console.log("capsule height must be more than or equal zero.");709 }710 var halfHeight = height / 2;711 var vertices = [];712 var normals = [];713 if (slice % 2)714 ++slice;715 var stepRadian = DegreeToRadian(360.0 / slice);716 var halfSlice = parseInt(slice / 2);717 for(var j=0;j<=halfSlice;++j)718 {719 var isUpperSphere = (j > parseInt(halfSlice / 2));720 var isLowerSphere = (j < parseInt(halfSlice / 2));721 for(var i=0;i<=slice;++i)722 {723 var x = Math.cos(stepRadian * i) * radius * Math.sin(stepRadian * j);724 var y = Math.cos(stepRadian * j) * radius;725 var z = Math.sin(stepRadian * i) * radius * Math.sin(stepRadian * j);726 var yExt = 0.0;727 if (isUpperSphere)728 yExt = -halfHeight;729 if (isLowerSphere)730 yExt = halfHeight;731 vertices.push(x); vertices.push(y+yExt); vertices.push(z);732 var normal = null;733 if (!isUpperSphere && !isLowerSphere)734 normal = CreateVec3(x, 0.0, z).GetNormalize();735 else736 normal = CreateVec3(x, y, z).GetNormalize();737 normals.push(normal.x); normals.push(normal.y); normals.push(normal.z);738 }739 }740 var elementCount = vertices.length / 3;741 var attribs = [];742 attribs.push(createAttribParameter('Pos', 3, vertices, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));743 attribs.push(createAttribParameter('Color', 4, GenerateColor(color, elementCount), gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 4, 0));744 attribs.push(createAttribParameter('Normal', 3, normals, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0));745 var faces = [];746 var iCount = 0;747 var toNextSlice = slice+1;748 for(var j=0;j<=halfSlice;++j)749 {750 for(var i=0;i<(slice-1);++i, iCount += 1)751 {752 faces.push(iCount); faces.push(iCount + 1); faces.push(iCount + toNextSlice);753 faces.push(iCount + toNextSlice); faces.push(iCount + 1); faces.push(iCount + toNextSlice + 1);754 }755 }756 var newStaticObject = createStaticObject(gl, shaderInfo, attribs, {faces:faces, bufferType:gl.STATIC_DRAW}, 0, elementCount, gl.TRIANGLES);757 CreateShadowVolume(newStaticObject, vertices, faces, TargetObjectArray);758 newStaticObject.pos = CreateVec3(pos.x, pos.y, pos.z);759 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);760 newStaticObject.scale = CreateVec3(scale, scale, scale);761 addObject(TargetObjectArray, newStaticObject);762 CreateBoundBox(gl, TargetObjectArray, GenerateBoundBox(vertices), color, CreateVec3(scale, scale, scale), newStaticObject, shaderInfo);763 CreateBoundSphere(gl, TargetObjectArray, GenerateBoundSphere(vertices), color, scale, newStaticObject, shaderInfo);764 return newStaticObject;765}766var CreateGizmo = function(gl, TargetObjectArray, pos, rot, scale)767{768 var length = 5;769 var length2 = length*0.6;770 var vertices = [771 0.0, 0.0, 0.0, 772 0.0, 0.0, length, 773 0.0, 0.0, length, 774 length2/2, 0.0, length2, 775 0.0, 0.0, length, 776 -length2/2, 0.0, length2, 777 0.0, 0.0, 0.0, 778 length, 0.0, 0.0, 779 length, 0.0, 0.0, 780 length2, 0.0, length2/2, 781 length, 0.0, 0.0, 782 length2, 0.0, -length2/2,783 0.0, 0.0, 0.0, 784 0.0, length, 0.0, 785 0.0, length, 0.0, 786 length2/2, length2, 0.0, 787 0.0, length, 0.0, 788 -length2/2, length2, 0.0, 789 ]; 790 var colors = [791 0, 0, 1, 1,792 0, 0, 1, 1,793 0, 0, 1, 1,794 0, 0, 1, 1,795 0, 0, 1, 1,796 0, 0, 1, 1,797 1, 0, 0, 1,798 1, 0, 0, 1,799 1, 0, 0, 1,800 1, 0, 0, 1,801 1, 0, 0, 1,802 1, 0, 0, 1,803 0, 1, 0, 1,804 0, 1, 0, 1,805 0, 1, 0, 1,806 0, 1, 0, 1,807 0, 1, 0, 1,808 0, 1, 0, 1,809 ];810 var elementCount = vertices.length / 3;811 var attrib0 = createAttribParameter('Pos', 3, vertices, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0);812 var attrib1 = createAttribParameter('Color', 4, colors, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 4, 0);813 var newStaticObject = createStaticObject(gl, CreateBaseColorOnlyShaderFile(), [attrib0, attrib1], null, 0, elementCount, gl.LINES);814 newStaticObject.pos = pos.CloneVec3();815 newStaticObject.rot = rot.CloneVec3();816 newStaticObject.scale = scale.CloneVec3();817 addObject(TargetObjectArray, newStaticObject);818 newStaticObject.isDisablePipeLineChange = true;819 return newStaticObject;820}821var CreateCoordinateXZObject = function(gl, TargetObjectArray, camera)822{823 var count = 150;824 var interval = 10;825 var halfCount = count / 2.0;826 var vertices = [];827 var colors = [];828 var x;829 var z;830 for(var i=-halfCount;i<=halfCount;++i)831 {832 x = i * interval;833 for(var k=-halfCount;k<=halfCount;++k)834 {835 z = k * interval;836 vertices.push(x + 0.0); vertices.push(0.0); vertices.push(z + interval); colors.push(0.0); colors.push(0.0); colors.push(1.0); colors.push(0.3);837 vertices.push(x + 0.0); vertices.push(0.0); vertices.push(z + -interval); colors.push(0.0); colors.push(0.0); colors.push(1.0); colors.push(0.3);838 vertices.push(x + interval); vertices.push(0.0); vertices.push(z + 0.0); colors.push(1.0); colors.push(0.0); colors.push(0.0); colors.push(0.3);839 vertices.push(x + -interval); vertices.push(0.0); vertices.push(z + 0.0); colors.push(1.0); colors.push(0.0); colors.push(0.0); colors.push(0.3);840 }841 }842 var elementCount = vertices.length / 3;843 var attrib0 = createAttribParameter('Pos', 3, vertices, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0);844 var attrib1 = createAttribParameter('Color', 4, colors, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 4, 0);845 var newStaticObject = createStaticObject(gl, CreateBaseColorOnlyShaderFile(), [attrib0, attrib1], null, 0, elementCount, gl.LINES, false, true);846 newStaticObject.updateFunc = function()847 {848 this.pos.x = Math.floor(camera.pos.x / 10) * 10;849 this.pos.z = Math.floor(camera.pos.z / 10) * 10;850 };851 newStaticObject.pos = CreateVec3(0.0, 0.0, 0.0);852 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);853 newStaticObject.scale = CreateVec3(1.0, 1.0, 1.0);854 addObject(TargetObjectArray, newStaticObject);855 newStaticObject.isDisablePipeLineChange = true;856 return newStaticObject;857}858var CreateCoordinateYObject = function(gl, TargetObjectArray)859{860 var length = 500;861 var vertices = [862 0.0, length, 0.0,863 0.0, -length, 0.0,864 ];865 var colors = [866 0, 1, 0, 1,867 0, 1, 0, 1,868 ];869 var elementCount = vertices.length / 3;870 var attrib0 = createAttribParameter('Pos', 3, vertices, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0);871 var attrib1 = createAttribParameter('Color', 4, colors, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 4, 0);872 var newStaticObject = createStaticObject(gl, CreateBaseColorOnlyShaderFile(), [attrib0, attrib1], null, 0, elementCount, gl.LINES, false, true);873 newStaticObject.pos = CreateVec3(0.0, 0.0, 0.0);874 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);875 newStaticObject.scale = CreateVec3(1.0, 1.0, 1.0);876 addObject(TargetObjectArray, newStaticObject);877 newStaticObject.isDisablePipeLineChange = true;878 return newStaticObject;879}880var CreateUIQuad = function(gl, TargetObjectArray, x, y, width, height, texture)881{882 var vertices = [883 0.0, 1.0,884 1.0, 1.0,885 0.0, 0.0,886 1.0, 0.0,887 ];888 var elementCount = vertices.length / 2;889 var attrib0 = createAttribParameter('VertPos', 2, vertices, gl.DYNAMIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 2, 0);890 var newStaticObject = createStaticObject(gl, CreateBaseUIShaderFile(), [attrib0], null, 0, elementCount, gl.TRIANGLE_STRIP);891 var uiStaticObject = { UIInfo:CreateVec4(x, y, width, height) };892 uiStaticObject.__proto__ = newStaticObject;893 uiStaticObject.isDisablePipeLineChange = true;894 uiStaticObject.setRenderProperty = function()895 {896 if (this.__proto__.setRenderProperty)897 this.__proto__.setRenderProperty();898 var program = this.pipeLineInfo.pipeLine;899 var pixelSizeLoc = gl.getUniformLocation(program, 'PixelSize');900 if (pixelSizeLoc)901 {902 var pixelSize = [1.0 / gl.canvas.width, 1.0 / gl.canvas.height];903 gl.uniform2fv(pixelSizeLoc, pixelSize);904 }905 906 var posLoc = gl.getUniformLocation(program, 'Pos');907 if (posLoc)908 {909 var pos = [this.UIInfo.x, this.UIInfo.y];910 gl.uniform2fv(posLoc, pos);911 }912 913 var sizeLoc = gl.getUniformLocation(program, 'Size');914 if (sizeLoc)915 {916 var size = [this.UIInfo.z, this.UIInfo.w];917 gl.uniform2fv(sizeLoc, size);918 }919 };920 newStaticObject.texture = texture;921 newStaticObject.pos = CreateVec3(0, 0, 0.0);922 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);923 newStaticObject.scale = CreateVec3(1.0, 1.0, 1.0);924 addObject(TargetObjectArray, uiStaticObject);925 return uiStaticObject;926}927var CreateBillboardQuad = function(gl, TargetObjectArray, pos, size, scale, color, shaderInfo, camera = null)928{929 var quad = CreateQuad(gl, TargetObjectArray, pos, size, scale, color, shaderInfo);930 quad.camera = camera;931 quad.updateFunc = function()932 {933 if (this.camera)934 {935 var normalizedCameraDir = this.camera.pos.CloneVec3().Sub(this.pos).GetNormalize();936 var eularAngleOfCameraDir = GetEulerAngleFromVec3(normalizedCameraDir);937 this.rot.y = eularAngleOfCameraDir.y;938 this.rot.z = eularAngleOfCameraDir.z;939 }940 else941 {942 console.log('BillboardQuad is updated without camera');943 }944 }945 return quad;946}947var CreateQuadTexture = function(gl, TargetObjectArray, pos, size, scale, texture)948{949 var halfSize = size.CloneVec3().Div(2.0);950 var offset = ZeroVec3.CloneVec3();951 var vertices = [952 offset.x + (-halfSize.x), 0.0, offset.y + (halfSize.y), 953 offset.x + (halfSize.x), 0.0, offset.y + (halfSize.y), 954 offset.x + (-halfSize.x), 0.0, offset.y + (-halfSize.y), 955 offset.x + (halfSize.x), 0.0, offset.y + (-halfSize.y), 956 ];957 var elementCount = vertices.length / 3;958 var uvs = [959 0.0, 1.0,960 0.0, 0.0,961 1.0, 1.0,962 1.0, 0.0,963 ];964 var attrib0 = createAttribParameter('Pos', 3, vertices, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 3, 0);965 var attrib1 = createAttribParameter('TexCoord', 2, uvs, gl.STATIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * 2, 0);966 var newStaticObject = createStaticObject(gl, CreateBaseTextureShaderFile(), [attrib0, attrib1], null, 0, elementCount, gl.TRIANGLE_STRIP);967 newStaticObject.isDisablePipeLineChange = true;968 969 CreateShadowVolume(newStaticObject, vertices, null, TargetObjectArray);970 newStaticObject.pos = CreateVec3(pos.x, pos.y, pos.z);971 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);972 newStaticObject.scale = CreateVec3(scale.x, scale.y, scale.z);973 newStaticObject.texture = texture;974 if (TargetObjectArray)975 {976 addObject(TargetObjectArray, newStaticObject);977 CreateBoundBox(gl, TargetObjectArray, GenerateBoundBox(vertices), CreateVec4(0.0, 0.0, 0.0, 1.0), scale, newStaticObject, CreateBaseColorOnlyShaderFile());978 CreateBoundSphere(gl, TargetObjectArray, GenerateBoundSphere(vertices), CreateVec4(0.0, 0.0, 0.0, 1.0), scale, newStaticObject, CreateBaseColorOnlyShaderFile());979 }980 return newStaticObject;981}982var CreateBillboardQuadTexture = function(gl, TargetObjectArray, pos, size, scale, texture)983{984 var quad = CreateQuadTexture(gl, TargetObjectArray, pos, size, scale, texture);985 quad.camera = null;986 quad.updateFunc = function()987 {988 if (this.camera)989 {990 var normalizedCameraDir = this.camera.pos.CloneVec3().Sub(this.pos).GetNormalize();991 var eularAngleOfCameraDir = GetEulerAngleFromVec3(normalizedCameraDir);992 this.rot.y = eularAngleOfCameraDir.y;993 this.rot.z = eularAngleOfCameraDir.z;994 }995 else996 {997 console.log('BillboardQuad is updated without camera');998 }999 }1000 return quad;1001}1002var CreateFullScreenQuad = function(gl, TargetObjectArray, texture)1003{1004 var vertices = [0.0, 1.0, 2.0, 3.0];1005 var elementCount = vertices.length;1006 var attrib0 = createAttribParameter('VertID', 1, vertices, gl.DYNAMIC_DRAW, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT, 0);1007 var newStaticObject = createStaticObject(gl, CreateFullscreenBlurShaderFile(), [attrib0], null, 0, elementCount, gl.TRIANGLE_STRIP);1008 var uiStaticObject = { vertical:true, maxDist:0.0, texIndex:0.0 };1009 uiStaticObject.__proto__ = newStaticObject;1010 uiStaticObject.setRenderProperty = function()1011 {1012 if (this.__proto__.setRenderProperty)1013 this.__proto__.setRenderProperty();1014 var program = this.pipeLineInfo.pipeLine;1015 var pixelSizeLoc = gl.getUniformLocation(program, 'PixelSize');1016 if (pixelSizeLoc)1017 {1018 var pixelSize = [1.0 / gl.canvas.width, 1.0 / gl.canvas.height];1019 gl.uniform2fv(pixelSizeLoc, pixelSize);1020 }1021 1022 var verticalLoc = gl.getUniformLocation(program, 'Vertical');1023 if (verticalLoc)1024 {1025 gl.uniform1f(verticalLoc, this.vertical);1026 }1027 var maxDistLoc = gl.getUniformLocation(program, 'MaxDist');1028 if (maxDistLoc)1029 {1030 gl.uniform1f(maxDistLoc, this.maxDist);1031 }1032 var texIndexLoc = gl.getUniformLocation(program, 'TexIndex');1033 if (texIndexLoc)1034 {1035 gl.uniform1f(texIndexLoc, this.texIndex);1036 }1037 };1038 newStaticObject.texture = texture;1039 newStaticObject.pos = CreateVec3(0, 0, 0.0);1040 newStaticObject.rot = CreateVec3(0.0, 0.0, 0.0);1041 newStaticObject.scale = CreateVec3(1.0, 1.0, 1.0);1042 if (TargetObjectArray)1043 addObject(TargetObjectArray, uiStaticObject);1044 return uiStaticObject;...

Full Screen

Full Screen

vector-polygon.js

Source:vector-polygon.js Github

copy

Full Screen

1// Table indicating how to specify coloration of elements2// -------------------------------------------------------------------3// |Color | HexColor | DecimalColor | PercentColor |4// |Space | (string) | (array) | (string) |5// |------+------------+--------------------------------+--------------|6// | Gray | #GG | [gray] | %G |7// | RGB | #rrggbb | [red, green, blue] | %r,g,b |8// | CMYK | #ccmmyykk | [cyan, magenta, yellow, black] | %c,m,y,k |9// -------------------------------------------------------------------10//11// HexColor component values (two hex digits) range from 00 to FF.12// DecimalColor component values range from 0 to 255.13// PercentColor component values range from 1 to 100.14/**15 * Draw a polygon16 * @name polygon17 * @function18 * @memberof Recipe19 * @param {number[]} coordinates - The array of coordinate [[x,y], ... [m,n]]20 * @param {Object} [options] - The options21 * @param {string|number[]} [options.color] - HexColor, PercentColor or DecimalColor22 * @param {string|number[]} [options.stroke] - HexColor, PercentColor or DecimalColor23 * @param {string|number[]} [options.fill] - HexColor, PercentColor or DecimalColor24 * @param {number} [options.lineWidth] - The line width25 * @param {number} [options.opacity] - The opacity26 * @param {number[]} [options.dash] - The dash pattern [dashSize, gapSize] or [dashAndGapSize]27 * @param {number} [options.dashPhase] - distance into dash pattern at which to start dash (default: 0, immediately)28 * @param {number} [options.rotation] - Accept: +/- 0 through 360. Default: 029 * @param {number[]} [options.rotationOrigin] - [originX, originY] Default: x, y30 * @param {string} [options.lineCap] - open line end style, 'butt', 'round', or 'square' (default: 'round')31 * @param {string} [options.lineJoin] - joined line end style, 'miter', 'round', or 'bevel' (default: 'round')32 * @param {number} [options.miterLimit] - limit at which 'miter' joins are forced to 'bevel' (default: 1.414) */33exports.polygon = function polygon(coordinates = [], options = {}) {34 // close polygon35 if (this._getDistance(coordinates[0], coordinates[coordinates.length - 1]) != 0) {36 coordinates.push(coordinates[0]);37 }38 let boundBox = [ /*minX, minY, maxX, maxY*/ ];39 coordinates.forEach((coord, index) => {40 if (index === 0) {41 boundBox = [coord[0], coord[1], coord[0], coord[1]];42 }43 boundBox[0] = (boundBox[0] > coord[0]) ? coord[0] : boundBox[0];44 boundBox[1] = (boundBox[1] > coord[1]) ? coord[1] : boundBox[1];45 boundBox[2] = (boundBox[2] < coord[0]) ? coord[0] : boundBox[2];46 boundBox[3] = (boundBox[3] < coord[1]) ? coord[1] : boundBox[3];47 });48 if(options.deltaYY) {49 boundBox[3] += options.deltaYY;50 delete options['deltaYY']; // keeps other calls to here safe51 }52 const pathOptions = this._getPathOptions(options);53 let colorModel = pathOptions.colorModel;54 const margin = pathOptions.width * 2;55 const width = Math.abs(boundBox[2] - boundBox[0]) + margin * 2;56 const height = Math.abs(boundBox[3] - boundBox[1]) + margin * 2;57 const startX = boundBox[0] - margin;58 const startY = boundBox[1] + height - margin;59 const { nx, ny } = this._calibrateCoordinate(startX, startY);60 const drawPolygon = (context, coordinates) => {61 coordinates.forEach((coord, index) => {62 let nx = coord[0];63 let ny = coord[1];64 if (index === 0) {65 context.m(nx - startX, startY -ny );66 } else {67 context.l(nx - startX, startY -ny);68 }69 });70 };71 const setPathOptions = (context) => {72 context73 .J(pathOptions.lineCap)74 .j(pathOptions.lineJoin)75 .d(pathOptions.dash, pathOptions.dashPhase)76 .M(pathOptions.miterLimit);77 };78 pathOptions.originX = nx + width/2; // default rotation point79 pathOptions.originY = ny + height/2;80 if (options.fill) {81 if (pathOptions.fill !== undefined) {82 colorModel = pathOptions.fillModel;83 }84 this._drawObject(this, nx, ny, width, height, pathOptions, (ctx, xObject) => {85 ctx.gs(xObject.getGsName(pathOptions.fillGsId)),86 setPathOptions(ctx);87 xObject.fill(colorModel);88 drawPolygon(ctx, coordinates);89 ctx.f();90 });91 }92 if (options.stroke || options.color || !options.fill) {93 if (pathOptions.stroke !== undefined) {94 colorModel = pathOptions.strokeModel;95 }96 this._drawObject(this, nx, ny, width, height, pathOptions, (ctx, xObject) => {97 ctx.w(pathOptions.width);98 setPathOptions(ctx);99 xObject.stroke(colorModel);100 drawPolygon(ctx, coordinates);101 ctx.s();102 });103 }104 return this;...

Full Screen

Full Screen

BaseShape.ts

Source:BaseShape.ts Github

copy

Full Screen

1import { IClone } from "../../../IClone"2import { BoundBox } from "../../../../math/BoundBox"3import { Rand } from "../../../../math/Rand"4import { Vector2 } from "../../../../math/Vector2"5import { Vector3 } from "../../../../math/Vector3"6/**7 * <code>BaseShape</code> 类用于粒子形状。8 */9export class BaseShape implements IClone {10 /**是否启用。*/11 enable: boolean=true;12 /**随机方向。*/13 randomDirection: number=0;14 /**15 * 创建一个 <code>BaseShape</code> 实例。16 */17 constructor() {18 }19 /**@internal */20 protected _getShapeBoundBox(boundBox: BoundBox): void {21 throw new Error("BaseShape: must override it.");22 }23 /**@internal */24 protected _getSpeedBoundBox(boundBox: BoundBox): void {25 throw new Error("BaseShape: must override it.");26 }27 /**28 * 用于生成粒子初始位置和方向。29 * @param position 粒子位置。30 * @param direction 粒子方向。31 */32 generatePositionAndDirection(position: Vector3, direction: Vector3, rand: Rand = null, randomSeeds: Uint32Array = null): void {33 throw new Error("BaseShape: must override it.");34 }35 /** 36 * @internal 37 */38 _calculateProceduralBounds(boundBox: BoundBox, emitterPosScale: Vector3, minMaxBounds: Vector2): void {39 this._getShapeBoundBox(boundBox);40 var min: Vector3 = boundBox.min;41 var max: Vector3 = boundBox.max;42 Vector3.multiply(min, emitterPosScale, min);43 Vector3.multiply(max, emitterPosScale, max);44 var speedBounds: BoundBox = new BoundBox(new Vector3(), new Vector3());45 if (this.randomDirection/* && (m_Type != kCone) && (m_Type != kConeShell)*/)//TODO:randomDirection应换成0到146 {47 speedBounds.min = new Vector3(-1, -1, -1);48 speedBounds.max = new Vector3(1, 1, 1);49 //minMaxBounds = Abs(minMaxBounds);50 }51 else {52 this._getSpeedBoundBox(speedBounds);53 }54 var maxSpeedBound: BoundBox = new BoundBox(new Vector3(), new Vector3());55 var maxSpeedMin: Vector3 = maxSpeedBound.min;56 var maxSpeedMax: Vector3 = maxSpeedBound.max;57 Vector3.scale(speedBounds.min, minMaxBounds.y, maxSpeedMin);58 Vector3.scale(speedBounds.max, minMaxBounds.y, maxSpeedMax);59 Vector3.add(boundBox.min, maxSpeedMin, maxSpeedMin);60 Vector3.add(boundBox.max, maxSpeedMax, maxSpeedMax);61 Vector3.min(boundBox.min, maxSpeedMin, boundBox.min);62 Vector3.max(boundBox.max, maxSpeedMin, boundBox.max);63 var minSpeedBound: BoundBox = new BoundBox(new Vector3(), new Vector3());64 var minSpeedMin: Vector3 = minSpeedBound.min;65 var minSpeedMax: Vector3 = minSpeedBound.max;66 Vector3.scale(speedBounds.min, minMaxBounds.x, minSpeedMin);67 Vector3.scale(speedBounds.max, minMaxBounds.x, minSpeedMax);68 Vector3.min(minSpeedBound.min, minSpeedMax, maxSpeedMin);69 Vector3.max(minSpeedBound.min, minSpeedMax, maxSpeedMax);70 Vector3.min(boundBox.min, maxSpeedMin, boundBox.min);71 Vector3.max(boundBox.max, maxSpeedMin, boundBox.max);72 }73 /**74 * 克隆。75 * @param destObject 克隆源。76 */77 cloneTo(destObject: any): void {78 var destShape: BaseShape = (<BaseShape>destObject);79 destShape.enable = this.enable;80 }81 /**82 * 克隆。83 * @return 克隆副本。84 */85 clone(): any {86 var destShape: BaseShape = new BaseShape();87 this.cloneTo(destShape);88 return destShape;89 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, textBox, write, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await goto("google.com");6 await write("Taiko", into(textBox(boundingBox(0,0,100,100))));7 } catch (e) {8 console.error(e);9 } finally {10 await closeBrowser();11 }12})();13const { openBrowser, goto, textBox, write, closeBrowser } = require('taiko');14(async () => {15 try {16 await openBrowser();17 await goto("google.com");18 await write("Taiko", into(textBox(boundingBox(0,0,100,100))));19 } catch (e) {20 console.error(e);21 } finally {22 await closeBrowser();23 }24})();25const { openBrowser, goto, textBox, write, closeBrowser } = require('taiko');26(async () => {27 try {28 await openBrowser();29 await goto("google.com");30 await write("Taiko", into(textBox(boundingBox(0,0,100,100))));31 } catch (e) {32 console.error(e);33 } finally {34 await closeBrowser();35 }36})();37const { openBrowser, goto, textBox, write, closeBrowser } = require('taiko');38(async () => {39 try {40 await openBrowser();41 await goto("google.com");42 await write("Taiko", into(textBox(boundingBox(0,0,100,100))));43 } catch (e) {44 console.error(e);45 } finally {46 await closeBrowser();47 }48})();49const { openBrowser, goto, textBox, write, closeBrowser } = require('taiko');50(async () => {51 try {52 await openBrowser();53 await goto("google.com");54 await write("Taiko", into(textBox(boundingBox(0,0,100,100))));55 } catch (e) {56 console.error(e);57 } finally {58 await closeBrowser();59 }60})();61const { openBrowser, goto, textBox, write, closeBrowser } = require('taiko');62(async () => {63 try {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, write, click, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await write("Taiko");6 await click("Google Search");7 await click("Taiko - A Node.js test automation framework");8 await click(boundBox("Get started with Taiko"));9 await click("API Reference");10 await click("openBrowser");11 await click("closeBrowser");12 } catch (e) {13 console.error(e);14 } finally {15 await closeBrowser();16 }17})();18const { openBrowser, goto, write, click, closeBrowser } = require('taiko');19(async () => {20 try {21 await openBrowser();22 await write("Taiko");23 await click("Google Search");24 await click("Taiko - A Node.js test automation framework");25 await click(boundBox("Get started with Taiko"));26 await click("API Reference");27 await click("openBrowser");28 await click("closeBrowser");29 } catch (e) {30 console.error(e);31 } finally {32 await closeBrowser();33 }34})();35const { openBrowser, goto, write, click, closeBrowser } = require('taiko');36(async () => {37 try {38 await openBrowser();39 await write("Taiko");40 await click("Google Search");41 await click("Taiko - A Node.js test automation framework");42 await click(boundBox("Get started with Taiko"));43 await click("API Reference");44 await click("openBrowser");45 await click("closeBrowser");46 } catch (e) {47 console.error(e);48 } finally {49 await closeBrowser();50 }51})();52const { openBrowser, goto, write, click, closeBrowser } = require('taiko');53(async () => {54 try {55 await openBrowser();56 await write("Taiko");57 await click("Google Search");

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, closeBrowser, $ } = require('taiko');2(async () => {3 try {4 await openBrowser();5 let ele = await $("#gauge-logo");6 let box = await ele.boundingBox();7 console.log(box);8 } catch (e) {9 console.error(e);10 } finally {11 await closeBrowser();12 }13})();14{ x: 0, y: 0, width: 0, height: 0 }15const { openBrowser, goto, closeBrowser, $ } = require('taiko');16(async () => {17 try {18 await openBrowser();19 let ele = await $("#gauge-logo");20 let box = await ele.boundingBox();21 console.log(box);22 } catch (e) {23 console.error(e);24 } finally {25 await closeBrowser();26 }27})();28{ x: 0, y: 0, width: 0, height: 0 }29const { openBrowser, goto,

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, textBox, write, button, click, closeBrowser, toRightOf, toLeftOf, below, above, text, link, image, listItem, checkBox, radioButton, dropDown, focus, clear, closeTab, evaluate, reload, accept, dismiss, setConfig, setViewPort, screenshot, scrollDown, scrollUp, scrollRight, scrollLeft, scrollTo, textBoxes, buttons, links, images, listItems, checkBoxes, radioButtons, dropDowns, texts, to, into, hover, doubleClick, rightClick, dragAndDrop, mouseAction, highlight, focusElement, textArea, textAreas, fileField, fileField, toLeftOf, toRightOf, above, below, near, $, $$, waitFor, waitForNavigation, waitForElement, waitForText, reload, accept, dismiss, setConfig, setViewPort, screenshot, scrollDown, scrollUp, scrollRight, scrollLeft, scrollTo } = require('taiko');2(async () => {3 try {4 await openBrowser({headless:false});5 await write("Taiko", into(textBox(toRightOf("Google Search"))));6 await click("Google Search");7 await closeBrowser();8 } catch (e) {9 console.error(e);10 } finally {11 }12})();13const { openBrowser, goto, textBox, write, button, click, closeBrowser, toRightOf, toLeftOf, below, above, text, link, image, listItem, checkBox, radioButton, dropDown, focus, clear, closeTab, evaluate, reload, accept, dismiss, setConfig, setViewPort, screenshot, scrollDown, scrollUp, scrollRight, scrollLeft, scrollTo, textBoxes, buttons, links, images, listItems, checkBoxes, radioButtons, dropDowns, texts, to, into, hover, doubleClick, rightClick, dragAndDrop, mouseAction, highlight, focusElement, textArea, textAreas, fileField, fileField, toLeftOf, toRightOf, above, below, near, $, $$, waitFor, waitForNavigation, waitForElement, waitForText, reload, accept, dismiss, setConfig, setViewPort, screenshot, scrollDown, scrollUp, scrollRight, scrollLeft, scrollTo

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, click, closeBrowser, textBox, write, button, waitFor, toRightOf, toLeftOf, below, above, link, image, listItem, dropDown, checkBox, radioButton, text, focus, evaluate, $, $$, into, clear, accept, dismiss, to, reload, emulateDevice, screenshot, intercept, setConfig, setViewPort, highlight, scrollTo, scrollRight, scrollDown, scrollLeft, scrollUp, doubleClick, rightClick, hover, dragAndDrop, press, textArea, fileField, toBottom, toTop, within, browserDescription, currentURL, title, $x, $id, $class, $linkText, $name, $partialLinkText, $tagName, $css, $xpath, $text, $q } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await goto("www.google.com");6 await write("taiko", into(textBox(toRightOf("Google Search"))));7 await click(button("Google Search"));8 await waitFor(2000);9 await screenshot({ path: 'google.png' });10 await click(link("Taiko - A Node.js library for automating ..."));11 await waitFor(2000);12 await screenshot({ path: 'taiko.png' });13 await click(link("Documentation"));14 await waitFor(2000);15 await screenshot({ path: 'documentation.png' });16 await click(link("API Reference"));17 await waitFor(2000);18 await screenshot({ path: 'api.png' });19 await click(link("click"));20 await waitFor(2000);21 await screenshot({ path: 'click.png' });22 await click(link("API Reference"));23 await waitFor(2000);24 await screenshot({ path: 'api.png' });25 await click(link("click"));26 await waitFor(2000);27 await screenshot({ path: 'click.png' });28 await click(link("API Reference"));29 await waitFor(2000);30 await screenshot({ path: 'api.png' });31 await click(link("click"));32 await waitFor(2000);33 await screenshot({ path: 'click.png' });34 await click(link("API Reference"));35 await waitFor(2000);36 await screenshot({ path: 'api.png' });37 await click(link("click"));38 await waitFor(2000);39 await screenshot({ path:

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, closeBrowser, textBox, button, text, toRightOf, toLeftOf, below, above, write, clear, focus, link, dropDown, radioButton, checkBox, image, listItem, tableCell, inputField, fileField, dateField, timeField, passwordField, textArea, $, $$, evaluate } = require('taiko');2(async () => {3 try {4 await openBrowser({ headless: false });5 await write("taiko");6 await click("Google Search");7 await focus(textBox(toRightOf("Search")));8 await write("What is Taiko?");9 await focus(textBox(toLeftOf("Search")));10 await write("What is Taiko?");11 await focus(textBox(below("Search")));12 await write("What is Taiko?");13 await focus(textBox(above("Search")));14 await write("What is Taiko?");15 await focus(textBox({ id: "gsc-i-id1" }));16 await write("What is Taiko?");17 await focus(textBox({ class: "gsc-input" }));18 await write("What is Taiko?");19 await focus(textBox({ placeholder: "Search" }));20 await write("What is Taiko?");21 await focus(textBox({ placeholder: /Search/ }));22 await write("What is Taiko?");23 await focus(textBox({ name: "q" }));24 await write("What is Taiko?");25 await focus(textBox({ name: /q/ }));26 await write("What is Taiko?");27 await focus(textBox({ type: "text" }));28 await write("What is Taiko?");29 await focus(textBox({ type: /text/ }));30 await write("What is Taiko?");31 await focus(textBox({ id: /gsc-i-id1/ }));32 await write("What is Taiko?");33 await focus(textBox({ class: /gsc-input/ }));34 await write("What is Taiko?");35 await focus(textBox({ id: "gsc-i-id1", class: "gsc-input" }));36 await write("What is Taiko?");37 await focus(textBox({ id: "gsc-i-id1", class: "gsc-input", placeholder: "Search" }));38 await write("What is Taiko?");39 await focus(textBox({ id: "gsc-i-id1",

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, closeBrowser, button, toRightOf, text, link, write, image, below, toLeftOf, toLeft, toRight, into, $, into, focus, textBox, to, click, dropDown, listItem, fileField, checkBox, radioButton, clear } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await click("Taiko - Test Automation for Modern Web Applications");6 await click("Taiko API");7 await click("Browser");8 await click("openBrowser");9 await click("openBrowser");

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run taiko automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful