0.0.28 • Published 11 months ago

three-scene v0.0.28

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

three-scene

基于 three 封装的场景功能

基本类

<template>
  <div class="container" ref="containerRef"></div>
</template>
<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { ThreeScene } from 'three-scene'

const containerRef = ref()

const options: ConstructorParameters<typeof ThreeScene>[0] = {
  camera: {
    position: [0, 3, 5]
  },
  grid: {
    visible: true
  },
  axes: {
    visible: true
  }
}

let scene: InstanceType<typeof ThreeScene>

onMounted(() => {
  options.container = containerRef.value
  scene = new ThreeScene(options)
  scene.run()
})
</script>
<style lang="scss" module>
.container {
  height: 100%;
  position: relative;
}
</style>

API

Attributes

属性名类型说明
optionsObject配置
containerHTMLElement容器
sceneInstanceType <typeof THREE.Scene>场景对象
rendererInstanceType <typeof THREE.WebGLRenderer>渲染器对象
baseCameraInstanceType <typeof THREE.PerspectiveCamera>基础相机对象
cruiseCameraInstanceType <typeof THREE.PerspectiveCamera>巡航相机对象
cruiseGroupInstanceType <typeof THREE.group>巡航组
controlsInstanceType <typeof OrbitControls>控制器对象
gridInstanceType <typeof THREE.GridHelper>网格对象
animationIdnumberrequestAnimationFrame 方法执行 id
forkNameSymbol网格交叉分组名称

Options

属性名类型可选值默认值说明
containerHTMLElement/String--容器
baseUrlString-''加载资源基本地址
bgColorNumber/String--背景色,0x000000,'#000000'
bgUrlString/String[]--背景图数组(6 张图)时可组成环境图
envString--场景环境,影响场景所有元素,仅支持 hdr 文件
scaleNumber-1缩放倍数,具体表现在计算坐标位置
fogObject--雾化
renderObject--渲染器
controlsObject--控制器
ambientLightObject--环境光
directionalLightObject--平行光
cameraObject--相机
gridObject--网格
axesObject--坐标
cruiseObject--巡航

Fog

属性名类型可选值默认值说明
visibleBoolean-false可见
nearNumber-100雾化最近距离
farNumber-1000雾化最远距离

Render

属性名类型可选值默认值说明
antialiasBoolean-true是否开启反锯齿
alphaBoolean-false画布透明度缓冲区
logarithmicDepthBufferBoolean-true设置对数深度缓存
preserveDrawingBufferBoolean-false是否保留缓冲区直到手动清除或覆盖,需要截图设置为 true,性能会下降

Controls

属性名类型可选值默认值说明
visibleBoolean-false可见
enableDampingBoolean-false阻尼(惯性)
dampingFactorNumber-0.25阻尼系数,鼠标灵敏度
autoRotateBoolean-false自动旋转
maxPolarAngleNumber--相机垂直旋转角度上限
enableZoomBoolean-true缩放
enablePanBoolean-true右键拖拽
screenSpacePanningBoolean-true相机垂直平移
minDistanceNumber-1相机距离原点最近距离
maxDistanceNumber-2000相机距离原点最远距离

AmbientLight

属性名类型可选值默认值说明
visibleBoolean-false可见
colorNumber/String-0xffffff环境光颜色
intensityNumber-1.5光强度

DirectionalLight

属性名类型可选值默认值说明
visibleBoolean-false可见
helperBoolean-false辅助器
light2boolean-true第二个平行光开启
colorNumber/String-0xffffff平行光颜色
intensityNumber-1.5光强度

Camera

属性名类型可选值默认值说明
helperBoolean-false辅助器
nearNumber-1相机最近距离
farNumber-10000相机最远距离
positionArray--350, 510, 700相机位置坐标

Grid

属性名类型可选值默认值说明
visibleBoolean-false可见
transparentBoolean-true透明
opacityNumber-0.3透明度
widthNumber-800网格宽度
divisionsNumber-80网格等分数
centerLineColorNumber/String-0xa1a1a1中心线颜色
gridColorNumber/String-0xa1a1a1网格颜色
forkBoolean-false网格交叉点
forkSizeNumber-1.4网格交叉点大小
forkColorNumber/String-0xa1a1a1网格交叉点颜色

Axes

属性名类型可选值默认值说明
visibleBoolean-false可见
sizeNumber-50坐标轴大小

Cruise

属性名类型可选值默认值说明
visibleBoolean-false可见
helperBoolean-false辅助器
pointsArray-[]巡航点位
segmentNumber-2巡航分段数
tensionNumber-0巡航曲线张力
mapUrlString--贴图地址
repeatArray-0.1, 1贴图重复
widthNumber-15宽度
speedNumber-1巡航时速度
mapSpeedNumber-0.006贴图材质动画滚动速度
offsetNumber-10巡航点偏差(距离巡航点的上下偏差)

Methods

方法名参数返回说明
init--初始化(灯光、网格、坐标轴、模型)
run--运行(循环渲染、控制器可视操作)
loop--循环(执行 requestAnimationFrame 方法)
animate--更新渲染器、TWEEN 更新、巡航更新
initModel--业务模型初始化(继承后可在此方法内编写业务代码)
modelAnimate--业务代码模型动画(配套使用)
initRenderer-渲染器对象初始化渲染器
initLight--初始化灯光(环境光、平行光)
createDirectionalLightcastShadow, s, size, near, far平行光对象创建平行光
initCamera-景深相机对象初始化相机
initControls-控制器对象初始化控制器
initCruise--初始化巡航
initGrid--初始化网格
initAxes--初始化坐标轴辅助器
setCruisePointpoints-设置巡航点位并生成巡航航道
createCruise--创建巡航航道
toggleCruise--巡航开启或者关闭
setScalescale-设置缩放大小,主要用于鼠标位置计算
setEnvironmentenv-设置场景环境
setBgTexturebgUrl-设置背景图
setBgColorcolor-设置背景色
exportImage--导出场景图片
addObject...objects-场景添加对象
controlReset--控制器重置
resize--重置画布大小
stopAnimate--停止动画(requestAnimationFrame)
disposeObjobj-清除场景对象
dispose--场景销毁

组件

组件文档
floor-scene楼层组件
map-scene地图组件

XYZ

属性名类型
xNumber
yNumber
zNumber
0.0.28

11 months ago

0.0.27

11 months ago

0.0.26

11 months ago

0.0.25

11 months ago

0.0.24

11 months ago

0.0.23

11 months ago

0.0.22

11 months ago

0.0.21

11 months ago

0.0.20

11 months ago

0.0.19

11 months ago

0.0.18

11 months ago

0.0.17

11 months ago

0.0.16

11 months ago

0.0.15

11 months ago

0.0.14

11 months ago

0.0.13

11 months ago

0.0.12

11 months ago

0.0.11

11 months ago

0.0.10

11 months ago

0.0.9

11 months ago

0.0.8

11 months ago

0.0.7

12 months ago

0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago

1.0.1

2 years ago

1.0.0

4 years ago