cacheCompiled functions are cached, requiresfilename
filenameUsed bycacheto key caches, and for includes
rootSet project root for includes with an absolute path (e.g, /file.ejs). Can be array to try to resolve include from multiple directories.
viewsAn array of paths to use when resolving includes with relative paths.
contextFunction execution context
compileDebugWhenfalseno debug instrumentation is compiled
clientReturns standalone compiled function
delimiterCharacter to use for inner delimiter, by default '%'
openDelimiterCharacter to use for opening delimiter, by default '<'
closeDelimiterCharacter to use for closing delimiter, by default '>'
debugOutputs generated function body
strictWhen set to `true`, generated function is in strict mode
_withWhether or not to usewith() {}constructs. Iffalsethen the locals will be stored in thelocalsobject. (Implies `--strict`)
localsNameName to use for the object storing local variables when not usingwithDefaults tolocals
rmWhitespaceRemove all safe-to-remove whitespace, including leading and trailing whitespace. It also enables a safer version of-%>line slurping for all scriptlet tags (it does not strip new lines of tags in the middle of a line).
escapeThe escaping function used with<%=construct. It is used in rendering and is.toString()ed in the generation of client functions. (By default escapes XML).
outputFunctionNameSet to a string (e.g.,'echo'or'print') for a function to print output inside scriptlet tags.
asyncWhentrue, EJS will use an async function for rendering. (Depends on async/await support in the JS runtime.Tags
<%'Scriptlet' tag, for control-flow, no output
<%_‘Whitespace Slurping’ Scriptlet tag, strips all whitespace before it
<%=Outputs the value into the template (HTML escaped)
<%-Outputs the unescaped value into the template
<%#Comment tag, no execution, no output
<%%Outputs a literal '<%'
%>Plain ending tag
-%>Trim-mode ('newline slurp') tag, trims following newline
_%>‘Whitespace Slurping’ ending tag, removes all whitespace after it
to가 절대경로가 아니면 절대경로를 찾을 때까지from아규먼트들을 우측에서 좌측의 순서로 앞에 이어붙힌다.모든from경로를 사용한 후에도 절대경로를 찾지 못하면 현재 워킹 디렉토리를 사용한다. 최종 경로는 정규화되고 경로가 루트 디렉토리로 처리되지 않는한 마지막 슬래시는 제거한다. 문자열이 아닌 아규먼트는 무시한다.
이는 쉘에서cd명령어를 순서대로 실행한 것과 같다.
path.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile')
//-- 이는 다음과 비슷하다.:
cd foo/bar
cd /tmp/file/
cd ..
cd a/../subfile
pwd
//--다른 경로라 존재할 필요가 없거나 파일일 수도 있다는 점만이 다르다.
path.resolve('/foo/bar', './baz')
// returns
'/foo/bar/baz'
path.resolve('/foo/bar', '/tmp/file/')
// returns
'/tmp/file'
path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
// if currently in /home/myself/node, it returns
'/home/myself/node/wwwroot/static_files/gif/image.gif'
This is the first article in a series of articles about three.js.Three.jsis a 3D library that tries to make it as easy as possible to get 3D content on a webpage.
Three.js is often confused with WebGL since more often than not, but not always, three.js uses WebGL to draw 3D.WebGL is a very low-level system that only draws points, lines, and triangles. To do anything useful with WebGL generally requires quite a bit of code and that is where three.js comes in. It handles stuff like scenes, lights, shadows, materials, textures, 3d math, all things that you'd have to write yourself if you were to use WebGL directly.
These tutorials assume you already know JavaScript and, for the most part they will use ES6 style.See here for a terse list of things you're expected to already know. Most browsers that support three.js are auto-updated so most users should be able to run this code. If you'd like to make this code run on really old browsers look into a transpiler likeBabel. Of course users running really old browsers probably have machines that can't run three.js.
When learning most programming languages the first thing people do is make the computer print"Hello World!". For 3D one of the most common first things to do is to make a 3D cube. So let's start with "Hello Cube!"
Before we get started let's try to give you an idea of the structure of a three.js app. A three.js app requires you to create a bunch of objects and connect them together. Here's a diagram that represents a small three.js app
Things to notice about the diagram above.
There is aRenderer. This is arguably the main object of three.js. You pass aSceneand aCamerato aRendererand it renders (draws) the portion of the 3D scene that is inside thefrustumof the camera as a 2D image to a canvas.
There is ascenegraphwhich is a tree like structure, consisting of various objects like aSceneobject, multipleMeshobjects,Lightobjects,Group,Object3D, andCameraobjects. ASceneobject defines the root of the scenegraph and contains properties like the background color and fog. These objects define a hierarchical parent/child tree like structure and represent where objects appear and how they are oriented. Children are positioned and oriented relative to their parent. For example the wheels on a car might be children of the car so that moving and orienting the car's object automatically moves the wheels. You can read more about this inthe article on scenegraphs.
Note in the diagramCamerais half in half out of the scenegraph. This is to represent that in three.js, unlike the other objects, aCameradoes not have to be in the scenegraph to function. Just like other objects, aCamera, as a child of some other object, will move and orient relative to its parent object. There is an example of putting multipleCameraobjects in a scenegraph at the end ofthe article on scenegraphs.
Meshobjects represent drawing a specificGeometrywith a specificMaterial. BothMaterialobjects andGeometryobjects can be used by multipleMeshobjects. For example to draw two blue cubes in different locations we could need twoMeshobjects to represent the position and orientation of each cube. We would only need oneGeometryto hold the vertex data for a cube and we would only need oneMaterialto specify the color blue. BothMeshobjects could reference the sameGeometryobject and the sameMaterialobject.
Geometryobjects represent the vertex data of some piece of geometry like a sphere, cube, plane, dog, cat, human, tree, building, etc... Three.js provides many kinds of built ingeometry primitives. You can alsocreate custom geometryas well asload geometry from files.
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
function comma(num){
var len, point, str;
num = num + "";
point = num.length % 3 ;
len = num.length;
str = num.substring(0, point);
while (point < len) {
if (str != "") str += ",";
str += num.substring(point, point + 3);
point += 3;
}
return str;
}