import { Utils } from '../common/Utils'
import { BaseModelObject3D } from './BaseModelObject3D';
function _getParam(width, height, param) {
if (Utils.isObject(width)) {
return width;
}
if (Utils.isObject(height)) {
return height;
}
return param;
}
function _buildParam(width, height, param) {
param = _getParam(width, height, param);
param['body'] = param['body'] || {};
param['body']['localScale'] = param['body']['localScale'] || [
Utils.parseFloat(width, Utils.parseFloat(param['width'], 1)),
Utils.parseFloat(height, Utils.parseFloat(param['height'], 1)),
1
];
param['body']['localAngles'] = param['body']['localAngles'] || [-90, 0, 0];
param['instanceGroupName'] = param['instanceGroupName'] || 'Plane';
return param;
}
/**
* Plane - 平面几何体
*
* 用于创建平面模型(片状,无厚度),支持自定义宽度和高度细分。
*
* @class Plane
* @memberof THING
* @extends THING.BaseModelObject3D
* @public
*
* @example
* const p = new THING.Plane(2, 2, {
* widthSegments: 16,
* heightSegments: 16,
* position: [3, 0.1, 3],
* });
*/
class Plane extends BaseModelObject3D {
static defaultTagArray = ['Geometry'];
/**
* 平面
* @param {number} [width=1.0] 宽度,单位为米
* @param {number} [height=1.0] 高度,单位为米
* @param {object} [param] 初始参数
* @param {number} [param.widthSegments=1] 宽度方向细分数
* @param {number} [param.heightSegments=1] 高度方向细分数
* @constructor
* @public
*/
constructor(width, height, param = {}) {
super(_buildParam(width, height, param));
}
// #region Overrides
// #endregion
// #region Accessor
/**
* 设置/获取 平面宽度(x方向 单位:米)
* @default 1.0
* @type {number}
* @public
*/
get width() {
return this.body.scale[0];
}
set width(value) {
this._processBodyWithoutPivot((body) => {
let scale = body.scale;
body.scale = [value, scale[1], scale[2]];
});
}
/**
* 设置/获取 平面高度(y方向 单位:米)
* @default 1.0
* @type {number}
* @public
*/
get height() {
return this.body.scale[1];
}
set height(value) {
this._processBodyWithoutPivot((body) => {
let scale = body.scale;
body.scale = [scale[0], value, scale[2]];
});
}
// #endregion
/**
* Check whether it's plane object.
* @type {boolean}
*/
get isPlane() {
return true;
}
}
export { Plane }