在淘宝小程序中,无法获取材质 #14
Answered
by
singlecoder
flyingflyfly
asked this question in
Mini Program(小程序)
-
1、模型:https://next-ubanner.oss-cn-beijing.aliyuncs.com/AE_BODY_MOVIN/TMP/2afcc40b678752f3c547a13124f7bef2/0002.gltf |
Beta Was this translation helpful? Give feedback.
Answered by
singlecoder
Sep 1, 2022
Replies: 0 comments 1 reply
-
你这个模型完整获取材质方式如下: const gltf = await engine.resourceManager.load<GLTFResource>(
"https://gw.alipayobjects.com/os/OasisHub/267000040/9994/%25E5%25BD%2592%25E6%25A1%25A3.gltf"
);
const gltfEntity = gltf.defaultSceneRoot;
rootEntity.addChild(gltfEntity);
// 获取有 MeshRenderer 组件的子节点
const meshEntity = gltfEntity.children[0];
const meshRenderer = meshEntity.getComponent(MeshRenderer);
const material = meshRenderer.getMaterial(); 原因: 模型加载后,美术给出模型并不一定就是挂在根节点,这个时候最好可以打印下查看子节点,打印 gltf.defaultSceneRoot 可以查看加载模型的结构,如下: 也可以通过 API 直接查找到所有 MeshRenderer,如下: const result: Array<MeshRenderer> = [];
gltf.defaultSceneRoot.getComponentsIncludeChildren(MeshRenderer, result); |
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
你这个模型完整获取材质方式如下:
原因:
模型加载后,美术给出模型并不一定就是挂在根节点,这个时候最好可以打印下查看子节点,打印 gltf.defaultSceneRoot 可以查看加载模型的结构,如下:
也可以通过 API 直接查找到所有 MeshRenderer,如下: