案例展示
标准网格材质
<template>
<div id="TO"></div>
</template>
<script setup>
import { onMounted } from 'vue';
onMounted(() => {
//初始化场景
let TO = new ThingOrigin("fileModel", document.getElementById("TO"), {
scene: {
ground:{
active: false,
},
background: {
type: 'color',//设置背景颜色
color: {
alpha: 1, // 透明度 取值范围0~1
color: "#000000",// 背景颜色
},
},
},
lights: [ //设置环境光
{
name: "light1",
type: "AmbientLight",
color: '#eeeeee',
intensity: 1,
visible: true,
position: {
x: 150,
y: 150,
z: 150,
},
},
],
helper: {//辅助工具
axes: {
active: false,
},
grid: {
active: false,
},
}
})
//设置颜色
const colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff, 0x00ffff, 0xf2f2f2, 0x888888,
0x336699, 0x993366, 0x669933, 0x999933, 0x339933, 0x993399, 0x339999, 0x0d77ff];
const matrixSize = 4;
const spacing = 22;
for (let i = 0; i < matrixSize; i++) {
for (let j = 0; j < matrixSize; j++) {
//创建球体
const sphereGeometry = TO.model.initSphere({
base:{
widthSegments: 32,
heightSegments: 32,
}
});
//创建材质
const material = TO.material.initStandardMaterial(
{
color: colors[i * matrixSize + j]
}
);
//设置材质
sphereGeometry.material = material;
//设置位置
sphereGeometry.position.x = (i - (matrixSize - 1) / 2) * spacing;
sphereGeometry.position.y = (j - (matrixSize - 1) / 2) * spacing;
TO.scene.add(sphereGeometry);
}
}
})
</script>
<style scoped>
#TO {
width: 100%;
height: 400px;
position: relative;
}
</style>API 介绍
material.initStandardMaterial
| 方法签名 | 返回值 | 描述 |
|---|---|---|
initStandardMaterial(params: Partial<MeshStandardMaterialParameters> = {}) | MeshStandardMaterial | 创建标准网格材质 |
MeshStandardMaterialParameters 参数说明:
| 参数名 | 说明 | 类型 | 必填 | 默认值 |
|---|---|---|---|---|
color | 材质的颜色 | string | number | Color | - | 0x000000 |
transparent | 是否开启透明度 | boolean | - | false |
opacity | 透明度(范围 0.0-1.0) | number | - | 1.0 |
side | 渲染面:FrontSide(正面)、BackSide(背面)、DoubleSide(双面) | string | - | FrontSide |
emissive | 放射(光)颜色 | string | number | Color | - | 0x000000 |
emissiveIntensity | 放射光强度 | number | - | 1 |
metalness | 金属度(范围 0.0-1.0) | number | - | 0.0 |
roughness | 粗糙度(范围 0.0-1.0) | number | - | 1.0 |