import PropTypes from 'prop-types'; import * as THREE from 'three'; export function getDisplayName(Wrapped, defaults = '$Component'): String; /** * 构建自定义校验 * @param {Array} keys * @example * static propTypes = { * ... * customProp: generateCustomProp(['geometry', 'material']) * } */ export function generateCustomProp(keys = []): Function; export const basePropTypes = { // https://react.docschina.org/docs/typechecking-with-proptypes.html#proptypes children: PropTypes.oneOfType([ // 数字、字符串、DOM 元素或包含这些类型的数组或fragment PropTypes.node, // React元素(原生HTML元素或React类) PropTypes.element ]), // 是否显示 Object3D visible: PropTypes.bool, // Object3D 元素名称 uniqueName: PropTypes.string }; /** Object3D 对象 */ export const object3DPropTypes = PropTypes.instanceOf(THREE.Object3D); /** string color or hex16 number color */ export const colorPropTypes = PropTypes.oneOfType([ PropTypes.string, PropTypes.number, PropTypes.instanceOf(THREE.Color) ]); /** 材质,当为 string 时,表示材质的路径 */ export const texturePropTypes = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(THREE.Texture)]); export const sidePropTypes = PropTypes.oneOf([THREE.FrontSide, THREE.BackSide, THREE.DoubleSide]); export const uuidPropTypes = PropTypes.oneOfType([PropTypes.string, PropTypes.number]); export const materialPropTypes = PropTypes.shape({ // Sets the alpha value to be used when running an alpha test. The material will not be renderered if the opacity is lower than this value. Default is 0 alphaTest: PropTypes.number, // Blending destination. Default is OneMinusSrcAlphaFactor. See the destination factors constants for all possible values. // The material's blending must be set to CustomBlending for this to have any effect. blendDst: PropTypes.number, blendDstAlpha: PropTypes.number, blendEquation: PropTypes.number, blendEquationAlpha: PropTypes.number, blending: PropTypes.number, blendSrc: PropTypes.number, blendSrcAlpha: PropTypes.number, clipIntersection: PropTypes.bool, clippingPlanes: PropTypes.array, clipShadows: PropTypes.bool, colorWrite: PropTypes.bool, depthFunc: PropTypes.bool, depthTest: PropTypes.bool, depthWrite: PropTypes.bool, flatShading: PropTypes.bool, fog: PropTypes.bool, lights: PropTypes.bool, name: PropTypes.string, needsUpdate: PropTypes.bool, opacity: PropTypes.number, polygonOffset: PropTypes.bool, polygonOffsetFactor: PropTypes.number, polygonOffsetUnits: PropTypes.number, precision: PropTypes.string, premultipliedAlpha: PropTypes.bool, dithering: PropTypes.bool, shadowSide: PropTypes.oneOfType([ sidePropTypes, PropTypes.oneOf([null]) ]), transparent: PropTypes.bool, vertexColors: PropTypes.number, vertexTangents: PropTypes.bool, visible: PropTypes.bool }); /** * scene 必要配置信息,或者 THREE.Scene 实例 */ export const scenePropTypes = PropTypes.oneOfType([ PropTypes.instanceOf(THREE.Scene), PropTypes.shape({ isFogExp2: PropTypes.bool, fog: PropTypes.oneOfType([ PropTypes.instanceOf(THREE.Fog), PropTypes.instanceOf(THREE.FogExp2), PropTypes.shape({ color: colorPropTypes, near: PropTypes.number, far: PropTypes.number }), PropTypes.shape({ color: colorPropTypes, density: PropTypes.number }) ]), overrideMaterial: PropTypes.object, autoUpdate: PropTypes.bool, background: PropTypes.object }) ]); /** * camera 必要配置信息,或者 THREE.Camera 实例 */ export const cameraPropTypes = PropTypes.oneOfType([ PropTypes.instanceOf(THREE.Camera), // PerspectiveCamera PropTypes.shape({ // Camera frustum vertical field of view. fov: PropTypes.number, // Camera frustum aspect ratio. aspect: PropTypes.number, // Camera frustum near plane. near: PropTypes.number, // Camera frustum far plane. far: PropTypes.number }), // OrthographicCamera PropTypes.shape({ left: PropTypes.number, // Camera frustum left plane. right: PropTypes.number, // Camera frustum right plane. top: PropTypes.number, // Camera frustum top plane. bottom: PropTypes.number, // Camera frustum bottom plane. near: PropTypes.number, // Camera frustum near plane. far: PropTypes.number // Camera frustum far plane. }) ]); export const lightPropTypes = PropTypes.instanceOf(THREE.Light); /** * scene children 注入的属性 */ export const sceneChildPropTypes = { ...basePropTypes, __scene__: PropTypes.object, __camera__: PropTypes.object, // 子组件可以将自身的三维元素,添加到cache putInCache: PropTypes.func, // 添加至场景 attach: PropTypes.func, detach: PropTypes.func, // 添加至相机 attachToCamera: PropTypes.func, detachFromCamera: PropTypes.func, // objectManager objectManager: PropTypes.object, insertPreSync: PropTypes.func, insertSync: PropTypes.func }; export const cameraChildPropTypes = { ...basePropTypes, __camera__: PropTypes.object, // 添加至相机 attach: PropTypes.func, detach: PropTypes.func }; /** * leke Vector2 * [1, 1] or { x: 1, y: 1 } or new Vector2(1, 1) */ export const likeVector2Types = PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.number), PropTypes.shape({ x: PropTypes.number, y: PropTypes.number }), PropTypes.instanceOf(THREE.Vector2) ]); /** * leke Vector3 * [1, 1, 1] or { x: 1, y: 1, z: 1 } or new Vector3(1, 1, 1) */ export const likeVector3Types = PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.number), PropTypes.shape({ x: PropTypes.number, y: PropTypes.number, z: PropTypes.number }), PropTypes.instanceOf(THREE.Vector3) ]); /** * position * 1 => { x: 1, y: 1, z: 1 } or [x, y, z] */ export const positionTypes = PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.number), PropTypes.shape({ x: PropTypes.number, y: PropTypes.number, z: PropTypes.number }) ]); /** * scale * 1 => { x: 1, y: 1, z: 1 } or [x, y, z] */ export const scaleTypes = PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.number), PropTypes.shape({ x: PropTypes.number, y: PropTypes.number, z: PropTypes.number }) ]); export const rotationTypes = PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.number), PropTypes.shape({ x: PropTypes.number, y: PropTypes.number, z: PropTypes.number, order: PropTypes.oneOf(['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX']) }) ]); export const objLoaderItemTypes = PropTypes.shape({ // 根目录,要求 mtl 与 obj 文件在同样的根目录下 basePath: PropTypes.string, objName: PropTypes.string, mtlName: PropTypes.string, position: positionTypes, scale: scaleTypes, rotation: rotationTypes, userData: PropTypes.object, // --- 其它用户信息 // 排序权重,常用于设置楼层, 默认 0 sortOrder: PropTypes.number, // 模型分类 modelClassify: PropTypes.string, // 模型所属层级 modelLevel: PropTypes.string, // 外键 用于关联子节点,或者内部节点 foreignKey: uuidPropTypes, // 主键,主要用于父节点寻找子节点时使用,该值必须和其它 Object3D 元素的 foreignKey 相等,才有效。 // 只针对Object3D 设置 或者 Group 设置 primaryKey: uuidPropTypes }); // lineStyle proptype export const lineStyleTypes = PropTypes.oneOfType([ // basic line PropTypes.shape({ color: colorPropTypes, linewidth: PropTypes.number, linecap: PropTypes.oneOf(['butt', 'round', 'square']), // default round linejoin: PropTypes.oneOf(['round', 'bevel', 'miter']), // default round lights: PropTypes.bool // Whether the material is affected by lights. Default is false. }), // dash line PropTypes.shape({ color: colorPropTypes, linewidth: PropTypes.number, scale: PropTypes.number, dashSize: PropTypes.number, gapSize: PropTypes.number, lights: PropTypes.bool // Whether the material is affected by lights. Default is false. }) ]); export const meshLineStyleTypes = PropTypes.shape({ linewidth: PropTypes.number, map: PropTypes.any, useMap: PropTypes.bool, alphaMap: PropTypes.any, useAlphaMap: PropTypes.bool, color: colorPropTypes, opacity: PropTypes.number, // 0~1 resolution: PropTypes.object, // Specify whether line's size is attenuated by the camera depth. (Perspective camera only.) Default is true. sizeAttenuation: PropTypes.bool, near: PropTypes.number, far: PropTypes.number, dashSize: PropTypes.number, // 0~3 dashOffset: PropTypes.number, dashRatio: PropTypes.number, // 0~1 useDash: PropTypes.bool, // 可见度 0~1, 当设置小于1的值时,需要设置 WebGLRenderer({ alpha: true }), alpha 为 true。否则无法显示非可见区 visibility: PropTypes.number, // Sets the alpha value to be used when running an alpha test. // The material will not be renderered if the opacity is lower than this value. Default is 0 alphaTest: PropTypes.number, repeat: PropTypes.object }); /** * [{ x: 1, y: 0, z: 0 }, { x: 1, y: 2, z: 3 } ...] * or * [[1,2,3], [1,0,3] ...] */ export const linePathTypes = PropTypes.arrayOf( PropTypes.oneOfType([ // [{ x: 1, y: 0, z: 0 }, { x: 1, y: 2, z: 3 } ...] PropTypes.shape({ x: PropTypes.number, y: PropTypes.number, z: PropTypes.number }), // [[1,2,3], [1,0,3] ...] PropTypes.array ]), ); /** * mesh draw mode */ export const meshDrawModeTypes = PropTypes.oneOf([ THREE.TrianglesDrawMode, // 0 THREE.TriangleStripDrawMode, // 1 THREE.TriangleFanDrawMode // 2 ]); /** * mesh Material types */ export const meshStyleTypes = PropTypes.shape({ alphaTest: PropTypes.number, blendDst: PropTypes.number, blendDstAlpha: PropTypes.number, blendEquation: PropTypes.number, blendEquationAlpha: PropTypes.number, blending: PropTypes.object, blendSrc: PropTypes.number, blendSrcAlpha: PropTypes.number, clipIntersection: PropTypes.bool, clippingPlanes: PropTypes.array, clipShadows: PropTypes.bool, colorWrite: PropTypes.bool, opacity: PropTypes.number, polygonOffset: PropTypes.bool, transparent: PropTypes.bool, color: colorPropTypes, map: PropTypes.instanceOf(THREE.Texture), dithering: PropTypes.bool, shadowSide: sidePropTypes, side: sidePropTypes }); /** path pen 参数 */ export const pathPenTypes = PropTypes.shape({ // 拐角半径,设置为0则禁止圆角 cornerRadius: PropTypes.number, // 拐角分割的曲线段数 cornerSplit: PropTypes.number, // 强制朝上的点,默认自动,按照切线计算 up: likeVector3Types, // 线路宽 width: PropTypes.number, // 是否显示箭头 arrow: PropTypes.bool, // line 展示进度,取值为 0~1 progress: PropTypes.number }); /** RouteLine proptypes 参数 */ export const routeLineTypes = { // 绘制模式 drawMode: meshDrawModeTypes, // 拐角半径,设置为0则禁止圆角 cornerRadius: PropTypes.number, // 拐角分割的曲线段数 cornerSplit: PropTypes.number, // 强制朝上的点,默认自动,按照切线计算 up: likeVector3Types, // 线路宽度 width: PropTypes.number, // 是否显示箭头,非 tube 下起效 showArrow: PropTypes.bool, // line 展示进度,取值为 0~1 progress: PropTypes.number, // 材质路径 image: PropTypes.string, // 是否启用 uv 动画 scrollUV: PropTypes.bool, // UV 动画播放速度, 数值设置成负数可以改变动画方向 scrollSpeed: PropTypes.number, points: linePathTypes }; /** * Orbit 控制器属性校验 */ export const orbitOptionsPropTypes = PropTypes.shape({ // 相机距离焦点的最远距离,默认值是 Infinity(无限远), 此属性适用于透视相机 PerspectiveCamera。 maxDistance: PropTypes.number, // 相机距离焦点的最近距离,默认值是0。 此属性适用于透视相机 PerspectiveCamera minDistance: PropTypes.number, // 0.0001 // 相机距离焦点的最近距离,默认值是0,此属性适用于正交相机 OrthographicCamera。 minZoom: PropTypes.number, // 0.15 // 相机距离焦点的最远距离,默认值是 Infinity(无限远),此属性适用于正交相机 OrthographicCamera。 maxZoom: PropTypes.number, // 8 // 当前相机是否自动旋转,默认值是 False,不自动旋转。 autoRotate: PropTypes.bool, // false // 是否开启拖拽惯性移动,即拖拽停止相机会有缓慢停止的距离移动,默认值是 False。 enableDamping: PropTypes.bool, // true // 相机位置和焦点与焦点和最上方组成的最小夹角限制,默认值是0。 minPolarAngle: PropTypes.number, // 0 // Math.PI 相机位置和焦点与焦点和最上方组成的最大夹角限制,默认值是 Math.PI,也就是180度角。 maxPolarAngle: PropTypes.number, // // 键盘上下左右键移动相机的速度,默认值是 7.0。 keyPanSpeed: PropTypes.number, // 0.1 // 平移的速度,默认值是 1.0。 panSpeed: PropTypes.number, // 0.1 // 旋转速度,默认值是 1.0。 rotateSpeed: PropTypes.number, // 0.07 // 拖拽惯性移动的阻力,默认值是 0.25。 dampingFactor: PropTypes.number, // 0.12 // 修改相机平移的方向,默认值是 False,即沿 x 轴正负方向和 y 轴正负方向移动。可选值是 True,可以修改为沿 x 轴正负方向和 y 轴正负方向移动。 screenSpacePanning: PropTypes.bool, // true // 是否开启当前控制器,默认值是 true,如果设置为 false,将无法通过操作修改相机。 enabled: PropTypes.bool // true }); /** * cameraOptions 支持的 propTypes */ export const cameraOptionsPropTypes = PropTypes.oneOfType([ PropTypes.instanceOf(THREE.Camera), PropTypes.shape({ type: PropTypes.oneOf(['Perspective', 'Orthographic']), // Object3D common castShadow: PropTypes.bool, receiveShadow: PropTypes.bool, visible: PropTypes.bool, renderOrder: PropTypes.number, // Camera common zoom: PropTypes.number, near: PropTypes.number, far: PropTypes.number, // Perspective Camera fov: PropTypes.number, aspect: PropTypes.number, // 默认 window.innerWidth/window.innerHeight // Orthographic Camera bottom: PropTypes.number, top: PropTypes.number, left: PropTypes.number, right: PropTypes.number, // 内置摄像机控制器 builtInOrbit: orbitOptionsPropTypes, // 是否开启拾取模式 enablePicker: PropTypes.bool, position: likeVector3Types, // 摄像机位置 target: likeVector3Types // 观察的目标点位置 或 观察的物体 }) ]); /** * sceneOptions 支持的 propTypes */ export const sceneOptionsPropTypes = PropTypes.oneOfType([ PropTypes.instanceOf(THREE.Scene), PropTypes.shape({ type: PropTypes.oneOf(['SceneBase', 'Scene2D', 'SceneNormal']), background: colorPropTypes, skyBox: PropTypes.oneOfType([ // 内置天空盒子名称、单图片路径 PropTypes.string, // 天空盒子图片路径数组 PropTypes.arrayOf(PropTypes.string), // CubeTexture or other Texture PropTypes.instanceOf(THREE.Texture) ]), // 是否启用动态天空 enableSky: PropTypes.bool, dynamicSkyConfig: PropTypes.shape({ // 时间 0~23.98 (23:59) time: PropTypes.number, // 9 // 倾角 与 x-z 平面的夹角 inclination: PropTypes.number, // 45 // 浑浊度 turbidity: PropTypes.number, // 10 // 散射 rayleigh: PropTypes.number, // 2 // 亮度 luminance: PropTypes.number, // 1 // MIE 系数 mieCoefficient: PropTypes.number, // 0.005 // MIE 方向 mieDirectionalG: PropTypes.number, // 0.95 // 太阳位置 sunPosition: likeVector3Types, // 扩展数 模拟太阳与地面的距离 scalar: PropTypes.number // 450000 }) }) ]); /** * rendererOptions 支持的 propTypes * * 支持 contextParams 和 r */ export const rendererOptionsPropTypes = PropTypes.shape({ // 是否使用 webgl1 默认为 false,表示使用 webgl2 useWebGL1: PropTypes.bool, // GPU 出错时回调方法 onError: PropTypes.func, antialias: PropTypes.bool, alpha: PropTypes.bool });