网格

Primitive Mesh

PrimitiveMesh提供了创建立方体、球体等网格对象的便捷方法。

编辑器使用

编辑器已经内置了立方体圆柱体 等基础几何体,可以直接在左侧节点树点击 + 置入模型:

image-20231009111916680

当然,我们也可以在组件面板点击 1 添加 Mesh Renderer组件,点击 2 绑定想要的基础几何体:

image-20231009112014068

内置几何体无法满足需求?您可以在 资产面板右键CreatePrimitiveMesh 创建一个 Mesh 资产,并通过调整 Mesh 的各项参数来满足需求。

image-20231009111916680

脚本使用

目前提供的几何体如下:

const entity = rootEntity.createChild("cuboid");
entity.transform.setPosition(0, 1, 0);
const renderer = entity.addComponent(MeshRenderer);
renderer.mesh = PrimitiveMesh.createCuboid(engine);
// Create material
const material = new BlinnPhongMaterial(engine);
material.emissiveColor.set(1, 1, 1, 1);
renderer.setMaterial(material);
const entity = rootEntity.createChild("sphere");
entity.transform.setPosition(0, 1, 0);
const renderer = entity.addComponent(MeshRenderer);
renderer.mesh = PrimitiveMesh.createSphere(engine);
// Create material
const material = new BlinnPhongMaterial(engine);
material.emissiveColor.set(1, 1, 1, 1);
renderer.setMaterial(material);
const entity = rootEntity.createChild("plane");
entity.transform.setPosition(0, 1, 0);
const renderer = entity.addComponent(MeshRenderer);
renderer.mesh = PrimitiveMesh.createPlane(engine);
// Create material
const material = new BlinnPhongMaterial(engine);
material.emissiveColor.set(1, 1, 1, 1);
renderer.setMaterial(material);
const entity = rootEntity.createChild("cylinder");
entity.transform.setPosition(0, 1, 0);
const renderer = entity.addComponent(MeshRenderer);
renderer.mesh = PrimitiveMesh.createCylinder(engine);
// Create material
const material = new BlinnPhongMaterial(engine);
material.emissiveColor.set(1, 1, 1, 1);
renderer.setMaterial(material);
const entity = rootEntity.createChild("torus");
entity.transform.setPosition(0, 1, 0);
const renderer = entity.addComponent(MeshRenderer);
renderer.mesh = PrimitiveMesh.createTorus(engine);
// Create material
const material = new BlinnPhongMaterial(engine);
material.emissiveColor.set(1, 1, 1, 1);
renderer.setMaterial(material);
const entity = rootEntity.createChild("cone");
entity.transform.setPosition(0, 1, 0);
const renderer = entity.addComponent(MeshRenderer);
renderer.mesh = PrimitiveMesh.createCone(engine);
// Create material
const material = new BlinnPhongMaterial(engine);
material.emissiveColor.set(1, 1, 1, 1);
renderer.setMaterial(material);
const entity = rootEntity.createChild("capsule");
entity.transform.setPosition(0, 1, 0);
const renderer = entity.addComponent(MeshRenderer);
renderer.mesh = PrimitiveMesh.createCapsule(engine);
// Create material
const material = new BlinnPhongMaterial(engine);
material.emissiveColor.set(1, 1, 1, 1);
renderer.setMaterial(material);
最后更新于 七月 11, 2024

这篇文档对您有帮助吗?