-
如何实现淘宝小程序中的模型换装功能 |
Beta Was this translation helpful? Give feedback.
Answered by
MQL9011
Aug 31, 2022
Replies: 0 comments 4 replies
-
可以是替换贴图,也可以替换模型+贴图,看你们具体需求 |
Beta Was this translation helpful? Give feedback.
1 reply
-
以换贴图为例,加载好新的贴图后,执行如下代码: // 通过模型所在实体拿到模型的网格渲染器,如果模型是有动画的,就用 SkinnedMeshRenderer
const meshRenderer = gltfEntity.getComponent(MeshRenderer);
// 获取网格渲染器的材质
const material = meshRenderer.getMaterial();
// 给材质设置贴图即可完成替换贴图
material.baseTexture = texture; 如果是模型都换了,也就是重新加载模型和贴图,然后把老的去掉 |
Beta Was this translation helpful? Give feedback.
0 replies
-
首先需要用资源加载加载 Texture2D 资源, 也就是模型贴图
拿到texture后可以找个变量存一下 加载模型后
从模型中获取材质, 给材质设置上texture
设置贴图的核心代码是这几行
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
singlecoder
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
首先需要用资源加载加载 Texture2D 资源, 也就是模型贴图
拿到texture后可以找个变量存一下
加载模型后
从模型中获取材质, 给材质设置上texture