vanilladocs
vanillapunch.com
API / graphics3d/skinnedmodelrenderer

graphics3d/skinnedmodelrenderer

스킨드 모델 렌더러. (스키닝 PBR 셰이더 템플릿 + 환경 상태 소유, 씬당 하나)

Skinned model renderer. (owns the skinning PBR shader template + environment state, one per scene)

SkinnedModelRendererextends Object

짝Counterpart: vanilla-engine SkinnedModelRenderer

스킨드 모델 렌더러. (스키닝 PBR 셰이더 템플릿 + 환경 상태 소유, 씬당 하나)

  • SkinnedModel 은 데이터/포즈만 갖고, 렌더링은 이 객체가 모델 인스턴스를 받아 수행한다.
  • 환경 상태(섀도우 맵 / 태양 / 안개)는 모델이 아닌 렌더러에 설정한다. 섀도우 맵이 없으면 섀도우 유닛에 1x1 비교 깊이 텍스처를 묶는다.
  • 프래그먼트 셰이더 소스를 주입하면 같은 스키닝/모프 버텍스 경로 위에 다른 셰이딩 템플릿을 세울 수 있다. (파생 렌더러는 use() 후 고유 유니폼을 설정하고 draw() 를 호출한다)

Skinned model renderer. (owns the skinning PBR shader template + environment state, one per scene)

  • SkinnedModel holds only data/pose, and this object takes a model instance and does the rendering.
  • Environment state (shadow map / sun / fog) is set on the renderer, not the model. Without a shadow map, a 1x1 comparison depth texture is bound to the shadow unit.
  • Injecting fragment shader source lets you build a different shading template on top of the same skinning/morph vertex path. (a derived renderer sets its own uniforms after use() and calls draw())
예제ExampleGLB 모델 하나를 태양과 안개 아래 그리기Draw one GLB model under sun and fog
import { SkinnedModel, SkinnedModelRenderer, Camera3D, Matrix4, Vector3 } from "./build/vanilla.js";

const width = 640;
const height = 360;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
document.body.appendChild(canvas);
const webGL2RenderingContext = canvas.getContext("webgl2");
const skinnedModelRenderer = new SkinnedModelRenderer(webGL2RenderingContext);
skinnedModelRenderer.setSunDirection(0.45, 0.76, 0.47);
skinnedModelRenderer.setFogColor(0.16, 0.2, 0.26);
skinnedModelRenderer.setFogRange(300, 800);
const skinnedModel = await SkinnedModel.loadFromUrl(webGL2RenderingContext, "examples/ancientmountain/assets/fox.glb", skinnedModelRenderer);
skinnedModel.update(0);

const cameraX = 0;
const cameraY = 80;
const cameraZ = 220;
const camera = new Camera3D();
camera.setPerspective(Math.PI / 3, 1, 2000);
camera.setAspectRatio(width / height);
const eyePosition = Vector3.create(cameraX, cameraY, cameraZ);
const targetPosition = Vector3.create(0, 45, 0);
camera.lookAt(eyePosition, targetPosition);
const viewProjectionMatrix = camera.getViewProjectionMatrix();
const viewProjectionElements = viewProjectionMatrix.getElements();
const modelMatrix = Matrix4.createIdentity();
const modelMatrixElements = modelMatrix.getElements();

webGL2RenderingContext.viewport(0, 0, width, height);
webGL2RenderingContext.enable(webGL2RenderingContext.DEPTH_TEST);
webGL2RenderingContext.clearColor(0.16, 0.2, 0.26, 1);
webGL2RenderingContext.clear(webGL2RenderingContext.COLOR_BUFFER_BIT | webGL2RenderingContext.DEPTH_BUFFER_BIT);
skinnedModelRenderer.draw(skinnedModel, viewProjectionElements, modelMatrixElements, cameraX, cameraY, cameraZ);
생성자constructorconstructor(webGL2RenderingContext, fragmentShaderSource = null, vertexShaderSource = null)#0.3.0 부터since 0.3.0소스source

생성.

Constructor.

webGL2RenderingContextWebGL2RenderingContext
WebGL2 렌더링 컨텍스트.WebGL2 rendering context.
fragmentShaderSourcestring | null
대체 프래그먼트 셰이더 소스. (null 이면 기본 PBR)Replacement fragment shader source. (default PBR if null)
vertexShaderSourcestring | null
대체 버텍스 셰이더 소스. (null 이면 기본 스키닝, 같은 어트리뷰트 / 출력 규약을 지켜야 한다)Replacement vertex shader source. (default skinning if null, must follow the same attribute / output conventions)

짝Counterpart: vanilla-engine SkinnedModelRenderer.new

예제Example같은 스키닝 경로 위에 다른 프래그먼트 셰이더 세우기Build a different fragment shader on the same skinning path
import { SkinnedModel, SkinnedModelRenderer } from "./build/vanilla.js";

const canvas = document.createElement("canvas");
const webGL2RenderingContext = canvas.getContext("webgl2");
const unlitShaderSource = `#version 300 es
precision highp float;
in vec3 worldNormal;
in vec2 fragmentTextureCoordinate;
uniform sampler2D baseColorTexture;
uniform vec3 baseColorFactor;
out vec4 outputColor;
void main() {
	vec3 albedo = texture(baseColorTexture, fragmentTextureCoordinate).rgb * baseColorFactor;
	float light = max(dot(normalize(worldNormal), vec3(0.0, 1.0, 0.0)), 0.0) * 0.6 + 0.4;
	outputColor = vec4(albedo * light, 1.0);
}
`;
const unlitRenderer = new SkinnedModelRenderer(webGL2RenderingContext, unlitShaderSource);
const skinnedModel = await SkinnedModel.loadFromUrl(webGL2RenderingContext, "examples/ancientmountain/assets/fox.glb", unlitRenderer);
const drawableList = skinnedModel.getDrawableList();
console.log(drawableList.length);
메서드methoduploadJointMatrices(jointMatrixArray)#0.4.0 부터since 0.4.0소스source

뼈 행렬 올리기. (JointBlock 유니폼 블록, 프로그램은 ShaderProgram 이 링크 뒤에 같은 바인딩 자리로 묶는다)

Uploads the joint matrices. (the JointBlock uniform block, ShaderProgram binds each program to the same binding point after linking)

jointMatrixArrayFloat32Array
뼈 행렬의 수. (16 의 배수)Joint matrix values. (a multiple of 16)
메서드methodcreateEmptyShadowTexture()#0.4.0 부터since 0.4.0소스source

빈 그림자 텍스처 짓기. (1x1 깊이 1, 비교 샘플링)

  • sampler2DShadow 유닛에 비교 모드가 없는 텍스처가 묶이면 WebGL 이 그리기를 거부하고, 깊이 텍스처가 없으면 맥 드라이버가 알린다.

Creates the empty shadow texture. (1x1 depth 1, comparison sampling)

  • If a texture without comparison mode is bound to a sampler2DShadow unit, WebGL refuses to draw, and if there is no depth texture, the Mac driver reports it.

반환ReturnsWebGLTexture 1x1 비교 깊이 텍스처.1x1 comparison depth texture.

메서드methoddraw(skinnedModel, viewProjectionElements, modelMatrixElements, cameraX, cameraY, cameraZ)#0.3.0 부터since 0.3.0소스source

출력. (모델 인스턴스의 드로어블 순회, 머티리얼 적용 + 조인트 행렬 업로드)

