案例展示
创建基础线条材质和虚线材质
<template>
<div id="TO"></div>
</template>
<script setup>
import { Camera } from '@element-plus/icons-vue';
import { onMounted } from 'vue';
let TO = null;
onMounted(() => {
//初始化场景
TO = new ThingOrigin("line", document.getElementById("TO"), {
helper: {//辅助线
axes: {
active: false,
}
},
scene: {
ground:{ //设置地面
active: false,
},
background: {
type: 'color',//设置背景颜色
color: {
alpha: 1, // 透明度 取值范围0~1
color: "#000000",// 背景颜色
},
},
},
camera: {
"position": {
"x": 0,
"y": 100,
"z": 50
}
},
});
// 创建实线
createSolidLine();
//创建虚线
createDashedLine();
});
// 创建实线
function createSolidLine() {
//创建基础线条材质
var material_1 = TO.material.initLineMaterial({ color: "#00ff00" });
//创建线条
let lineGeometry = TO.line.initLine({
base: {
p1: { //起始位置
x: -50,
y: 30,
z: 0,
},
p2: {//结束位置
x: 50,
y: 30,
z: 0,
},
}
});
lineGeometry.material = material_1;
//添加到场景中
TO.scene.add(lineGeometry);
}
// 创建虚线
function createDashedLine() {
//创建虚线材质
var material_2 = TO.material.initLineDashedMaterial({ color: "#ffff00", dashSize: 3, gapSize: 1 });
//创建线条
let lineGeometry = TO.line.initLine({
base: {
p1: { //起始位置
x: -50,
y: 0,
z: 0,
},
p2: {//结束位置
x: 50,
y: 0,
z: 0,
},
}
});
lineGeometry.material = material_2;
lineGeometry.computeLineDistances(); // 必须调用此方法使虚线生效
//添加到场景中
TO.scene.add(lineGeometry);
}
</script>
<style scoped>
#TO {
width: 100%;
height: 400px;
position: relative;
}
</style>API 介绍
material.initLineBasicMaterial
| 方法签名 | 返回值 | 描述 |
|---|---|---|
initLineBasicMaterial(params: Partial<LineBasicMaterialParameters> = {} ) | LineBasicMaterial | 创建基础线条材质 |
LineBasicMaterialParameters 参数说明:
| 参数名 | 说明 | 类型 | 必填 | 默认值 |
|---|---|---|---|---|
color | 线条材质颜色 | string | number | Color | - | 0xffffff |
linewidth | 线条宽度(由于渲染器限制,无论如何设置该值,线宽始终为1) | number | - | 1 |
linecap | 线条两端样式('butt' | 'round' | 'square') | string | - | 'round' |
linejoin | 线连接节点样式('round' | 'bevel' | 'miter') | string | - | 'round' |
transparent | 线条是否透明度 | boolean | - | false |
opacity | 线条透明度(0.0-1.0) | number | - | 1 |
material.initLineDashedMaterial
| 方法签名 | 返回值 | 描述 |
|---|---|---|
initLineDashedMaterial(params: Partial<LineDashedMaterialParameters> = {}) | LineDashedMaterial | 创建虚线材质 |
LineDashedMaterialParameters 参数说明:
| 参数名 | 说明 | 类型 | 必填 | 默认值 |
|---|---|---|---|---|
color | 线条材质颜色 | string | number | Color | - | 0xffffff |
linewidth | 线条宽度 | number | - | 1 |
scale | 线条中虚线部分的占比 | number | - | 1 |
dashSize | 虚线的大小 | number | - | 3 |
gapSize | 间隙大小 | number | - | 1 |
transparent | 线条是否透明度 | boolean | - | false |
opacity | 线条透明度(0.0-1.0) | number | - | 1 |