!2351 优化:在ShareView中降低显示精度,并且Revolve和Sweep实体使用BufferGeometry,降低内存占用

pull/2352/head
ChenX 1 year ago
parent 05b684c121
commit 0d923213d8

@ -12,6 +12,7 @@ import { inflateBase64 } from "../../Common/inflate";
import { CADFiler } from "../../DatabaseServices/CADFiler";
import { commandMachine } from "../../Editor/CommandMachine";
import { userConfig } from "../../Editor/UserConfig";
import { ARC_DRAW_CONFIG } from "../../Geometry/ExtrudeMeshGeomBuilder/SplitCurveParams";
import { RenderType } from "../../GraphicsSystem/RenderType";
import { LoadDefaultExr, LoadMetalEnv } from "../../Loader/EnvLoader";
import "../../UI/Css/blue.less";
@ -190,6 +191,10 @@ window.onload = async function ()
if (false)
new ErrorMonitoring();
//对于ShareView,我们将显示精度降低
ARC_DRAW_CONFIG.Arc_MinSplitCount = 8;
ARC_DRAW_CONFIG.ARC_MaxSplitCount = 60;
LogEnable.Display = true;
// ReportErrorWrap.ReportError = ReportError;

@ -1,9 +1,9 @@
import { Box3, Face3, Geometry, Matrix4, Mesh, MeshNormalMaterial, Object3D, ShapeUtils, Vector2, Vector3 } from "three";
import { Box3, BufferGeometry, Face3, Geometry, Matrix4, Mesh, MeshNormalMaterial, Object3D, ShapeUtils, Vector2, Vector3 } from "three";
import { ColorMaterial } from "../../Common/ColorPalette";
import { Object3DRemoveAll } from "../../Common/Dispose";
import { FixIndex, clamp } from "../../Common/Utils";
import { ObjectSnapMode } from "../../Editor/ObjectSnapMode";
import { AsVector2, YAxis, ZeroVec, angle, equaln, equalv3, isParallelTo } from "../../Geometry/GeUtils";
import { AsVector3, YAxis, ZeroVec, angle, equaln, equalv3, isParallelTo } from "../../Geometry/GeUtils";
import { Matrix2 } from "../../Geometry/Matrix2";
import { Orbit } from "../../Geometry/Orbit";
import { RenderType } from "../../GraphicsSystem/RenderType";
@ -145,7 +145,10 @@ export class RevolveSolid extends Entity
}
}
private _MeshGeometry: Geometry;
//del_exp_start
private _MeshGeometry: BufferGeometry;
//del_exp_end
//del_exp_start//del_exp_end private _MeshGeometry: Geometry;
get BoundingBox()
{
@ -187,22 +190,15 @@ export class RevolveSolid extends Entity
if (this._CacheContourPoints === undefined)
{
this._CacheContourPoints3D = [];
let ocsInv = this._Contour.OCSInv;
for (let i = 0; i < this._Contour.EndParam; i++)
this._CacheContourPoints = [];
for (let p of this._Contour.Shape.getPoints(6))
{
let c = this._Contour.GetCurveAtIndex(i);
this._CacheContourPoints3D.push(c.StartPoint);
if (c instanceof Arc)
{
let minCount = Math.max(2, Math.ceil((c.AllAngle) / Math.PI) * 3);
let count = clamp(c.Length / 20, minCount, 30);
for (let j = 0; j < count; j++)
this._CacheContourPoints3D.push(c.GetPointAtParam((j + 1) / (count + 1)));
}
this._CacheContourPoints3D.push(c.EndPoint);
this._CacheContourPoints.push(p);
if (p["_mask_"])
this._CacheContourPoints.push(p);
}
this._CacheContourPoints = this._CacheContourPoints3D.map(p => AsVector2(p.clone().applyMatrix4(ocsInv)));
this._CacheContourPoints3D = this._CacheContourPoints.map(p => AsVector3(p).applyMatrix4(this._Contour.OCSNoClone));
this._CacheContourFaces = ShapeUtils.triangulateShape(this._CacheContourPoints, []) as [number, number, number][];
@ -284,8 +280,11 @@ export class RevolveSolid extends Entity
RevolveLine(geo, this._CacheContourPoints3DQ, this._CacheContourPoints3DQ2, this._StartAngle, allAngle, us);
geo.computeFaceNormals();
geo.computeVertexNormals();
this._MeshGeometry = geo;
return geo;
//del_exp_start 因为UE不需要BufferGeometry 直接提供Geom就好了
this._MeshGeometry = new BufferGeometry().fromGeometry(geo);
//del_exp_end
return this._MeshGeometry;
}
//#region Draw

@ -163,7 +163,7 @@ export class SweepSolid extends Entity
Log("错误:提供的轮廓没有和路径垂直!", LogType.Error);
}
private _MeshGeometry: SweepGeometry;
private _MeshGeometry: SweepGeometry | BufferGeometry;
private _LineGeom: LineGeometry;
get MeshGeometry()
{
@ -182,6 +182,11 @@ export class SweepSolid extends Entity
this._EdgeGeometry = this._MeshGeometry.EdgeGeom;
this._LineGeom = this._MeshGeometry.LineGeom;
this._MeshGeometry.edgePts = undefined;
//del_exp_start 渲染器不需要BufferGeom
this._MeshGeometry = new BufferGeometry().fromGeometry(this._MeshGeometry);
//del_exp_end
return this._MeshGeometry;
}
catch (error)

