원클릭으로
galacean-resource
此 Skill 包含了在 Galacean Engine 中通过 ResourceManager 加载资源(GLTF 模型、纹理等)的核心模式
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
此 Skill 包含了在 Galacean Engine 中通过 ResourceManager 加载资源(GLTF 模型、纹理等)的核心模式
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
此 Skill 约定了 Galacean Engine 中自定义着色器的编写方式,包含 Shader.create、BaseMaterial 参数绑定、动画驱动、透明混合与常见排错。
此 Skill 包含了使用 Galacean Engine 物理引擎的注意事项、距离检测替代方案以及常见问题解决方案
此 Skill 包含了在 Galacean Engine 中通过 Script 脚本处理物体交互(如点击)的核心模式,基于 onPointerClick 实现
此 Skill 包含了在 Galacean Engine 中创建物理碰撞体的核心模式,涵盖动态碰撞体 (DynamicCollider) 和 静态碰撞体 (StaticCollider) 的实现
使用 Galacean Engine 开发2D游戏的核心模式,包括真2D(Sprite)和伪2D(3D正交投影)实现
此 Skill 包含了 Galacean Engine 相机的配置方法,包括透视/正交投影设置、俯视视角配置、窗口适配等
| name | galacean-resource |
| description | 此 Skill 包含了在 Galacean Engine 中通过 ResourceManager 加载资源(GLTF 模型、纹理等)的核心模式 |
Galacean Engine 使用 ResourceManager 来管理资源的加载。支持 GLTF/GLB 模型、纹理 (Texture2D)、材质等多种资源的异步加载。
需引入引擎和资源加载相关的类型:
import { WebGLEngine, GLTFResource, Texture2D, AssetType } from "@galacean/engine";
适用场景:在游戏初始化阶段加载必要的 3D 模型或图片。
核心机制:
async/await 或 .then()。代码模式:
// 假设在 init 函数中
async function loadResources(engine: WebGLEngine, rootEntity: Entity) {
// 1. 加载 GLTF 模型
// load 方法会根据后缀自动推断类型,也可以通过 type 指定
const gltfResource = await engine.resourceManager.load<GLTFResource>("https://example.com/duck.glb");
// 实例化模型到场景中
const defaultSceneRoot = gltfResource.defaultSceneRoot;
rootEntity.addChild(defaultSceneRoot);
// 2. 加载纹理图片
const texture = await engine.resourceManager.load<Texture2D>("https://example.com/texture.png");
console.log("Resources loaded successfully");
}
适用场景:同时加载多个资源以提高初始化效率。
代码模式:
const [duckGLTF, terrainGLTF, bgTexture] = await Promise.all([
engine.resourceManager.load<GLTFResource>("https://path/to/duck.glb"),
engine.resourceManager.load<GLTFResource>("https://path/to/terrain.glb"),
engine.resourceManager.load<Texture2D>("https://path/to/bg.png")
]);
// 添加到场景
rootEntity.addChild(duckGLTF.defaultSceneRoot);
rootEntity.addChild(terrainGLTF.defaultSceneRoot);
适用场景:需要指定资源类型(当 URL 无后缀时)或设置重试次数等参数。
代码模式:
engine.resourceManager.load({
url: "https://api.example.com/get-model-data",
type: AssetType.GLTF, // 显式指定类型
retryCount: 3 // 失败重试次数
}).then((resource) => {
const gltf = resource as GLTFResource;
rootEntity.addChild(gltf.defaultSceneRoot);
});
适用场景:加载模型后需要播放动画或修改材质。
代码模式:
engine.resourceManager.load<GLTFResource>("model.gltf").then((gltf) => {
// 1. 添加到场景
rootEntity.addChild(gltf.defaultSceneRoot);
// 2. 获取动画 (如果有)
const animations = gltf.animations;
if (animations && animations.length > 0) {
const animator = gltf.defaultSceneRoot.getComponent(Animator);
animator.play(animations[0].name);
}
// 3. 获取材质/纹理等其他资源
// gltf.materials, gltf.textures, etc.
});