graphics3d/skinnedmodelasset
스킨드 모델 자산. (같은 파일에서 지은 모델 인스턴스들이 나눠 쓰는 풀린 자료와 GPU 자원)
Skinned model asset. (decoded data and GPU resources shared by the model instances built from the same file)
SkinnedModelAssetextends Object
스킨드 모델 자산. (같은 파일에서 지은 모델 인스턴스들이 나눠 쓰는 풀린 자료와 GPU 자원)
- 메시 버퍼와 버텍스 어레이, 머티리얼 원형과 그 텍스처, 모프 텍스처, 노드와 스킨 원형, 애니메이션 클립을 한 벌만 든다. (유니티의 메시와 sharedMaterial, three.js 의 BufferGeometry 와 Material 을 복제본들이 나눠 쓰는 것과 같다)
- 인스턴스(SkinnedModel)는 이것을 참조 수로 나눠 쓴다. 인스턴스마다 따로 갖는 것은 포즈, 애니메이션 재생 상태, 모프 가중치, 갈라진 머티리얼(getMaterial), 와이어프레임 버퍼, addMorphTarget 으로 갈라진 모프 텍스처다.
- 마지막 인스턴스가 destroy 하면(참조 수 0) GPU 자원을 지우고 캐시에서 빠진다.
- 캐시는 셰이더 프로그램과 자산 키(normalizeKey 로 정규화한 주소나 자산 이름)로 찾는다. SkinnedModel.loadFromUrl 같은 받기가 이것을 쓴다.
Skinned model asset. (decoded data and GPU resources shared by the model instances built from the same file)
- Holds one copy of the mesh buffers and vertex arrays, the material prototypes and their textures, the morph textures, the node and skin prototypes and the animation clips. (the same as clones sharing Unity's mesh and sharedMaterial, or three.js BufferGeometry and Material)
- Instances (SkinnedModel) share it by reference count. Each instance keeps its own pose, animation playback state, morph weights, forked materials (getMaterial), wireframe buffers and morph textures forked by addMorphTarget.
- When the last instance calls destroy (reference count 0), the GPU resources are deleted and the asset leaves the cache.
- The cache is looked up by shader program and asset key (a path or asset name normalized with normalizeKey). Loads such as SkinnedModel.loadFromUrl use it.
import { SkinnedModel, SkinnedModelAsset, SkinnedModelRenderer } from "./build/vanilla.js";
const canvas = document.createElement("canvas");
const webGL2RenderingContext = canvas.getContext("webgl2");
const skinnedModelRenderer = new SkinnedModelRenderer(webGL2RenderingContext);
const firstModel = await SkinnedModel.loadFromUrl(webGL2RenderingContext, "examples/ancientmountain/assets/fox.glb", skinnedModelRenderer);
const secondModel = await SkinnedModel.loadFromUrl(webGL2RenderingContext, "./examples/ancientmountain/assets/fox.glb", skinnedModelRenderer);
const skinnedModelAsset = firstModel.getAsset();
console.log(skinnedModelAsset === secondModel.getAsset(), skinnedModelAsset.getReferenceCount(), skinnedModelAsset.getKey());
firstModel.destroy();
secondModel.destroy();
console.log(skinnedModelAsset.getReferenceCount(), skinnedModelAsset.isDestroyed(), SkinnedModelAsset.getCachedCount());생성. (SkinnedModel.uploadMeshesAndMaterials 가 올린 뒤 짓는다, 참조 수 1)
Constructor. (built by SkinnedModel.uploadMeshesAndMaterials after uploading, reference count 1)
- webGL2RenderingContextWebGL2RenderingContext
- 자원을 지은 렌더링 컨텍스트.Rendering context the resources were created with.
- shaderProgramShaderProgram
- 버텍스 어레이와 머티리얼이 쓰는 셰이더 프로그램.Shader program used by the vertex arrays and materials.
- contentobject
- 나눠 쓸 자료. ({ drawableList, materialList, nodeList, rootNodeIndices, skinList, animationList, bufferByteCount }, 드로어블은 원형으로 두고 인스턴스가 베낀다)Data to share. ({ drawableList, materialList, nodeList, rootNodeIndices, skinList, animationList, bufferByteCount }, drawables stay as prototypes that instances copy)
짝Counterpart: vanilla-engine SkinnedModelAsset.new
자산 키 정규화. (정적, 역슬래시를 / 로, "." 과 ".." 마디를 풀고 빈 마디를 줄인다, 앞의 "주소틀://" 과 뒤의 ?, # 은 그대로)
- 같은 파일을 "./a/b.glb", "a/c/../b.glb" 처럼 다르게 적어도 같은 키가 되게 한다. 기준 주소로 절대 주소를 만들지는 않는다.
Normalize an asset key. (static: backslashes become /, "." and ".." segments are resolved and empty segments dropped; a leading "scheme://" and a trailing ? or # part stay as they are)
- The same file written differently, such as "./a/b.glb" and "a/c/../b.glb", gets the same key. It does not resolve against a base URL into an absolute one.
- pathstring
- 자산 주소나 이름.Asset path or name.
반환Returnsstring 정규화한 키.Normalized key.
짝Counterpart: vanilla-engine SkinnedModelAsset.normalize_key
import { SkinnedModelAsset } from "./build/vanilla.js";
console.log(SkinnedModelAsset.normalizeKey("./assets/models/../fox.glb"));
console.log(SkinnedModelAsset.normalizeKey("assets\\fox.glb"));
console.log(SkinnedModelAsset.normalizeKey("https://example.com/a/./b/../fox.glb?v=2"));캐시에서 찾기. (정적, 셰이더 프로그램과 키가 같고 살아 있는 자산)
Find in the cache. (static, a live asset with the same shader program and key)
- assetKeystring
- 자산 키. (normalizeKey 로 정규화한다)Asset key. (normalized with normalizeKey)
- shaderProgramShaderProgram
- 모델을 그릴 셰이더 프로그램. (렌더러의 getShaderProgram)Shader program the model is drawn with. (the renderer's getShaderProgram)
반환ReturnsSkinnedModelAsset | null 찾은 자산. (없으면 null)Asset found. (null if none)
짝Counterpart: vanilla-engine SkinnedModelAsset.find
캐시에 넣기. (정적, 자산에 키를 붙인다. 같은 자리에 있던 자산은 캐시에서만 빠지고 쓰던 인스턴스는 그대로 쓴다)
Add to the cache. (static, gives the asset the key. An asset that held the same slot only leaves the cache, and instances using it keep working)
- assetKeystring
- 자산 키. (normalizeKey 로 정규화한다)Asset key. (normalized with normalizeKey)
- assetSkinnedModelAsset
- 넣을 자산. (지워진 자산이면 오류를 던진다)Asset to add. (throws if the asset was destroyed)
짝Counterpart: vanilla-engine SkinnedModelAsset.register
import { SkinnedModel, SkinnedModelAsset, SkinnedModelRenderer } from "./build/vanilla.js";
const canvas = document.createElement("canvas");
const webGL2RenderingContext = canvas.getContext("webgl2");
const skinnedModelRenderer = new SkinnedModelRenderer(webGL2RenderingContext);
const response = await fetch("examples/ancientmountain/assets/fox.glb");
const arrayBuffer = await response.arrayBuffer();
const skinnedModel = await SkinnedModel.loadFromBytes(webGL2RenderingContext, arrayBuffer, skinnedModelRenderer);
SkinnedModelAsset.register("fox", skinnedModel.getAsset());
const shaderProgram = skinnedModelRenderer.getShaderProgram();
const foundAsset = SkinnedModelAsset.find("fox", shaderProgram);
const otherModel = SkinnedModel.createFromAsset(foundAsset);
console.log(foundAsset.getReferenceCount(), otherModel.getDrawableList().length);
otherModel.destroy();
skinnedModel.destroy();캐시 비우기. (정적, 모든 자산을 캐시에서 뺀다. 쓰던 인스턴스는 그대로 그리고, 마지막 인스턴스가 destroy 할 때 GPU 자원이 지워진다)
- 다음 받기는 파일을 새로 풀어 새 자산을 짓는다.
Clear the cache. (static, removes every asset from the cache. Instances in use keep drawing, and the GPU resources are deleted when the last instance calls destroy)
- The next load parses the file again into a new asset.
짝Counterpart: vanilla-engine SkinnedModelAsset.clear_cache
import { SkinnedModelAsset } from "./build/vanilla.js";
SkinnedModelAsset.clearCache();
console.log(SkinnedModelAsset.getCachedCount());캐시에 든 자산 수. (정적, 모든 셰이더 프로그램 합)
Number of assets in the cache. (static, sum over all shader programs)
반환Returnsnumber 캐시에 든 자산 수.Number of assets in the cache.
짝Counterpart: vanilla-engine SkinnedModelAsset.get_cached_count
참조 늘리기. (인스턴스가 자산을 나눠 쓰기 시작할 때, SkinnedModel.createFromAsset 이 부른다)
Add a reference. (when an instance starts sharing the asset, called by SkinnedModel.createFromAsset)
짝Counterpart: vanilla-engine SkinnedModelAsset.retain
참조 줄이기. (인스턴스가 destroy 할 때, 0 이 되면 GPU 자원을 지우고 캐시에서 빠진다)
Remove a reference. (when an instance calls destroy; at 0 the GPU resources are deleted and the asset leaves the cache)
반환Returnsboolean 이번에 자원을 지웠으면 참.True if this call deleted the resources.
짝Counterpart: vanilla-engine SkinnedModelAsset.release
자산 키 반환.
Return the asset key.
반환Returnsstring | null 캐시에 넣은 키. (넣지 않았거나 캐시에서 빠졌으면 null)Key added to the cache. (null if never added or removed from the cache)
짝Counterpart: vanilla-engine SkinnedModelAsset.get_key
참조 수 반환. (이 자산을 나눠 쓰는 살아 있는 인스턴스 수)
Return the reference count. (number of live instances sharing this asset)
반환Returnsnumber 참조 수. (지워졌으면 0)Reference count. (0 once destroyed)
짝Counterpart: vanilla-engine SkinnedModelAsset.get_reference_count
지워졌는지.
Whether destroyed.
반환Returnsboolean 마지막 인스턴스가 destroy 해 GPU 자원을 지웠으면 참.True if the last instance called destroy and the GPU resources were deleted.
짝Counterpart: vanilla-engine SkinnedModelAsset.is_destroyed
GPU 바이트 수. (정점, 인덱스 버퍼와 모프 텍스처와 머티리얼 원형 텍스처, 밉맵 포함, 인스턴스 수와 상관없이 한 벌)
GPU byte count. (vertex and index buffers, morph textures and material prototype textures including mipmaps, one copy regardless of the instance count)
반환Returnsnumber 이 자산이 GPU 에 올린 바이트 수. (지워졌으면 0)Bytes this asset uploaded to the GPU. (0 once destroyed)
짝Counterpart: vanilla-engine SkinnedModelAsset.get_gpu_byte_count
렌더링 컨텍스트 반환.
Returns the rendering context.
반환ReturnsWebGL2RenderingContext 자원을 지은 렌더링 컨텍스트.Rendering context the resources were created with.
셰이더 프로그램 반환.
Returns the shader program.
반환ReturnsShaderProgram 버텍스 어레이와 머티리얼이 쓰는 셰이더 프로그램.Shader program used by the vertex arrays and materials.
짝Counterpart: vanilla-engine SkinnedModelAsset.get_shader_program
원형 드로어블 목록 반환. (인스턴스는 이것을 베껴 버퍼와 머티리얼 원형을 나눠 쓴다, 바꾸지 않는다)
Return the prototype drawable list. (instances copy it to share the buffers and material prototypes; do not change it)
반환Returnsobject[] 원형 드로어블 목록.Prototype drawable list.
짝Counterpart: vanilla-engine SkinnedModelAsset.get_drawable_list
머티리얼 원형 목록 반환. (기본 머티리얼이 마지막, 이 자산이 지었고 마지막 인스턴스가 destroy 할 때 지운다)
Return the material prototype list. (the default material is last; this asset created them and deletes them when the last instance calls destroy)
반환ReturnsMaterial[] 머티리얼 원형 목록. (sharedMaterial, 값을 바꾸면 이 자산을 쓰는 모든 인스턴스가 바뀐다)Material prototype list. (sharedMaterial; changing a value changes every instance using this asset)
짝Counterpart: vanilla-engine SkinnedModelAsset.get_material_list
노드 원형 목록 반환. (올릴 때의 노드, 인스턴스는 이것을 베껴 포즈를 따로 든다)
Return the node prototype list. (the nodes at upload; instances copy them and keep their own pose)
반환Returnsobject[] 노드 원형 목록.Node prototype list.
짝Counterpart: vanilla-engine SkinnedModelAsset.get_node_list
루트 노드 목록 반환.
Return the root node list.
반환Returnsnumber[] 루트 노드 번호 목록.Root node index list.
짝Counterpart: vanilla-engine SkinnedModelAsset.get_root_node_indices
스킨 원형 목록 반환. (조인트와 역바인드 행렬은 나눠 쓰고, 조인트 행렬 배열은 인스턴스마다 따로)
Return the skin prototype list. (joints and inverse bind matrices are shared, the joint matrix array is per instance)
반환Returnsobject[] 스킨 원형 목록.Skin prototype list.
짝Counterpart: vanilla-engine SkinnedModelAsset.get_skin_list
애니메이션 클립 목록 반환. (인스턴스가 모두 같은 목록을 나눠 쓴다, addAnimationsFromFbx* 로 더한 클립도 모두에게 보인다)
Return the animation clip list. (all instances share the same list; clips added with addAnimationsFromFbx* are visible to all)
반환Returnsobject[] 애니메이션 클립 목록.Animation clip list.
짝Counterpart: vanilla-engine SkinnedModelAsset.get_animation_list