vanilladocs
vanillapunch.com
API / graphics3d/skinnedmodelasset

graphics3d/skinnedmodelasset

스킨드 모델 자산. (원본 graphics3d/skinnedmodelasset.js)

  • 같은 파일에서 지은 모델 인스턴스들이 나눠 쓰는 풀린 자료와 GPU 자원이다. 메시 버퍼와 버텍스 어레이, 머티리얼 원형과 그 텍스처, 모프 텍스처, 노드와 스킨 원형, 애니메이션 클립을 한 벌만 든다. (유니티의 메시와 sharedMaterial, three.js 의 BufferGeometry 와 Material 을 복제본들이 나눠 쓰는 것과 같다)
  • 인스턴스(SkinnedModel)는 이것을 참조 수로 나눠 쓴다. 인스턴스마다 따로 갖는 것은 포즈, 애니메이션 재생 상태, 모프 가중치, 갈라진 머티리얼(get_material), 와이어프레임 버퍼, add_morph_target 으로 갈라진 모프 텍스처다.
  • 마지막 인스턴스가 destroy 하면(참조 수 0) GPU 자원을 지우고 캐시에서 빠진다. 참조 수는 Rc 의 수가 아니라 retain / release 로 센다. (원본과 같은 수, get_asset 으로 Rc 를 더 쥐어도 자원 수명은 인스턴스 수를 따른다)
  • 캐시는 셰이더 프로그램과 자산 키(normalize_key 로 정규화한 주소나 자산 이름)로 찾는다. 받기 손잡이의 create_model, load_from_url_async 같은 받기가 이것을 쓴다. 캐시는 스레드마다 하나다. (GL 컨텍스트가 스레드에 묶여서다)

Skinned model asset. (original graphics3d/skinnedmodelasset.js)

  • 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 (get_material), wireframe buffers and morph textures forked by add_morph_target.
  • When the last instance calls destroy (reference count 0), the GPU resources are deleted and the asset leaves the cache. The reference count is kept by retain / release, not by the Rc count. (the same count as the original; holding more Rc through get_asset does not extend the resource lifetime beyond the instances)
  • The cache is looked up by shader program and asset key (a path or asset name normalized with normalize_key). Loads such as the load handle's create_model and load_from_url_async use it. There is one cache per thread. (because a GL context is bound to a thread)
예제Example키 정규화와 빈 캐시Key normalization and an empty cache
use vanilla::SkinnedModelAsset;

assert_eq!(SkinnedModelAsset::normalize_key("./assets/models/../fox.glb"), "assets/fox.glb");
SkinnedModelAsset::clear_cache();
assert_eq!(SkinnedModelAsset::get_cached_count(), 0);

SkinnedModelAssetContentstruct

소스source

자산에 넣을 자료. (SkinnedModel::upload_meshes_and_materials 가 올린 뒤 채운다, 원본 생성자의 content 객체)