@ -8,29 +8,33 @@ import { BUL_IS_LINE_FUZZ } from "../../DatabaseServices/Entity/Polyline";
import { AsVector3, equaln } from "../GeUtils";
//del_exp_start
export const ARC_SplitLength = 4;//圆的分段长度
export const ARC_RADIUS_MIN = 25;//大于半径25的自动优化成36等分圆 保证绘制光滑
export const Arc_MinSplitCount = 36;//圆的最小分段个数
export const ARC_MaxSplitCount = 180;//圆的最大分段个数
export const ARC_DRAW_CONFIG = {
ARC_SplitLength: 4,//圆的分段长度
ARC_RADIUS_MIN: 25,//大于半径25的自动优化成36等分圆 保证绘制光滑
Arc_MinSplitCount: 36,//圆的最小分段个数
ARC_MaxSplitCount: 180,//圆的最大分段个数
};
//del_exp_end
//del_exp_start
/*
//del_exp_end
export const ARC_SplitLength = 0.4;//圆的分段长度(虚幻引擎的尺寸单位是厘米)
export const ARC_RADIUS_MIN = 2.5;//大于半径25的自动优化成36等分圆 保证绘制光滑
export const Arc_MinSplitCount = 8;//圆的最小分段个数
export const ARC_MaxSplitCount = 90;//圆的最大分段个数
export const ARC_DRAW_CONFIG = {
ARC_SplitLength: 0.4,//圆的分段长度
ARC_RADIUS_MIN: 2.5,//大于半径25的自动优化成36等分圆 保证绘制光滑
Arc_MinSplitCount: 8,//圆的最小分段个数
ARC_MaxSplitCount: 90,//圆的最大分段个数
};
//del_exp_start
*/
//del_exp_end
export function GetArcDrawCount(arc: Arc | Circle): number
{
let splitCount = arc.Radius / ARC_SplitLength;
let splitCount = arc.Radius / ARC_DRAW_CONFIG.ARC_SplitLength;
//保证是偶数(避免奇数和Shape2计算方式一致导致的干涉)
splitCount = clamp(Math.floor(splitCount * 0.5) * 2, Arc_MinSplitCount, ARC_MaxSplitCount);
if (arc.Radius > ARC_RADIUS_MIN)
splitCount = clamp(Math.floor(splitCount * 0.5) * 2, ARC_DRAW_CONFIG.Arc_MinSplitCount, ARC_DRAW_CONFIG.ARC_MaxSplitCount);
if (arc.Radius > ARC_DRAW_CONFIG.ARC_RADIUS_MIN)
splitCount = Math.max(36, splitCount);
return splitCount;
}

Loading…
Cancel
Save