graphics3d/toon/meshbuilder
3D 모형 짓기. (기본 도형을 코드로 지어 꼭짓점 배열 하나에 담음) 툰 3D(점토 같은 한 색 재질과 바깥선)를 그릴 꼭짓점 배열을 짓는다. 외계행성 광부 키우기의 판 3D 에서 왔다. (three.js 의 기본 도형과 같은 꼴)
- 도형은 가운데가 원점인 자기 좌표로 짓는다. 부품을 더할 때 자리, 돌림, 크기를 곱해 한 덩어리에 담는다.
- 꼭짓점 하나는 자리 3, 노멀 3, 색 3(sRGB), 재질 2(빛남의 세기, 빛을 받지 않음), 무늬 4(무늬 번호, 무늬 색) 이다. 무늬 번호와 색의 뜻은 그리는 셰이더가 정한다. (0 이면 무늬 없음)
- 텍스처 좌표(UV)는 꼭짓점 배열 밖의 uvData 에 꼭짓점마다 2 씩 따로 담는다. UV 를 준 꼭짓점이 하나라도 있으면 나머지는 0 으로 채운다. (도형의 uvs, addTriangles 의 uvs)
- 2 번 UV 도 같은 꼴로 uv1Data 에 담는다. (도형의 uvs1, addTriangles 의 uvs1, GLB 의 TEXCOORD_1, 천사 고리처럼 두 번째 펼침을 읽는 것) (0, 0) 이 그림의 왼쪽 위다. (glTF 와 같음) 상자는 면마다 0 ~ 1, 구는 경도와 위도로 0 ~ 1 이다.
- 재질 범위(materialRanges)는 몸의 꼭짓점 번호 가운데 한 재질이 든 자리다. GLB 읽기가 프리미티브마다 담는다. (재질 이름, extras, 텍스처, ToonRenderer.drawMesh 의 indexStart, indexCount)
- 바깥선은 부품을 조금 키운 사본이다. 뒷면만 그리므로 따로 담는다. (inverted hull)
- 삼각형의 감기는 꼭짓점 노멀을 보고 바깥이 앞면이 되게 맞춘다. (뒷면 가리기와 바깥선이 감기에 기댐)
Building 3D models. (Builds basic shapes in code and puts them into one vertex array) Builds the vertex array used to draw toon 3D (single-color clay-like material with outlines). It came from the in-board 3D of webgame-rimminer. (Same form as the three.js basic geometries)
- Shapes are built in their own coordinates with the center at the origin. When a part is added, position, rotation and scale are multiplied in and it is put into one lump.
- One vertex is position 3, normal 3, color 3 (sRGB), material 2 (glow strength, unlit), pattern 4 (pattern number, pattern color). The meaning of the pattern number and color is decided by the shader that draws it. (0 means no pattern)
- Texture coordinates (UV) are stored separately, 2 per vertex, in uvData outside the vertex array. If even one vertex was given a UV, the rest are filled with 0. (uvs of a shape, uvs of addTriangles)
- The second UV is stored the same way in uv1Data. (uvs1 of a shape, uvs1 of addTriangles, TEXCOORD_1 of GLB, for things that read a second unwrap such as the angel ring) (0, 0) is the top left of the image. (Same as glTF) A box is 0 ~ 1 per face, a sphere is 0 ~ 1 by longitude and latitude.
- A material range (materialRanges) is the span of body vertex indices that holds one material. The GLB reader stores one per primitive. (Material name, extras, textures, indexStart and indexCount of ToonRenderer.drawMesh)
- The outline is a slightly enlarged copy of the part. Since only its back faces are drawn, it is stored separately. (inverted hull)
- Triangle winding is fixed by looking at the vertex normals so the outside becomes the front face. (Back-face culling and the outline rely on winding)
import { ToonRenderer, MeshBuilder, createPartMatrix, createCapsuleGeometry, createSphereGeometry, createCylinderGeometry, createBoxGeometry, Camera3D, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const builder = new MeshBuilder();
const bodyMatrix = createPartMatrix(null, [0, 0.6, 0], null, null);
builder.addPart(createCapsuleGeometry(0.3, 0.5, 6, 16), bodyMatrix, "#f0c8a0");
builder.addPart(createSphereGeometry(0.28, 20, 14), createPartMatrix(bodyMatrix, [0, 0.65, 0], null, null), "#f8e0c8", { outlineWidth: 0.015 });
builder.addPart(createCylinderGeometry(0, 0.12, 0.3, 12), createPartMatrix(bodyMatrix, [0, 1.05, 0], null, null), "#d04040", { glow: 0.5 });
builder.addPart(createBoxGeometry(2, 0.1, 2), Matrix4.createTranslation(0, -0.05, 0), "#708060", { hasOutline: false });
const mesh = renderer.createMesh(builder.readArrays());
const camera = new Camera3D();
camera.setPerspective(0.8, 0.1, 100);
camera.lookAt(Vector3.create(0, 1.5, 3), Vector3.create(0, 0.8, 0), Vector3.create(0, 1, 0));
renderer.beginFrameWithCamera(camera);
renderer.drawMesh(mesh, Matrix4.createIdentity());
renderer.endFrame();MeshBuilder
모형 한 덩어리를 짓는 것.
Builder for one model chunk.
import { ToonRenderer, MeshBuilder, createRoundedBoxGeometry, createSphereGeometry, Camera3D, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const builder = new MeshBuilder();
builder.addPart(createRoundedBoxGeometry(1, 0.5, 0.6, 3, 0.1), Matrix4.createTranslation(0, 0.25, 0), "#d0d8e0");
const lampStart = builder.getIndexCount();
builder.addPart(createSphereGeometry(0.12, 12, 8), Matrix4.createTranslation(0.5, 0.35, 0), "#ffe080", { glow: 1.5, isUnlit: true });
const lampCount = builder.getIndexCount() - lampStart;
const mesh = renderer.createMesh(builder.readArrays());
const camera = new Camera3D();
camera.setPerspective(0.8, 0.1, 100);
camera.lookAt(Vector3.create(1.5, 1.2, 2), Vector3.create(0, 0.2, 0), Vector3.create(0, 1, 0));
renderer.beginFrameWithCamera(camera);
renderer.drawMesh(mesh, Matrix4.createIdentity(), { indexStart: 0, indexCount: lampStart });
renderer.drawMesh(mesh, Matrix4.createIdentity(), { indexStart: lampStart, indexCount: lampCount, tintColor: [1, 0.5, 0.5, 1], hasOutline: false });
renderer.endFrame();지어 둔 배열 여럿을 옮겨 한 배열로 잇기. (움직이지 않는 조각을 한 메시로, 돌리거나 키우지 않음)
- 조각마다 { arrays: readArrays 나 readGlbArrays 의 결과, offset: [x, y, z] (없으면 옮기지 않음) }. 자리에 옮김을 더하고 번호에 앞 조각의 꼭짓점 수를 더한다. 바깥선 껍데기와 안쪽 범위(innerOutlineRanges, innerBodyRanges)도 같이 옮겨 잇는다.
- 뼈대는 잇지 않는다. 뼈대가 있는 조각도 쉬는 자세 그대로 움직이지 않는 몸이 된다.
Translates several built arrays and joins them into one array. (static pieces into one mesh, no rotation or scaling)
- Per piece { arrays: result of readArrays or readGlbArrays, offset: [x, y, z] (not translated if absent) }. Adds the offset to positions and the previous pieces' vertex count to indices. The outline shell and inner ranges (innerOutlineRanges, innerBodyRanges) are also translated and joined.
- Skeletons are not joined. Even a piece with a skeleton becomes a static body in its rest pose.
- piecesArray<object>
- { arrays, offset }
반환Returnsobject readArrays 의 꼴.Form of readArrays.
짝Counterpart: vanilla-engine MeshBuilder.combine
import { ToonRenderer, MeshBuilder, createFacetedChunkGeometry, Matrix4 } from "./vanilla.js";
const renderer = new ToonRenderer(document.createElement("canvas").getContext("webgl2"));
const builder = new MeshBuilder();
builder.addPart(createFacetedChunkGeometry(0.4, [1, 0.8, 1.1, 0.9], [1, 0.7, 1]), Matrix4.createIdentity(), "#8a8070");
const rockArrays = builder.readArrays();
const pieces = [{ arrays: rockArrays, offset: [0, 0, 0] }, { arrays: rockArrays, offset: [1.2, 0, 0.3] }, { arrays: rockArrays, offset: [-0.8, 0, 1] }];
const combinedArrays = MeshBuilder.combine(pieces);
const rocksMesh = renderer.createMesh(combinedArrays);비었는지.
Whether it is empty.
반환Returnsboolean 몸의 삼각형이 하나도 없으면 true.true if the body has no triangles.
짝Counterpart: vanilla-engine MeshBuilder.is_empty
지금까지 담은 몸의 꼭짓점 번호 수. (한 부위의 몸이 든 자리를 따로 그릴 때 그 앞뒤로 읽음)
Number of body vertex indices stored so far. (read before and after a part when drawing that part's body span separately)
반환Returnsnumber 몸의 꼭짓점 번호 수. (indexData 의 길이)Number of body vertex indices. (Length of indexData)
짝Counterpart: vanilla-engine MeshBuilder.get_index_count
import { MeshBuilder, createBoxGeometry, createCylinderGeometry, createPartMatrix, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
builder.addPart(createBoxGeometry(1.2, 0.4, 0.6), Matrix4.createTranslation(0, 0.4, 0), "#c04040");
const wheelStart = builder.getIndexCount();
builder.addPart(createCylinderGeometry(0.2, 0.2, 0.1, 16), createPartMatrix(null, [0.4, 0.2, 0.35], [Math.PI / 2, 0, 0], null), "#303030");
const wheelRange = { indexStart: wheelStart, indexCount: builder.getIndexCount() - wheelStart };지금까지 담은 바깥선 껍데기의 꼭짓점 번호 수. (한 부위의 껍데기가 든 자리를 따로 그릴 때 그 앞뒤로 읽음)
Number of outline shell vertex indices stored so far. (read before and after a part when drawing that part's shell span separately)
반환Returnsnumber 바깥선 껍데기의 꼭짓점 번호 수. (outlineIndexData 의 길이)Number of vertex indices of the outline shell. (Length of outlineIndexData)
짝Counterpart: vanilla-engine MeshBuilder.get_outline_index_count
import { MeshBuilder, createBoxGeometry, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
builder.addPart(createBoxGeometry(1, 1, 1), Matrix4.createIdentity(), "#a0a0a0");
const windowOutlineStart = builder.getOutlineIndexCount();
builder.addPart(createBoxGeometry(0.4, 0.3, 0.05), Matrix4.createTranslation(0, 0.1, 0.5), "#80c0ff", { outlineWidth: 0.01 });
const windowOutlineRange = { outlineIndexStart: windowOutlineStart, outlineIndexCount: builder.getOutlineIndexCount() - windowOutlineStart };부품 하나 더하기. (도형에 행렬을 곱해 담고, 바깥선이면 조금 키운 사본도 담음)
Adds one part. (stores the shape multiplied by the matrix, and with an outline also stores a slightly enlarged copy)
- geometryobject
- { positions, normals, indices, uvs (없어도 됨), uvs1 (2 번 UV, 없어도 됨) }{ positions, normals, indices, uvs (optional), uvs1 (second UV, optional) }
- matrixMatrix4
- 도형에 곱할 자리, 돌림, 크기 행렬.Position, rotation and scale matrix to multiply into the shape.
- colorTextstring
- "#rrggbb"
- optionsobject
- { glow 빛남(0 ~), isUnlit 빛을 받지 않음, hasOutline 바깥선(기본 있음), outlineWidth 바깥선 굵기 }{ glow glow (0 ~), isUnlit unlit, hasOutline outline (on by default), outlineWidth outline width }
짝Counterpart: vanilla-engine MeshBuilder.add_part
import { MeshBuilder, createSphereGeometry, createCylinderGeometry, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
builder.addPart(createSphereGeometry(0.5, 24, 16), Matrix4.createTranslation(0, 0.5, 0), "#f0e0d0", { outlineWidth: 0.03 });
builder.addPart(createSphereGeometry(0.06, 10, 8), Matrix4.createTranslation(0.15, 0.6, 0.45), "#40ffff", { glow: 2, isUnlit: true, hasOutline: false });
builder.addPart(createCylinderGeometry(0.5, 0.5, 0.01, 24), Matrix4.createTranslation(0, 0.005, 0), "#202020", { hasOutline: false });네모 면 하나 더하기. (블록 지형과 바닥 같은 면, 네 점은 둘레 차례, 바깥선 없음)
Adds one quad. (faces like block terrain and floors, four points in perimeter order, no outline)
- cornersArray<Array<number>>
- 네 점 [x, y, z]Four points [x, y, z]
- normalArray<number>
- [x, y, z]
- colorArray<number>
- [r, g, b] sRGB.
- patternnumber
- 무늬 번호. (뜻은 셰이더가 정함, 0 이면 없음)Pattern number. (meaning decided by the shader, 0 means none)
- patternColorArray<number> | null
- [r, g, b] 무늬 색. (없으면 null)[r, g, b] pattern color. (null if none)
- isUnlitboolean
- 빛을 받지 않음.Unlit.
짝Counterpart: vanilla-engine MeshBuilder.add_quad
import { MeshBuilder, readColorValues } from "./vanilla.js";
const builder = new MeshBuilder();
const grassColor = readColorValues("#60a040");
builder.addQuad([[0, 0, 0], [1, 0, 0], [1, 0, 1], [0, 0, 1]], [0, 1, 0], grassColor, 0, null, false);
builder.addQuad([[1, 0, 0], [2, 0, 0], [2, 0, 1], [1, 0, 1]], [0, 1, 0], grassColor, 1, [0.4, 0.7, 0.3], false);네모 면들의 바깥선 껍데기 담기. (땅 덩어리처럼 면으로 지은 것)
- 꼭짓점 자리를 1e-4 로 반올림한 것을 열쇠로 삼아 열쇠마다 서로 다른 면 법선을 한 번씩 더해 정규화하고, 꼭짓점을 그쪽으로 굵기만큼 민다.
- 면의 감기는 addQuad 와 같다. (그리는 쪽이 앞면을 가려 뒷면만 보인다)
Stores the outline shell of quads. (things built from faces, like ground chunks)
- Using vertex positions rounded to 1e-4 as keys, adds each distinct face normal once per key and normalizes, then pushes the vertex that way by the width.
- Face winding is the same as addQuad. (the drawing side culls front faces so only back faces show)
- quadsArray<object>
- { corners 네 점 [x, y, z], normal [x, y, z] }{ corners four points [x, y, z], normal [x, y, z] }
- outlineWidthnumber
- 껍데기 굵기. (꼭짓점 좌표 길이)Shell thickness. (Length in vertex coordinates)
짝Counterpart: vanilla-engine MeshBuilder.add_quad_shell
import { MeshBuilder } from "./vanilla.js";
const builder = new MeshBuilder();
const quads = [
{ corners: [[0, 1, 0], [1, 1, 0], [1, 1, 1], [0, 1, 1]], normal: [0, 1, 0] },
{ corners: [[0, 0, 1], [1, 0, 1], [1, 1, 1], [0, 1, 1]], normal: [0, 0, 1] },
];
for (const quad of quads) {
builder.addQuad(quad.corners, quad.normal, [0.5, 0.4, 0.3], 0, null, false);
}
builder.addQuadShell(quads, 0.02);addTriangles(positions, normals, indices, matrix, color, glow, isUnlit, joints, weights, uvs = null, uvs1 = null)#받은 모형의 삼각형 담기. (GLB 의 프리미티브 하나, 감기는 그대로)
Stores triangles of a loaded model. (one GLB primitive, winding kept as is)
- positionsFloat32Array
- 꼭짓점마다 [x, y, z].[x, y, z] per vertex.
- normalsFloat32Array
- 꼭짓점마다 [x, y, z] 노멀.[x, y, z] normal per vertex.
- indicesArrayLike<number>
- 삼각형마다 꼭짓점 번호 셋.Three vertex indices per triangle.
- matrixMatrix4
- 꼭짓점에 곱할 행렬.Matrix to multiply into the vertices.
- colorArray<number>
- [r, g, b] sRGB.
- glownumber
- 빛남의 세기. (바탕색에 곱해 더함, 0 이면 없음)Glow strength. (Multiplied by the base color and added, 0 means none)
- isUnlitboolean
- 빛을 받지 않음.Unlit.
- jointsArrayLike<number> | null
- 꼭짓점마다 뼈대 번호 넷. (없으면 null)Four joint indices per vertex. (null if none)
- weightsArrayLike<number> | null
- 꼭짓점마다 무게 넷.Four weights per vertex.
- uvsArrayLike<number> | null
- 꼭짓점마다 텍스처 좌표 둘. (없으면 null)Two texture coordinates per vertex. (null if none)
- uvs1ArrayLike<number> | null
- 꼭짓점마다 2 번 텍스처 좌표 둘. (없으면 null)Two second texture coordinates per vertex. (null if none)
짝Counterpart: vanilla-engine MeshBuilder.add_triangles
import { MeshBuilder, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
const positions = new Float32Array([0, 0, 0, 1, 0, 0, 0, 1, 0]);
const normals = new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1]);
const uvs = new Float32Array([0, 1, 1, 1, 0, 0]);
builder.addTriangles(positions, normals, [0, 1, 2], Matrix4.createIdentity(), [1, 0.8, 0.6], 0, false, null, null, uvs);
const arrays = builder.readArrays();받은 모형의 바깥선 껍데기 담기. (이미 부풀린 것, 감기는 그대로)
Stores the outline shell of a loaded model. (already inflated, winding kept as is)
- positionsFloat32Array
- 이미 부풀린 껍데기의 꼭짓점마다 [x, y, z].[x, y, z] per vertex of an already inflated shell.
- indicesArrayLike<number>
- 삼각형마다 꼭짓점 번호 셋. (감기는 그대로 담는다)Three vertex indices per triangle. (Winding is stored as is)
- matrixMatrix4
- 꼭짓점에 곱할 행렬.Matrix to multiply into the vertices.
- jointsArrayLike<number> | null
- 꼭짓점마다 뼈대 번호 넷. (없으면 null)Four joint indices per vertex. (null if none)
- weightsArrayLike<number> | null
- 꼭짓점마다 무게 넷. (없으면 null)Four weights per vertex. (null if none)
짝Counterpart: vanilla-engine MeshBuilder.add_outline_triangles
import { MeshBuilder, createFacetedChunkGeometry, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
const body = createFacetedChunkGeometry(0.5, [1], [1, 1, 1]);
const shell = createFacetedChunkGeometry(0.53, [1], [1, 1, 1]);
builder.addTriangles(new Float32Array(body.positions), new Float32Array(body.normals), body.indices, Matrix4.createIdentity(), [0.6, 0.8, 1], 0, false, null, null);
builder.addOutlineTriangles(new Float32Array(shell.positions), shell.indices, Matrix4.createIdentity(), null, null);받은 모형의 몸으로 바깥선 껍데기 짓기. (addPart 의 바깥선과 같은 셈, 감기는 그대로, 뼈대 번호와 무게는 몸의 것 그대로)
- 여러 프리미티브를 이어 붙여 한 번에 넘기면 프리미티브 사이의 같은 자리 점도 함께 민다.
Builds an outline shell from a loaded model's body. (same computation as addPart's outline, winding kept as is, joint indices and weights taken from the body as is)
- If several primitives are concatenated and passed at once, points at the same position across primitives are pushed together too.
- positionsArrayLike<number>
- 몸의 꼭짓점마다 [x, y, z].[x, y, z] per body vertex.
- normalsArrayLike<number>
- 몸의 꼭짓점마다 [x, y, z] 노멀.[x, y, z] normal per body vertex.
- indicesArrayLike<number>
- 삼각형마다 꼭짓점 번호 셋.Three vertex indices per triangle.
- matrixMatrix4
- 꼭짓점에 곱할 행렬.Matrix to multiply into the vertices.
- outlineWidthnumber
- 껍데기 굵기. (행렬을 곱한 뒤의 길이)Shell thickness. (Length after the matrix is applied)
- jointsArrayLike<number> | null
- 꼭짓점마다 뼈대 번호 넷. (없으면 null)Four joint indices per vertex. (null if none)
- weightsArrayLike<number> | null
- 꼭짓점마다 무게 넷. (없으면 null)Four weights per vertex. (null if none)
짝Counterpart: vanilla-engine MeshBuilder.add_triangle_shell
import { MeshBuilder, createFacetedChunkGeometry, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
const body = createFacetedChunkGeometry(0.5, [1, 0.9, 1.1], [1, 0.8, 1]);
const matrix = Matrix4.createTranslation(0, 0.4, 0);
builder.addTriangles(new Float32Array(body.positions), new Float32Array(body.normals), body.indices, matrix, [0.6, 0.55, 0.5], 0, false, null, null);
builder.addTriangleShell(body.positions, body.normals, body.indices, matrix, 0.02, null, null);방금 담은 꼭짓점들의 텍스처 좌표 담기. (uvs 가 null 이면 UV 가 이미 있을 때만 0 으로 채운다, 앞 꼭짓점의 빈자리도 0 으로)
Stores texture coordinates of the vertices just stored. (if uvs is null, fills with 0 only when UV already exists, gaps for earlier vertices are also filled with 0)
- uvsArrayLike<number> | null
- 꼭짓점마다 텍스처 좌표 둘. (없으면 null)Two texture coordinates per vertex. (null if none)
- vertexCountnumber
- 방금 담은 꼭짓점 수.Number of vertices just stored.
방금 담은 꼭짓점들의 2 번 텍스처 좌표 담기. (pushUvValues 와 같은 꼴)
Store the second texture coordinates of the vertices just added. (Same form as pushUvValues)
- uvs1ArrayLike<number> | null
- 꼭짓점마다 2 번 텍스처 좌표 둘. (없으면 null)Two second texture coordinates per vertex. (null if none)
- vertexCountnumber
- 방금 담은 꼭짓점 수.Number of vertices just stored.
텍스처 좌표 칸에 담기. (값이 null 이고 칸이 비면 아무것도 하지 않는다, 앞 꼭짓점의 빈자리는 0)
Store into a texture coordinate array. (Does nothing if the values are null and the array is empty, gaps of earlier vertices are 0)
- targetArray<number>
- 담을 칸.Target array.
- uvsArrayLike<number> | null
- 꼭짓점마다 둘. (없으면 null)Two per vertex. (null if none)
- vertexCountnumber
- 방금 담은 꼭짓점 수.Number of vertices just stored.
재질 범위 담기. ({ name, indexStart, indexCount, ... } 몸의 꼭짓점 번호 자리, GLB 읽기가 프리미티브마다 담음)
Stores a material range. ({ name, indexStart, indexCount, ... } span of body vertex indices, the GLB reader stores one per primitive)
- materialRangeobject
- { name, indexStart, indexCount, ... } 몸의 꼭짓점 번호 자리. (readArrays 의 materialRanges 에 복사해 담긴다){ name, indexStart, indexCount, ... } span of body vertex indices. (Copied into materialRanges of readArrays)
짝Counterpart: vanilla-engine MeshBuilder.add_material_range
import { MeshBuilder, createBoxGeometry, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
builder.addPart(createBoxGeometry(1, 1, 1), Matrix4.createIdentity(), "#909090");
const screenStart = builder.getIndexCount();
builder.addPart(createBoxGeometry(0.6, 0.4, 0.02), Matrix4.createTranslation(0, 0.1, 0.51), "#102030", { hasOutline: false });
builder.addMaterialRange({ name: "screen", indexStart: screenStart, indexCount: builder.getIndexCount() - screenStart, extras: {} });
const screenRange = builder.readArrays().materialRanges.find((materialRange) => materialRange.name === "screen");뼈대 번호와 무게 담기. (뼈대가 없으면 담지 않음)
Stores joint indices and weights. (not stored if there is no skeleton)
- targetArray<number>
- 담을 곳. (몸이나 바깥선의 뼈대 값)Destination. (Skeleton values of the body or the outline)
- jointsArrayLike<number> | null
- 꼭짓점마다 뼈대 번호 넷. (없으면 담지 않음)Four joint indices per vertex. (Not stored if none)
- weightsArrayLike<number> | null
- 꼭짓점마다 무게 넷. (없으면 담지 않음)Four weights per vertex. (Not stored if none)
- vertexCountnumber
- 담을 꼭짓점 수.Number of vertices to store.
다 지은 배열. ({ vertexData, indexData, outlineVertexData, outlineIndexData, outlineBaseData })
The finished arrays. ({ vertexData, indexData, outlineVertexData, outlineIndexData, outlineBaseData })
반환Returnsobject { vertexData, indexData, outlineVertexData, outlineIndexData, outlineBaseData, skinData, outlineSkinData, skeleton, uvData, uv1Data, materialRanges }
짝Counterpart: vanilla-engine MeshBuilder.read_arrays
import { ToonRenderer, MeshBuilder, createTorusGeometry, Matrix4 } from "./vanilla.js";
const renderer = new ToonRenderer(document.createElement("canvas").getContext("webgl2"));
const builder = new MeshBuilder();
builder.addPart(createTorusGeometry(0.4, 0.1, 10, 24), Matrix4.createIdentity(), "#e08060");
const arrays = builder.readArrays();
const mesh = builder.isEmpty() ? null : renderer.createMesh(arrays);노멀에 곱할 3x3. (행렬 왼쪽 위 3x3 의 역의 전치, 행 차례)
3x3 to multiply normals by. (transpose of the inverse of the matrix's upper-left 3x3, row order)
- elementsFloat32Array
- Matrix4 의 수.Elements of a Matrix4.
반환ReturnsArray<number> 노멀에 곱할 3x3 의 수 9. (행 차례, 행렬식이 0 에 가까우면 단위 행렬)Nine numbers of the 3x3 to multiply into normals. (Row order, identity if the determinant is near 0)
삼각형마다 감기를 뒤집을지. (면 노멀이 꼭짓점 노멀의 합과 반대면 뒤집음)
Whether to flip the winding of each triangle. (flips if the face normal is opposite to the sum of vertex normals)
- indicesArray<number>
- 삼각형마다 꼭짓점 번호 셋.Three vertex indices per triangle.
- worldPositionsArray<number>
- 행렬을 곱한 꼭짓점 자리. (3 씩)Vertex positions with the matrix applied. (3 each)
- worldNormalsArray<number>
- 행렬을 곱한 단위 노멀. (3 씩)Unit normals with the matrix applied. (3 each)
반환ReturnsArray<boolean> 삼각형마다 뒤집을지.Whether to flip each triangle.
삼각형 담기. (뒤집을 것은 둘째와 셋째를 바꿈)
Stores triangles. (for ones to flip, swaps the second and third)
- targetArray<number>
- 담을 꼭짓점 번호 배열.Vertex index array to store into.
- indicesArray<number>
- 도형의 삼각형마다 꼭짓점 번호 셋.Three vertex indices per triangle of the shape.
- flipsArray<boolean>
- 삼각형마다 뒤집을지. (readTriangleFlips)Whether to flip each triangle. (readTriangleFlips)
- startIndexnumber
- 번호에 더할 첫 꼭짓점 차례.First vertex order to add to the indices.
바깥선 껍데기의 삼각형 담기. (뒤집을 것은 둘째와 셋째를 바꾸고, 밀고 나서 면이 뒤집힌 삼각형은 뺌)
- 오목한 곳(몸과 바닥판이 이어진 곳)에서 굵기보다 좁게 굽은 면은 밀면 껍데기가 접혀 면이 뒤집힌다. 뒤집힌 면은 카메라 쪽을 뒷면으로 보여, 깊이와 함께 나중에 그리는 껍데기(건물, 바위)에서는 몸 위에 짙은 줄로 비친다.
Stores outline shell triangles. (for ones to flip, swaps the second and third, and drops triangles whose face flipped after pushing)
- In concave areas (where the body meets the base plate), surfaces curving tighter than the width fold the shell when pushed, flipping the face. A flipped face shows its back face toward the camera, so on shells drawn later with depth (buildings, rocks) it shows as a dark streak over the body.
- targetArray<number>
- 담을 껍데기 꼭짓점 번호 배열.Shell vertex index array to store into.
- indicesArrayLike<number>
- 삼각형마다 꼭짓점 번호 셋.Three vertex indices per triangle.
- flipsArray<boolean> | null
- 없으면 감기 그대로.If absent, winding is kept as is.
- startIndexnumber
- 번호에 더할 첫 껍데기 꼭짓점 차례.First shell vertex order to add to the indices.
- worldPositionsArray<number>
- 밀기 전의 점.Points before pushing.
- offsetsArray<number>
- 점마다 민 만큼.Push amount per point.
바깥선 껍데기의 점마다 밀어낼 만큼. (점마다 [x, y, z], 자리가 같은 점끼리 함께 밂)
- 같은 자리의 점(날카로운 모서리, 이음매, 극)은 서로 다른 법선을 한 번씩 더한 쪽으로 함께 밀어 껍데기가 벌어지지 않게 한다.
- 모서리에서는 맞닿은 면마다 굵기만큼 떨어지게 더 민다. (그 쪽과 면 법선의 가장 작은 코사인으로 나눔) 뾰족한 끝(원뿔 꼭대기)이 너무 튀지 않게 그 코사인은 MINIMUM_OUTLINE_MITER_COSINE 밑으로 내리지 않는다.
Push amount per point of the outline shell. ([x, y, z] per point, points at the same position are pushed together)
- Points at the same position (sharp edges, seams, poles) are pushed together toward the sum of their distinct normals, each added once, so the shell does not split open.
- At edges, pushes further so it stays the width away from each adjoining face. (divided by the smallest cosine between that direction and the face normals) So sharp tips (cone apex) do not stick out too far, that cosine is not lowered below MINIMUM_OUTLINE_MITER_COSINE.
- worldPositionsArray<number>
- 행렬을 곱한 꼭짓점 자리. (3 씩)Vertex positions with the matrix applied. (3 each)
- worldNormalsArray<number>
- 단위 법선.Unit normal.
- outlineWidthnumber
- 껍데기 굵기.Shell thickness.
반환ReturnsArray<number> 점마다 밀어낼 [x, y, z]. (3 씩)[x, y, z] to push out per point. (3 each)
짝Counterpart: vanilla-engine MeshBuilder.read_outline_offsets
도형의 둘레 반지름. (상자 가운데에서 가장 먼 점까지)
Bounding radius of the shape. (from the box center to the farthest point)
- positionsArray<number>
- 꼭짓점 자리. (3 씩)Vertex positions. (3 each)
반환Returnsnumber 감싸는 상자 가운데에서 가장 먼 점까지의 거리.Distance from the center of the bounding box to the farthest point.
행렬의 가장 큰 크기. (세 축의 길이 가운데 큰 것)
Largest scale of the matrix. (the largest of the three axis lengths)
- elementsFloat32Array
- Matrix4 의 수.Elements of a Matrix4.
반환Returnsnumber 세 축 길이 가운데 가장 큰 것.The largest of the three axis lengths.
함수Functions
색 글자를 sRGB 세 수로. ("#rrggbb" → [r, g, b], 0 ~ 1)
Color string to three sRGB numbers. ("#rrggbb" → [r, g, b], 0 ~ 1)
- colorTextstring
- "#rrggbb" 색 글자."#rrggbb" color text.
반환ReturnsArray<number> [r, g, b] sRGB. (0 ~ 1)
짝Counterpart: vanilla-engine read_color_values
import { readColorValues, MeshBuilder } from "./vanilla.js";
const color = readColorValues("#80c040");
const builder = new MeshBuilder();
builder.addQuad([[0, 0, 0], [1, 0, 0], [1, 0, 1], [0, 0, 1]], [0, 1, 0], color, 0, null, false);
const arrays = builder.readArrays();자리, 돌림, 크기로 변환 행렬 짓기. (부모 행렬 뒤에 곱함, 돌림은 three.js 의 기본 차례 XYZ)
Builds a transform matrix from position, rotation and scale. (multiplied after the parent matrix, rotation uses three.js default order XYZ)
- parentMatrixMatrix4 | null
- 부모 행렬. (null 이면 단위 행렬)Parent matrix. (Identity if null)
- positionArray<number>
- [x, y, z]
- rotationArray<number> | null
- [x, y, z] 라디안.[x, y, z] radians.
- scaleArray<number> | null
- [x, y, z]
반환ReturnsMatrix4 부모 x 자리 x 돌림 x 크기 행렬. (새 행렬)Parent x translation x rotation x scale matrix. (New matrix)
짝Counterpart: vanilla-engine create_part_matrix
import { MeshBuilder, createPartMatrix, createBoxGeometry, createCapsuleGeometry } from "./vanilla.js";
const builder = new MeshBuilder();
const bodyMatrix = createPartMatrix(null, [0, 1, 0], [0, Math.PI / 4, 0], null);
const armMatrix = createPartMatrix(bodyMatrix, [0.4, 0.1, 0], [0, 0, -0.6], [1, 1.5, 1]);
builder.addPart(createBoxGeometry(0.5, 0.6, 0.3), bodyMatrix, "#4080c0");
builder.addPart(createCapsuleGeometry(0.08, 0.3, 4, 10), armMatrix, "#f0c8a0");네모 상자. (면마다 꼭짓점을 따로 두어 모서리가 날카로움)
Box. (separate vertices per face so edges are sharp)
- widthnumber
- X 축 길이.X axis length.
- heightnumber
- Y 축 길이.Y axis length.
- depthnumber
- Z 축 길이.Z axis length.
반환Returnsobject { positions, normals, indices, uvs } 도형. (면마다 UV 0 ~ 1){ positions, normals, indices, uvs } shape. (UV 0 ~ 1 per face)
짝Counterpart: vanilla-engine create_box_geometry
import { MeshBuilder, createBoxGeometry, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
const geometry = createBoxGeometry(6, 0.2, 6);
builder.addPart(geometry, Matrix4.createTranslation(0, -0.1, 0), "#607050", { hasOutline: false });
const arrays = builder.readArrays();모서리가 둥근 상자. (면마다 격자를 깔고 안쪽 상자에서 반지름만큼 밀어냄)
Rounded box. (lays a grid on each face and pushes out from an inner box by the radius)
- widthnumber
- X 축 길이.X axis length.
- heightnumber
- Y 축 길이.Y axis length.
- depthnumber
- Z 축 길이.Z axis length.
- segmentsnumber
- 둥근 곳의 마디 수.Number of segments in the rounded parts.
- radiusnumber
- 모서리 반지름. (반 길이보다 크면 그 축은 다 둥글다)Corner radius. (If larger than the half length, that axis is fully rounded)
반환Returnsobject { positions, normals, indices } 도형.{ positions, normals, indices } shape.
짝Counterpart: vanilla-engine create_rounded_box_geometry
import { MeshBuilder, createRoundedBoxGeometry, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
builder.addPart(createRoundedBoxGeometry(1, 0.6, 0.8, 4, 0.12), Matrix4.createIdentity(), "#e0a060");
builder.addPart(createRoundedBoxGeometry(0.3, 0.1, 0.3, 2, 0.04), Matrix4.createTranslation(0, 0.35, 0), "#c04040");
const arrays = builder.readArrays();원기둥. (위와 아래 반지름이 다르면 깔때기, 위가 0 이면 원뿔, 위아래 뚜껑 포함)
Cylinder. (a funnel if the top and bottom radii differ, a cone if the top is 0, includes top and bottom caps)
- radiusTopnumber
- 위 반지름. (0 이면 원뿔)Top radius. (0 makes a cone)
- radiusBottomnumber
- 아래 반지름.Bottom radius.
- heightnumber
- 높이. (가운데가 원점)Height. (Center at the origin)
- radialSegmentsnumber
- 둘레 마디 수.Number of segments around.
반환Returnsobject { positions, normals, indices } 도형.{ positions, normals, indices } shape.
짝Counterpart: vanilla-engine create_cylinder_geometry
import { MeshBuilder, createCylinderGeometry, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
builder.addPart(createCylinderGeometry(0.08, 0.1, 0.6, 10), Matrix4.createTranslation(0, 0.3, 0), "#806040");
builder.addPart(createCylinderGeometry(0, 0.4, 0.9, 12), Matrix4.createTranslation(0, 1, 0), "#40a050");
const arrays = builder.readArrays();createSphereGeometry(radius, widthSegments, heightSegments, thetaLength = System.Math.PI)#구. (위에서부터 thetaLength 까지, π/2 면 위쪽 반구)
Sphere. (from the top down to thetaLength, π/2 gives the upper hemisphere)
- radiusnumber
- 반지름.Radius.
- widthSegmentsnumber
- 경도 마디 수.Number of longitude segments.
- heightSegmentsnumber
- 위도 마디 수.Number of latitude segments.
- thetaLengthnumber
- 위에서부터 깎을 각. (라디안, 기본 π 면 온 구)Angle to sweep from the top. (Radians, the default π is a full sphere)
반환Returnsobject { positions, normals, indices, uvs } 도형. (UV 는 경도와 위도로 0 ~ 1){ positions, normals, indices, uvs } shape. (UV 0 ~ 1 by longitude and latitude)
짝Counterpart: vanilla-engine create_sphere_geometry
import { MeshBuilder, createCylinderGeometry, createSphereGeometry, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
builder.addPart(createCylinderGeometry(0.6, 0.6, 1, 24), Matrix4.createTranslation(0, 0.5, 0), "#e0d0b0");
builder.addPart(createSphereGeometry(0.6, 24, 8, Math.PI / 2), Matrix4.createTranslation(0, 1, 0), "#c06050");
const arrays = builder.readArrays();돌려 깎기. (옆모습의 점 [x, y] 들을 Y 축으로 돌림, 노멀은 옆모습의 기울기로)
Lathe. (revolves the profile points [x, y] around the Y axis, normals from the profile slope)
- pointsArray<Array<number>>
- 아래에서 위로.From bottom to top.
- segmentsnumber
- 둘레 마디 수.Number of segments around.
반환Returnsobject { positions, normals, indices } 도형.{ positions, normals, indices } shape.
짝Counterpart: vanilla-engine create_lathe_geometry
import { MeshBuilder, createLatheGeometry, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
const profile = [[0.001, 0], [0.25, 0.05], [0.3, 0.3], [0.15, 0.6], [0.2, 0.75]];
builder.addPart(createLatheGeometry(profile, 20), Matrix4.createIdentity(), "#5080c0");
const arrays = builder.readArrays();캡슐. (가운데 길이 length 의 원기둥 위아래에 반구, 전체 높이는 length + 반지름 둘)
Capsule. (hemispheres on the top and bottom of a middle cylinder of length length, total height is length + two radii)
- radiusnumber
- 반지름.Radius.
- lengthnumber
- 가운데 원기둥의 길이. (반구는 빼고)Length of the middle cylinder. (Without the hemispheres)
- capSegmentsnumber
- 반구 하나의 위도 마디 수.Number of latitude segments of one hemisphere.
- radialSegmentsnumber
- 둘레 마디 수.Number of segments around.
반환Returnsobject { positions, normals, indices } 도형.{ positions, normals, indices } shape.
짝Counterpart: vanilla-engine create_capsule_geometry
import { MeshBuilder, createCapsuleGeometry, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
builder.addPart(createCapsuleGeometry(0.2, 0.8, 6, 16), Matrix4.createRotationZ(Math.PI / 2), "#a0d0f0");
builder.addPart(createCapsuleGeometry(0.1, 0.3, 4, 12), Matrix4.createTranslation(0, 0.4, 0), "#80b0d0");
const arrays = builder.readArrays();createTorusGeometry(radius, tube, radialSegments, tubularSegments, arc = System.Math.PI * 2)#고리. (XY 평면에 누운 고리, arc 만큼만)
Torus. (a ring lying on the XY plane, only as far as arc)
- radiusnumber
- 고리의 반지름.Radius of the ring.
- tubenumber
- 관의 반지름.Radius of the tube.
- radialSegmentsnumber
- 관을 도는 마디.Segments around the tube.
- tubularSegmentsnumber
- 고리를 도는 마디.Segments around the ring.
- arcnumber
- 고리를 도는 각. (라디안, 기본 2π)Angle around the ring. (Radians, default 2π)
반환Returnsobject { positions, normals, indices } 도형.{ positions, normals, indices } shape.
짝Counterpart: vanilla-engine create_torus_geometry
import { MeshBuilder, createTorusGeometry, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
builder.addPart(createTorusGeometry(0.5, 0.08, 8, 24, Math.PI), Matrix4.createRotationX(-Math.PI / 2), "#f0d060");
builder.addPart(createTorusGeometry(0.3, 0.05, 8, 20), Matrix4.createTranslation(0, 0.5, 0), "#e0b040");
const arrays = builder.readArrays();팔면체. (면마다 꼭짓점을 따로 두어 각진 결정)
Octahedron. (separate vertices per face for an angular crystal)
- radiusnumber
- 가운데에서 꼭짓점까지.From the center to a vertex.
반환Returnsobject { positions, normals, indices } 도형.{ positions, normals, indices } shape.
짝Counterpart: vanilla-engine create_octahedron_geometry
import { MeshBuilder, createOctahedronGeometry, createCylinderGeometry, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
builder.addPart(createOctahedronGeometry(0.4), Matrix4.createScale(0.6, 1.4, 0.6), "#80e0ff", { glow: 0.8 });
builder.addPart(createCylinderGeometry(0.3, 0.35, 0.15, 8), Matrix4.createTranslation(0, -0.6, 0), "#605870");
const arrays = builder.readArrays();각진 돌덩이. (이십면체의 꼭짓점 열둘을 저마다 늘이고 줄여, 면마다 꼭짓점을 따로 둔 깎은 돌)
Angular rock. (stretches and shrinks each of the twelve icosahedron vertices, a faceted stone with separate vertices per face)
- radiusnumber
- 기준 반지름.Base radius.
- vertexScalesArray<number>
- 꼭짓점 열둘의 반지름 배. (모자라면 처음부터 되풀이)Radius multipliers for the twelve vertices. (repeats from the start if too few)
- axisScaleArray<number>
- [x, y, z] 배.[x, y, z] multiplier.
반환Returnsobject { positions, normals, indices }
짝Counterpart: vanilla-engine create_faceted_chunk_geometry
import { MeshBuilder, createFacetedChunkGeometry, Matrix4 } from "./vanilla.js";
const builder = new MeshBuilder();
const vertexScales = [1, 0.85, 1.1, 0.9, 1.05, 0.8, 1, 0.95, 1.15, 0.9, 1, 0.85];
builder.addPart(createFacetedChunkGeometry(0.5, vertexScales, [1.2, 0.6, 1]), Matrix4.createIdentity(), "#908878");
const arrays = builder.readArrays();상수Constants
꼭짓점 하나의 수 개수. (자리 3, 노멀 3, 색 3, 재질 2, 무늬 4)
Number of values per vertex. (position 3, normal 3, color 3, material 2, pattern 4)
반환Returnsnumber
짝Counterpart: vanilla-engine VERTEX_FLOAT_COUNT
뼈대가 있는 모형의 꼭짓점마다 따로 담는 수 개수. (뼈대 번호 4, 무게 4)
Number of values stored separately per vertex for models with a skeleton. (joint indices 4, weights 4)
반환Returnsnumber
짝Counterpart: vanilla-engine SKIN_FLOAT_COUNT