Draw. (iterates the model instance's drawables, applies materials + uploads joint matrices)

skinnedModelSkinnedModel
그릴 모델. (update 로 포즈를 셈한 뒤)Model to draw. (after its pose is computed with update)
viewProjectionElementsFloat32Array
보기와 투영을 곱한 행렬 원소. (열 우선 4x4)Elements of the combined view and projection matrix. (column-major 4x4)
modelMatrixElementsFloat32Array
모델 월드 행렬 원소. (열 우선 4x4)Elements of the model world matrix. (column-major 4x4)
cameraXnumber
카메라 월드 X.Camera world X.
cameraYnumber
카메라 월드 Y.Camera world Y.
cameraZnumber
카메라 월드 Z.Camera world Z.

짝Counterpart: vanilla-engine SkinnedModelRenderer.draw

메서드methoddrawDepth(skinnedModel, lightViewProjectionElements, modelMatrixElements)#0.3.0 부터since 0.3.0소스source

깊이 패스 출력. (섀도우 맵 캐스팅, ShadowMap.beginRender() 이후 호출)

Draws the depth pass. (shadow map casting, call after ShadowMap.beginRender())

skinnedModelSkinnedModel
그림자를 드리울 모델.Model that casts the shadow.
lightViewProjectionElementsFloat32Array
광원 뷰 투영 행렬 원소. (열 우선 4x4)Elements of the light view-projection matrix. (column-major 4x4)
modelMatrixElementsFloat32Array
모델 월드 행렬 원소. (열 우선 4x4)Elements of the model world matrix. (column-major 4x4)

짝Counterpart: vanilla-engine SkinnedModelRenderer.draw_depth

메서드methoddrawWireframe(skinnedModel, viewProjectionElements, modelMatrixElements, red, green, blue, alpha)#0.3.0 부터since 0.3.0소스source

와이어프레임 출력. (모서리 선, 모프 / 스키닝 반영, 블렌드 / 깊이 상태는 호출자가 잡는다)

  • 드로어블 버텍스 어레이의 엘리먼트 버퍼를 잠시 선 인덱스로 바꿔 그리고 원래 인덱스로 되돌린다.

Draws the wireframe. (edge lines, reflects morph / skinning, the caller sets blend / depth state)

  • Temporarily swaps the drawable vertex array's element buffer to line indices, draws, and restores the original indices.
skinnedModelSkinnedModel
선으로 그릴 모델. (처음 그릴 때 선 인덱스를 올린다)Model to draw as lines. (line indices are uploaded on the first draw)
viewProjectionElementsFloat32Array
보기와 투영을 곱한 행렬 원소. (열 우선 4x4)Elements of the combined view and projection matrix. (column-major 4x4)
modelMatrixElementsFloat32Array
모델 월드 행렬 원소. (열 우선 4x4)Elements of the model world matrix. (column-major 4x4)
rednumber
선 빨강. (0 ~ 1)Line red. (0 ~ 1)
greennumber
선 초록. (0 ~ 1)Line green. (0 ~ 1)
bluenumber
선 파랑. (0 ~ 1)Line blue. (0 ~ 1)
alphanumber
선 알파. (0 ~ 1, 섞기는 호출자가 켠다)Line alpha. (0 ~ 1, the caller enables blending)

짝Counterpart: vanilla-engine SkinnedModelRenderer.draw_wireframe

예제Example본 패스 위에 반투명 선 얹기Overlay translucent lines on the main pass
import { SkinnedModel, SkinnedModelRenderer, Camera3D, Matrix4, Vector3 } from "./build/vanilla.js";

const canvas = document.createElement("canvas");
const webGL2RenderingContext = canvas.getContext("webgl2");
const skinnedModelRenderer = new SkinnedModelRenderer(webGL2RenderingContext);
const skinnedModel = await SkinnedModel.loadFromUrl(webGL2RenderingContext, "examples/ancientmountain/assets/fox.glb", skinnedModelRenderer);
skinnedModel.update(0);
const camera = new Camera3D();
const eyePosition = Vector3.create(0, 80, 220);
const targetPosition = Vector3.create(0, 45, 0);
camera.setPerspective(1.0, 1, 2000);
camera.lookAt(eyePosition, targetPosition);
const viewProjectionMatrix = camera.getViewProjectionMatrix();
const viewProjectionElements = viewProjectionMatrix.getElements();
const modelMatrix = Matrix4.createIdentity();
const modelMatrixElements = modelMatrix.getElements();
webGL2RenderingContext.enable(webGL2RenderingContext.DEPTH_TEST);
skinnedModelRenderer.draw(skinnedModel, viewProjectionElements, modelMatrixElements, 0, 80, 220);
webGL2RenderingContext.enable(webGL2RenderingContext.BLEND);
webGL2RenderingContext.blendFunc(webGL2RenderingContext.SRC_ALPHA, webGL2RenderingContext.ONE_MINUS_SRC_ALPHA);
webGL2RenderingContext.depthFunc(webGL2RenderingContext.LEQUAL);
skinnedModelRenderer.drawWireframe(skinnedModel, viewProjectionElements, modelMatrixElements, 0.2, 1.0, 0.6, 0.5);
webGL2RenderingContext.depthFunc(webGL2RenderingContext.LESS);
webGL2RenderingContext.disable(webGL2RenderingContext.BLEND);
메서드methodapplyMorphUniforms(shaderProgram, drawable)#0.3.0 부터since 0.3.0소스source

모프 유니폼 적용. (드로어블의 모프 텍스처/가중치, 타깃이 없으면 개수 0 으로 비활성)

Applies morph uniforms. (drawable's morph texture/weights, disabled with count 0 if there are no targets)

shaderProgramShaderProgram
유니폼을 넣을 셰이더 프로그램. (use 한 뒤)Shader program to set uniforms on. (after use)
drawableobject
모델의 드로어블.A drawable of the model.

짝Counterpart: vanilla-engine SkinnedModelRenderer.apply_morph_uniforms

메서드methodsetShadowMap(shadowMapTexture, lightViewProjectionElements, texelSize)#0.3.0 부터since 0.3.0소스source

섀도우 맵 설정. (본 패스에서 그림자 수신)

Sets the shadow map. (receives shadows in the main pass)

shadowMapTextureWebGLTexture | null
섀도우 맵 깊이 텍스처. (비교 샘플링, null 이면 그림자를 받지 않는다)Shadow map depth texture. (comparison sampling, no shadows are received when null)
lightViewProjectionElementsFloat32Array | null
광원 뷰 투영 행렬 원소. (null 이면 그림자를 받지 않는다)Elements of the light view-projection matrix. (no shadows are received when null)
texelSizenumber
섀도우 맵 한 텍셀의 텍스처 좌표 크기. (1 / 해상도, 표본 간격)Size of one shadow map texel in texture coordinates. (1 / resolution, the sample spacing)

짝Counterpart: vanilla-engine SkinnedModelRenderer.set_shadow_map

메서드methodsetShadowStrength(shadowStrength)#0.3.0 부터since 0.3.0소스source

그림자 강도 설정. (0 = 수신 안 함)

Sets the shadow strength. (0 = no receiving)

shadowStrengthnumber
그림자 강도. (0 ~ 1, 기본 0)Shadow strength. (0 ~ 1, default 0)

짝Counterpart: vanilla-engine SkinnedModelRenderer.set_shadow_strength

메서드methodsetSunDirection(x, y, z)#0.3.0 부터since 0.3.0소스source

태양 방향 설정.

Sets the sun direction.

xnumber
표면에서 태양을 향하는 방향 X. (셰이더가 정규화한다, 기본 (0, 1, 0))X of the direction from the surface toward the sun. (normalized by the shader, default (0, 1, 0))
ynumber
표면에서 태양을 향하는 방향 Y.Y of the direction from the surface toward the sun.
znumber
표면에서 태양을 향하는 방향 Z.Z of the direction from the surface toward the sun.

짝Counterpart: vanilla-engine SkinnedModelRenderer.set_sun_direction

메서드methodsetFogColor(red, green, blue)#0.3.0 부터since 0.3.0소스source

안개 색 설정.

Sets the fog color.

rednumber
안개 빨강. (0 ~ 1, 기본 0.8)Fog red. (0 ~ 1, default 0.8)
greennumber
안개 초록. (0 ~ 1, 기본 0.85)Fog green. (0 ~ 1, default 0.85)
bluenumber
안개 파랑. (0 ~ 1, 기본 0.92)Fog blue. (0 ~ 1, default 0.92)

짝Counterpart: vanilla-engine SkinnedModelRenderer.set_fog_color

메서드methodsetFogRange(startDistance, endDistance)#0.3.0 부터since 0.3.0소스source

안개 거리 범위 설정.

Sets the fog distance range.

startDistancenumber
안개가 끼기 시작하는 카메라 거리. (월드 단위, 기본 55)Camera distance where fog begins. (world units, default 55)
endDistancenumber
안개가 다 덮는 카메라 거리. (월드 단위, 기본 250)Camera distance where fog fully covers. (world units, default 250)

짝Counterpart: vanilla-engine SkinnedModelRenderer.set_fog_range

메서드methodgetShaderProgram()#0.3.0 부터since 0.3.0소스source

셰이더 프로그램 반환. (스키닝 PBR 템플릿)

Returns the shader program. (skinning PBR template)

반환ReturnsShaderProgram 본 패스 셰이딩 프로그램.Main pass shading program.

짝Counterpart: vanilla-engine SkinnedModelRenderer.get_shader_program

메서드methodgetDepthShaderProgram()#0.3.0 부터since 0.3.0소스source

깊이 셰이더 프로그램 반환.

Returns the depth shader program.

반환ReturnsShaderProgram 깊이 전용 스키닝 프로그램.Depth-only skinning program.

짝Counterpart: vanilla-engine SkinnedModelRenderer.get_depth_shader_program

메서드methodgetWireframeShaderProgram()#0.3.0 부터since 0.3.0소스source

와이어프레임 셰이더 프로그램 반환.

Returns the wireframe shader program.

반환ReturnsShaderProgram 와이어프레임 스키닝 프로그램.Wireframe skinning program.

짝Counterpart: vanilla-engine SkinnedModelRenderer.get_wireframe_shader_program

메서드methodgetWebGL2RenderingContext()#0.3.0 부터since 0.3.0소스source

렌더링 컨텍스트 반환.

Returns the rendering context.

반환ReturnsWebGL2RenderingContext 렌더링 컨텍스트.Rendering context.

메서드methodgetEmptyShadowTexture()#0.4.0 부터since 0.4.0소스source

빈 그림자 텍스처 반환. (그림자를 받지 않을 때 섀도우 유닛에 묶는 1x1 비교 깊이 텍스처, 파생 렌더러가 같이 쓴다)

Returns the empty shadow texture. (1x1 comparison depth texture bound to the shadow unit when not receiving shadows, shared by derived renderers)

반환ReturnsWebGLTexture 1x1 비교 깊이 텍스처.1x1 comparison depth texture.

짝Counterpart: vanilla-engine SkinnedModelRenderer.get_empty_shadow_texture

상수Constants

상수constantMORPH_GLSL#0.3.0 부터since 0.3.0소스source

모프 타깃 GLSL. (버텍스 셰이더 삽입, 실수 텍스처의 위치/노멀 델타를 가중 합산)

  • 텍셀 인덱스 = gl_VertexID, 타깃 블록 = [위치 행들][노멀 행들] 순서.

Morph target GLSL. (inserted into the vertex shader, weighted sum of position/normal deltas from a float texture)

  • texel index = gl_VertexID, target block = [position rows][normal rows] order.

짝Counterpart: vanilla-engine MORPH_GLSL