Skip to content

模型换装功能 #20

Answered by MQL9011
KingCyril asked this question in Engine
Aug 30, 2022 · 0 comments · 4 replies
Discussion options

You must be logged in to vote

首先需要用资源加载加载 Texture2D 资源, 也就是模型贴图

// 加载资源
  async resourceLoadTexture2D(url) {
    return new Promise((resolve) => {
      (this.engine as WebGLEngine).resourceManager
        .load<Texture2D>({
          url,
        })
        .then((texture) => {
          resolve(texture);
        });
    });
  },

拿到texture后可以找个变量存一下

加载模型后

// 加载模型
  async resourceLoadGLTF(url) {
    return new Promise((resolve) => {
      (this.engine as WebGLEngine).resourceManager
        .load<GLTFResource>(url)
        .then((gltf) => {
          resolve(gltf);
        });
    });
  },

从模型中获取材质, 给材质设置上texture

 // 加载篮球
    const lanqiu_gltf = await this.resourceLoadGLTF(LANQIU_GLTF);
    const entity_lanqiu = roo…

Replies: 0 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@KingCyril
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by singlecoder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Engine
Labels
None yet
3 participants