Data to put in an asset. (filled by SkinnedModel::upload_meshes_and_materials after uploading, the original constructor's content object)

예제Example자료의 루트 노드 수 읽기 (자료는 SkinnedModel::upload_meshes_and_materials 가 채운다)Reading the root node count of the data (the data is filled by SkinnedModel::upload_meshes_and_materials)
use vanilla::SkinnedModelAssetContent;

fn read_root_count(content: &SkinnedModelAssetContent) -> usize {
	content.root_node_indices.len()
}
let _ = read_root_count;
필드fieldpub drawable_list: Vec<Drawable>#0.4.0 부터since 0.4.0소스source

원형 드로어블 목록. (인스턴스는 이것을 베껴 버퍼와 머티리얼 원형을 나눠 쓴다)

Prototype drawable list. (instances copy it to share the buffers and material prototypes)

반환ReturnsVec<Drawable>

필드fieldpub material_list: Vec<Rc<Material>>#0.4.0 부터since 0.4.0소스source

머티리얼 원형 목록. (기본 머티리얼이 마지막, 마지막 인스턴스가 destroy 할 때 지운다)

Material prototype list. (the default material is last, deleted when the last instance calls destroy)

반환ReturnsVec<Rc<Material>>

필드fieldpub node_list: Vec<SkinnedModelNode>#0.4.0 부터since 0.4.0소스source

노드 원형 목록. (올릴 때의 노드)

Node prototype list. (the nodes at upload)

반환ReturnsVec<SkinnedModelNode>

필드fieldpub root_node_indices: Vec<usize>#0.4.0 부터since 0.4.0소스source

루트 노드 번호 목록.

Root node index list.

반환ReturnsVec<usize>

필드fieldpub skin_list: Vec<Skin>#0.4.0 부터since 0.4.0소스source

스킨 원형 목록.

Skin prototype list.

반환ReturnsVec<Skin>

필드fieldpub animation_list: Rc<RefCell<Vec<AnimationClip>>>#0.4.0 부터since 0.4.0소스source

애니메이션 클립 목록. (인스턴스가 모두 같은 목록을 나눠 쓴다)

Animation clip list. (all instances share the same list)

반환ReturnsRc<RefCell<Vec<AnimationClip>>>

필드fieldpub buffer_byte_count: usize#0.4.0 부터since 0.4.0소스source

정점, 인덱스 버퍼와 모프 텍스처의 GPU 바이트 수.

GPU bytes of the vertex and index buffers and morph textures.

반환Returnsusize

SkinnedModelAssetstruct

짝Counterpart: vanilla.js SkinnedModelAsset소스source

스킨드 모델 자산. (같은 파일에서 지은 모델 인스턴스들이 나눠 쓰는 풀린 자료와 GPU 자원, 참조 수로 수명을 센다)

Skinned model asset. (decoded data and GPU resources shared by the model instances built from the same file, lifetime counted by reference count)

예제Example받은 모델을 열 마리로 늘리고 자산 하나를 나눠 쓰는지 보기Spawn ten from a loaded model and check that they share one asset
use vanilla::{SkinnedModel, SkinnedModelAsset};

fn spawn_herd(gl: &vanilla::GlContext, source_model: &SkinnedModel) -> Result<Vec<SkinnedModel>, String> {
	let mut model_list = Vec::new();
	for _ in 0..10 {
		model_list.push(source_model.create_instance()?);
	}
	let skinned_model_asset = source_model.get_asset().ok_or("no asset")?;
	assert_eq!(skinned_model_asset.get_reference_count(), 11);
	println!("{} bytes on GPU", skinned_model_asset.get_gpu_byte_count());
	let _ = gl;
	Ok(model_list)
}
생성자constructorpub fn new(shader_program: Rc<ShaderProgram>, content: SkinnedModelAssetContent) -> SkinnedModelAsset#0.4.0 부터since 0.4.0소스source

생성. (SkinnedModel::upload_meshes_and_materials 가 올린 뒤 짓는다, 참조 수 1)

Constructor. (built by SkinnedModel::upload_meshes_and_materials after uploading, reference count 1)

shader_programRc<ShaderProgram>
버텍스 어레이와 머티리얼이 쓰는 셰이더 프로그램.Shader program used by the vertex arrays and materials.
contentSkinnedModelAssetContent
나눠 쓸 자료. (드로어블은 원형으로 두고 인스턴스가 베낀다)Data to share. (drawables stay as prototypes that instances copy)

반환ReturnsSkinnedModelAsset 참조 수 1, 캐시 밖의 자산.Asset with reference count 1, outside the cache.

짝Counterpart: vanilla.js SkinnedModelAsset.constructor

정적staticpub fn normalize_key(path: &str) -> String#0.4.0 부터since 0.4.0소스source

자산 키 정규화. (역슬래시를 / 로, "." 과 ".." 마디를 풀고 빈 마디를 줄인다, 앞의 "주소틀://" 과 뒤의 ?, # 은 그대로)

  • 같은 파일을 "./a/b.glb", "a/c/../b.glb" 처럼 다르게 적어도 같은 키가 되게 한다. 기준 주소로 절대 주소를 만들지는 않는다.

Normalize an asset key. (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.
path&str
자산 주소나 이름.Asset path or name.

반환ReturnsString 정규화한 키.Normalized key.

짝Counterpart: vanilla.js SkinnedModelAsset.normalizeKey

예제Example다르게 적은 같은 경로The same path written differently
use vanilla::SkinnedModelAsset;

assert_eq!(SkinnedModelAsset::normalize_key("./assets/models/../fox.glb"), "assets/fox.glb");
assert_eq!(SkinnedModelAsset::normalize_key("assets\\fox.glb"), "assets/fox.glb");
assert_eq!(SkinnedModelAsset::normalize_key("https://example.com/a/./b/../fox.glb?v=2"), "https://example.com/a/fox.glb?v=2");
정적staticpub fn find(asset_key: &str, shader_program: &Rc<ShaderProgram>) -> Option<Rc<SkinnedModelAsset>>#0.4.0 부터since 0.4.0소스source

캐시에서 찾기. (셰이더 프로그램과 키가 같고 살아 있는 자산)

Find in the cache. (a live asset with the same shader program and key)

asset_key&str
자산 키. (normalize_key 로 정규화한다)Asset key. (normalized with normalize_key)
shader_program&Rc<ShaderProgram>
모델을 그릴 셰이더 프로그램. (렌더러의 get_shader_program)Shader program the model is drawn with. (the renderer's get_shader_program)

반환ReturnsOption<Rc<SkinnedModelAsset>> 찾은 자산. (없으면 None)Asset found. (None if none)

짝Counterpart: vanilla.js SkinnedModelAsset.find

정적staticpub fn register(asset_key: &str, asset: &Rc<SkinnedModelAsset>) -> Result<(), String>#0.4.0 부터since 0.4.0소스source

캐시에 넣기. (자산에 키를 붙인다. 같은 자리에 있던 자산은 캐시에서만 빠지고 쓰던 인스턴스는 그대로 쓴다)

Add to the cache. (gives the asset the key. An asset that held the same slot only leaves the cache, and instances using it keep working)

asset_key&str
자산 키. (normalize_key 로 정규화한다)Asset key. (normalized with normalize_key)
asset&Rc<SkinnedModelAsset>
넣을 자산.Asset to add.

반환ReturnsResult<(), String> 넣었으면 Ok. 지워진 자산이면 Err.Ok if added. Err if the asset was destroyed.

짝Counterpart: vanilla.js SkinnedModelAsset.register

예제Example번들에서 꺼낸 바이트로 지은 모델을 이름으로 나눠 쓰기Share a model built from bundled bytes by name
use vanilla::{SkinnedModel, SkinnedModelAsset, SkinnedModelRenderer};

fn load_named_model(gl: &vanilla::GlContext, bytes: &[u8], skinned_model_renderer: &SkinnedModelRenderer) -> Result<SkinnedModel, String> {
	if let Some(found_asset) = SkinnedModelAsset::find("fox", &skinned_model_renderer.get_shader_program()) {
		return SkinnedModel::create_from_asset(&found_asset);
	}
	let skinned_model = SkinnedModel::load_from_bytes(gl, bytes, skinned_model_renderer)?;
	SkinnedModelAsset::register("fox", skinned_model.get_asset().ok_or("no asset")?)?;
	Ok(skinned_model)
}
정적staticpub fn clear_cache()#0.4.0 부터since 0.4.0소스source

캐시 비우기. (모든 자산을 캐시에서 뺀다. 쓰던 인스턴스는 그대로 그리고, 마지막 인스턴스가 destroy 할 때 GPU 자원이 지워진다)

  • 다음 받기는 파일을 새로 풀어 새 자산을 짓는다.

Clear the cache. (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.js SkinnedModelAsset.clearCache

예제Example판을 바꿀 때 캐시를 비우기Clear the cache when switching stages
use vanilla::SkinnedModelAsset;

SkinnedModelAsset::clear_cache();
assert_eq!(SkinnedModelAsset::get_cached_count(), 0);
정적staticpub fn get_cached_count() -> usize#0.4.0 부터since 0.4.0소스source

캐시에 든 자산 수. (모든 셰이더 프로그램 합)

Number of assets in the cache. (sum over all shader programs)

반환Returnsusize 캐시에 든 자산 수.Number of assets in the cache.

짝Counterpart: vanilla.js SkinnedModelAsset.getCachedCount

메서드methodpub fn retain(&self) -> Result<(), String>#0.4.0 부터since 0.4.0소스source

참조 늘리기. (인스턴스가 자산을 나눠 쓰기 시작할 때, SkinnedModel::create_from_asset 이 부른다)

Add a reference. (when an instance starts sharing the asset, called by SkinnedModel::create_from_asset)

반환ReturnsResult<(), String> 늘렸으면 Ok. 지워진 자산이면 Err.Ok if added. Err if the asset was destroyed.

짝Counterpart: vanilla.js SkinnedModelAsset.retain

메서드methodpub fn release(&self, gl: &GlContext) -> bool#0.4.0 부터since 0.4.0소스source

참조 줄이기. (인스턴스가 destroy 할 때, 0 이 되면 GPU 자원을 지우고 캐시에서 빠진다)

Remove a reference. (when an instance calls destroy; at 0 the GPU resources are deleted and the asset leaves the cache)

gl&GlContext
자원을 지은 GL 컨텍스트.GL context the resources were created with.

반환Returnsbool 이번에 자원을 지웠으면 true.true if this call deleted the resources.

짝Counterpart: vanilla.js SkinnedModelAsset.release

메서드methodpub fn get_key(&self) -> Option<String>#0.4.0 부터since 0.4.0소스source

자산 키 반환.

Return the asset key.

반환ReturnsOption<String> 캐시에 넣은 키. (넣지 않았거나 캐시에서 빠졌으면 None)Key added to the cache. (None if never added or removed from the cache)

짝Counterpart: vanilla.js SkinnedModelAsset.getKey

메서드methodpub fn get_reference_count(&self) -> usize#0.4.0 부터since 0.4.0소스source

참조 수 반환. (이 자산을 나눠 쓰는 살아 있는 인스턴스 수)

Return the reference count. (number of live instances sharing this asset)

반환Returnsusize 참조 수. (지워졌으면 0)Reference count. (0 once destroyed)

짝Counterpart: vanilla.js SkinnedModelAsset.getReferenceCount

메서드methodpub fn is_destroyed(&self) -> bool#0.4.0 부터since 0.4.0소스source

지워졌는지.

Whether destroyed.

반환Returnsbool 마지막 인스턴스가 destroy 해 GPU 자원을 지웠으면 true.true if the last instance called destroy and the GPU resources were deleted.

짝Counterpart: vanilla.js SkinnedModelAsset.isDestroyed

메서드methodpub fn get_gpu_byte_count(&self) -> usize#0.4.0 부터since 0.4.0소스source

GPU 바이트 수. (정점, 인덱스 버퍼와 모프 텍스처와 머티리얼 원형 텍스처, 밉맵 포함, 인스턴스 수와 상관없이 한 벌)

GPU byte count. (vertex and index buffers, morph textures and material prototype textures including mipmaps, one copy regardless of the instance count)

반환Returnsusize 이 자산이 GPU 에 올린 바이트 수. (지워졌으면 0)Bytes this asset uploaded to the GPU. (0 once destroyed)

짝Counterpart: vanilla.js SkinnedModelAsset.getGpuByteCount

메서드methodpub fn get_shader_program(&self) -> &Rc<ShaderProgram>#0.4.0 부터since 0.4.0소스source

셰이더 프로그램 반환.

Returns the shader program.

반환Returns&Rc<ShaderProgram> 버텍스 어레이와 머티리얼이 쓰는 셰이더 프로그램.Shader program used by the vertex arrays and materials.

짝Counterpart: vanilla.js SkinnedModelAsset.getShaderProgram

메서드methodpub fn get_drawable_list(&self) -> Ref<'_, Vec<Drawable>>#0.4.0 부터since 0.4.0소스source

원형 드로어블 목록 반환. (인스턴스는 이것을 베껴 버퍼와 머티리얼 원형을 나눠 쓴다)

Return the prototype drawable list. (instances copy it to share the buffers and material prototypes)

반환ReturnsRef<'_, Vec<Drawable>> 원형 드로어블 목록. (지워졌으면 비어 있다)Prototype drawable list. (empty once destroyed)

짝Counterpart: vanilla.js SkinnedModelAsset.getDrawableList

메서드methodpub fn get_material_list(&self) -> Ref<'_, Vec<Rc<Material>>>#0.4.0 부터since 0.4.0소스source

머티리얼 원형 목록 반환. (기본 머티리얼이 마지막, 이 자산이 지었고 마지막 인스턴스가 destroy 할 때 지운다)

Return the material prototype list. (the default material is last; this asset created them and deletes them when the last instance calls destroy)

반환ReturnsRef<'_, Vec<Rc<Material>>> 머티리얼 원형 목록. (sharedMaterial, 값을 바꾸면 이 자산을 쓰는 모든 인스턴스가 바뀐다)Material prototype list. (sharedMaterial; changing a value changes every instance using this asset)

짝Counterpart: vanilla.js SkinnedModelAsset.getMaterialList

메서드methodpub fn get_node_list(&self) -> &[SkinnedModelNode]#0.4.0 부터since 0.4.0소스source

노드 원형 목록 반환. (올릴 때의 노드, 인스턴스는 이것을 베껴 포즈를 따로 든다)

Return the node prototype list. (the nodes at upload; instances copy them and keep their own pose)

반환Returns&[SkinnedModelNode] 노드 원형 목록.Node prototype list.

짝Counterpart: vanilla.js SkinnedModelAsset.getNodeList

메서드methodpub fn get_root_node_indices(&self) -> &[usize]#0.4.0 부터since 0.4.0소스source

루트 노드 목록 반환.

Return the root node list.

반환Returns&[usize] 루트 노드 번호 목록.Root node index list.

짝Counterpart: vanilla.js SkinnedModelAsset.getRootNodeIndices

메서드methodpub fn get_skin_list(&self) -> &[Skin]#0.4.0 부터since 0.4.0소스source

스킨 원형 목록 반환. (조인트와 역바인드 행렬을 인스턴스가 베낀다)

Return the skin prototype list. (instances copy the joints and inverse bind matrices)

반환Returns&[Skin] 스킨 원형 목록.Skin prototype list.

짝Counterpart: vanilla.js SkinnedModelAsset.getSkinList

메서드methodpub fn get_animation_list(&self) -> &Rc<RefCell<Vec<AnimationClip>>>#0.4.0 부터since 0.4.0소스source

애니메이션 클립 목록 반환. (인스턴스가 모두 같은 목록을 나눠 쓴다, add_animations_from_fbx_* 로 더한 클립도 모두에게 보인다)

Return the animation clip list. (all instances share the same list; clips added with add_animations_from_fbx_* are visible to all)

반환Returns&Rc<RefCell<Vec<AnimationClip>>> 나눠 든 클립 목록.Shared clip list.

짝Counterpart: vanilla.js SkinnedModelAsset.getAnimationList