diff --git a/__test__/FileSystem/__snapshots__/wblockClone.test.ts.snap b/__test__/FileSystem/__snapshots__/wblockClone.test.ts.snap index 14c6204c1..e804a5677 100644 --- a/__test__/FileSystem/__snapshots__/wblockClone.test.ts.snap +++ b/__test__/FileSystem/__snapshots__/wblockClone.test.ts.snap @@ -49,7 +49,7 @@ Array [ 3, 1, "材质1", - 3, + 4, "#ffffff", false, 0.2, @@ -66,6 +66,7 @@ Array [ "", "", "", + false, 1, -1, 0, @@ -163,7 +164,7 @@ Array [ 3, 1, "材质1", - 3, + 4, "#ffffff", false, 0.2, @@ -180,6 +181,7 @@ Array [ "", "", "", + false, "PhysicalMaterialRecord", 2, 103, @@ -187,7 +189,7 @@ Array [ 3, 1, "材质1(1)", - 3, + 4, "#ffffff", false, 0.2, @@ -204,6 +206,7 @@ Array [ "", "", "", + false, 1, -1, 0, @@ -287,7 +290,7 @@ Array [ 3, 1, "材质1", - 3, + 4, "#ffffff", false, 0, @@ -304,6 +307,7 @@ Array [ "", "", "", + false, 1, -1, 0, diff --git a/src/DatabaseServices/Entity/Board.ts b/src/DatabaseServices/Entity/Board.ts index 4d6550250..546d587a6 100644 --- a/src/DatabaseServices/Entity/Board.ts +++ b/src/DatabaseServices/Entity/Board.ts @@ -1,4 +1,4 @@ -import { Matrix4, Vector3, LineSegments, Object3D, Mesh, BufferGeometry } from 'three'; +import { Matrix4, Vector3, LineSegments, Object3D, Mesh, Geometry } from 'three'; import { Board2Regions } from '../../Add-on/BoardEditor/Board2Regions'; import { deserializationBoardData, serializeBoardData } from '../../Add-on/BoardEditor/SerializeBoardData'; import { arrayRemoveIf } from '../../Common/ArrayExt'; @@ -664,6 +664,10 @@ export class Board extends ExtrudeSolid else return boardUVGenerator2; } + UpdateUV(geo: Geometry, ocs: Matrix4, isRev = false) + { + super.UpdateUV(geo, ocs, this.BoardProcessOption.lines === LinesType.Reverse); + } //从一个实体拷贝数据,实体类型必须相同. CopyFrom(obj: Board) diff --git a/src/DatabaseServices/Entity/Extrude.ts b/src/DatabaseServices/Entity/Extrude.ts index d570e6b6e..7b30ce28a 100644 --- a/src/DatabaseServices/Entity/Extrude.ts +++ b/src/DatabaseServices/Entity/Extrude.ts @@ -1,4 +1,4 @@ -import { BoxGeometry, BufferGeometry, ExtrudeGeometry, ExtrudeGeometryOptions, LineSegments, Matrix3, Matrix4, Mesh, Object3D, Path, Vector3, Line as TLine } from "three"; +import { BoxGeometry, BufferGeometry, ExtrudeGeometry, ExtrudeGeometryOptions, LineSegments, Matrix3, Matrix4, Mesh, Object3D, Path, Vector3, Line as TLine, Geometry } from "three"; import { Line2 } from "three/examples/jsm/lines/Line2"; import { arrayClone, arrayLast, arrayRemoveIf, arrayRemoveOnce, arraySortByNumber, arraySum } from "../../Common/ArrayExt"; import { ColorMaterial } from "../../Common/ColorPalette"; @@ -20,7 +20,7 @@ import { GenerateExtrudeEdgeGeometry } from "../../Geometry/ExtrudeEdgeGeometry" import { ExtrudeGeometryBuilder } from "../../Geometry/ExtrudeEdgeGeometry2"; import { AsVector2, AsVector3, equaln, equalv2, equalv3, IdentityMtx4, isIntersect, isParallelTo, isPerpendicularityTo, MoveMatrix, XAxis, YAxis, ZAxis, ZeroVec } from "../../Geometry/GeUtils"; import { OBB } from "../../Geometry/OBB/obb"; -import { ScaleUV } from "../../Geometry/UVUtils"; +import { ScaleUV, ScaleUV2 } from "../../Geometry/UVUtils"; import { RenderType } from "../../GraphicsSystem/RenderType"; import { BlockTableRecord } from "../BlockTableRecord"; import { CADFactory, Factory } from "../CADFactory"; @@ -38,6 +38,7 @@ import { Entity } from "./Entity"; import { Polyline } from "./Polyline"; import { Region } from "./Region"; import { Line } from "./Line"; +import { PhysicalMaterialRecord } from "../PhysicalMaterialRecord"; export type ExtureContourCurve = Polyline | Circle; export type ExtureContour = Polyline | Circle | ExtrudeSolid | Region; @@ -1613,7 +1614,7 @@ export class ExtrudeSolid extends Entity }; let geo = new ExtrudeGeometry(shape.Shape, extrudeSettings); geo.applyMatrix4(contour.OCSNoClone); - ScaleUV(geo); + this.UpdateUV(geo, contour.OCSNoClone); let bgeo = new BufferGeometry().fromGeometry(geo); this._MeshGeometry = bgeo; return bgeo; @@ -1674,7 +1675,19 @@ export class ExtrudeSolid extends Entity this.MeshGeometry; return this._EdgeGeometry; } + UpdateUV(geo: Geometry, ocs: Matrix4, isRev = false) + { + let mat: PhysicalMaterialRecord; + if (this.Material && this.Material.Object) + mat = this.Material.Object as PhysicalMaterialRecord; + else + mat = this.Db?.DefaultMaterial; + if (mat && mat.IsFull) + ScaleUV2(geo, ocs, this.width, this.height, isRev); + else + ScaleUV(geo); + } DeferUpdate() { if (this.NeedUpdateFlag & UpdateDraw.Matrix) @@ -1682,7 +1695,6 @@ export class ExtrudeSolid extends Entity if (this.RelevanceKnifs.some(id => !id.IsErase)) this.NeedUpdateFlag |= UpdateDraw.Geometry; } - super.DeferUpdate(); } @@ -1734,7 +1746,6 @@ export class ExtrudeSolid extends Entity ); } } - UpdateDrawObjectMaterial(renderType: RenderType, obj: Object3D) { if (renderType === RenderType.Wireframe) diff --git a/src/DatabaseServices/PhysicalMaterialRecord.ts b/src/DatabaseServices/PhysicalMaterialRecord.ts index f075868bb..b70a253bf 100644 --- a/src/DatabaseServices/PhysicalMaterialRecord.ts +++ b/src/DatabaseServices/PhysicalMaterialRecord.ts @@ -4,6 +4,7 @@ import { CADFiler } from "./CADFiler"; import { MaterialTableRecord } from "./MaterialTableRecord"; import { ObjectId } from "./ObjectId"; import { TextureTableRecord } from "./Texture"; +import { AutoRecord } from "./AutoRecord"; export interface IGoodProps @@ -35,6 +36,7 @@ export class PhysicalMaterialRecord extends MaterialTableRecord material: "", }; private material = new MeshPhysicalMaterial({}); + @AutoRecord IsFull = false; async Update() { if (!this.material.color) @@ -113,19 +115,25 @@ export class PhysicalMaterialRecord extends MaterialTableRecord this.useRoughnessMap = file.Read(); if (ver <= 2) file.Read(); - else + if (ver > 2) { this._goodsInfo.name = file.Read(); this._goodsInfo.material = file.Read(); this._goodsInfo.color = file.Read(); } + + if (ver > 3) + { + this.IsFull = file.Read(); + } + this.Update(); } //对象将自身数据写入到文件. WriteFile(file: CADFiler) { super.WriteFile(file); - file.Write(3); + file.Write(4); file.Write(this.color); file.Write(this.transparent); file.Write(this.matalness); @@ -142,6 +150,7 @@ export class PhysicalMaterialRecord extends MaterialTableRecord file.Write(this._goodsInfo.name); file.Write(this._goodsInfo.material); file.Write(this._goodsInfo.color); + file.Write(this.IsFull); } //#endregion } diff --git a/src/Geometry/BoardUVGenerator.ts b/src/Geometry/BoardUVGenerator.ts index 380c13628..4af6e2157 100644 --- a/src/Geometry/BoardUVGenerator.ts +++ b/src/Geometry/BoardUVGenerator.ts @@ -67,9 +67,9 @@ class BoardUVGenerator2 extends BoardUVGenerator var c_y = vertices[indexC * 3 + 1]; return [ - new Vector2(-a_y, a_x), - new Vector2(-b_y, b_x), - new Vector2(-c_y, c_x) + new Vector2(a_y, a_x), + new Vector2(b_y, b_x), + new Vector2(c_y, c_x) ]; } } diff --git a/src/Geometry/UVUtils.ts b/src/Geometry/UVUtils.ts index eebbe30e4..cac497118 100644 --- a/src/Geometry/UVUtils.ts +++ b/src/Geometry/UVUtils.ts @@ -1,4 +1,5 @@ -import { Geometry } from "three"; +import { Geometry, Matrix4, Vector3 } from "three"; +import { AsVector3 } from "./GeUtils"; export function ScaleUV(geo: Geometry, scale = 1e-3) { @@ -13,3 +14,28 @@ export function ScaleUV(geo: Geometry, scale = 1e-3) } } } +export function ScaleUV2(geo: Geometry, ocs: Matrix4, xScale = 1e-3, yScale = 1e-3, isInvert = false) +{ + for (let uvsg of geo.faceVertexUvs) + { + for (let uvs of uvsg) + { + for (let uv of uvs) + { + let p = new Vector3(uv.x, uv.y).applyMatrix4(ocs); + uv.x = p.x; + uv.y = p.y; + if (isInvert) + { + uv.x /= yScale; + uv.y /= xScale; + } + else + { + uv.x /= xScale; + uv.y /= yScale; + } + } + } + } +} diff --git a/src/UI/MaterialEditor/PropertiesPane.tsx b/src/UI/MaterialEditor/PropertiesPane.tsx index e56a9114b..d886ec172 100644 --- a/src/UI/MaterialEditor/PropertiesPane.tsx +++ b/src/UI/MaterialEditor/PropertiesPane.tsx @@ -1,8 +1,8 @@ -import { Divider } from "@blueprintjs/core"; +import { Divider, Checkbox } from "@blueprintjs/core"; import { inject, observer } from "mobx-react"; import * as React from "react"; import { MaterialStore } from "../Store/MaterialStore"; -import { Check, ColorSelect, Lable, LableInput, Slider } from "./MaterialCommon"; +import { Check, ColorSelect, Lable, LableInput, Slider, Input } from "./MaterialCommon"; import { MaterialLinkShopId } from "./MaterialLinkShop"; import { Texture } from "./TextureItem"; import { TextureList } from "./TextureList"; @@ -30,6 +30,7 @@ export class PropertiesPane extends React.Component<{ store?: MaterialStore; }, + store.isFull = !store.isFull} />
{ />
- 重复 - X + 尺寸(m) + - Y +
-
- 尺寸 - - - - -
diff --git a/src/UI/Store/MaterialStore.ts b/src/UI/Store/MaterialStore.ts index 683e881dc..87559f6f4 100644 --- a/src/UI/Store/MaterialStore.ts +++ b/src/UI/Store/MaterialStore.ts @@ -9,6 +9,9 @@ import { MaterialEditor } from "../../Editor/MaterialEditor"; import { IDirectoryProps } from "../Components/SourceManage/CommonPanel"; import { AppToaster } from "../Components/Toaster"; import { TextureStore } from "./TextureStore"; +import { UpdateDraw } from "../../Common/Status"; + +let oldFullStatus = false; export class MaterialStore extends Singleton { @@ -37,7 +40,7 @@ export class MaterialStore extends Singleton currentEditorStore: TextureStore; currentTextureTable: TextureTableRecord; currentDir: IDirectoryProps; - + @observable isFull = false; constructor() { super(); @@ -79,6 +82,7 @@ export class MaterialStore extends Singleton this.textureMaping.startObserver(); this.bumpMaping.startObserver(); this.roughnessMaping.startObserver(); + oldFullStatus = this.isFull; } Destroy() { @@ -86,6 +90,18 @@ export class MaterialStore extends Singleton this.textureMaping.dispose(); this.bumpMaping.dispose(); this.roughnessMaping.dispose(); + + if (oldFullStatus !== this.isFull) + { + for (let en of app.Database.ModelSpace.Entitys) + { + if (en.Material === this.Material.Id || app.Database.DefaultMaterial.Id === this.Material.Id) + { + en.Update(UpdateDraw.Geometry); + } + } + app.Viewer.UpdateRender(); + } } Material: PhysicalMaterialRecord; BindMaterial(material: PhysicalMaterialRecord) @@ -132,6 +148,7 @@ export class MaterialStore extends Singleton this.Material.useMap = this.textureMaping.use.get(); this.Material.useBumpMap = this.bumpMaping.use.get(); this.Material.useRoughnessMap = this.roughnessMaping.use.get(); + this.Material.IsFull = this.isFull; this.Material.GoodsInfo = toJS(this.goodsInfo); @@ -139,7 +156,7 @@ export class MaterialStore extends Singleton this.bumpMaping.UpdateStore(this.bumpMaping.textureId); this.roughnessMaping.UpdateStore(this.roughnessMaping.textureId); - this.Material.Update(); + await this.Material.Update(); await (MaterialEditor.GetInstance() as MaterialEditor).Update(); } }; @@ -155,6 +172,7 @@ export class MaterialStore extends Singleton this.transparent.set(parseFloat((1 - this.Material.opacity).toFixed(2))); this.bumpScale.set(this.Material.bumpScale); this.roughness.set(this.Material.roughness); + this.isFull = this.Material.IsFull; Object.assign(this.goodsInfo, this.Material.GoodsInfo); } diff --git a/src/UI/Store/TextureStore.ts b/src/UI/Store/TextureStore.ts index 856d1e27f..a0984900c 100644 --- a/src/UI/Store/TextureStore.ts +++ b/src/UI/Store/TextureStore.ts @@ -75,8 +75,8 @@ export class TextureStore this.updateing = true; - this.repeatX.set(texture.repeatX); - this.repeatY.set(texture.repeatY); + this.repeatX.set(1 / texture.repeatX); + this.repeatY.set(1 / texture.repeatY); this.warpS.set(texture.WrapS); this.wrapT.set(texture.WrapT); let deg = MathUtils.radToDeg(texture.rotation); @@ -99,7 +99,7 @@ export class TextureStore this.repeatX.set(1); } else - texture.repeatX = this.repeatX.get(); + texture.repeatX = 1 / this.repeatX.get(); if (texture.WrapT === ClampToEdgeWrapping) { @@ -107,7 +107,7 @@ export class TextureStore this.repeatY.set(1); } else - texture.repeatY = this.repeatY.get(); + texture.repeatY = 1 / this.repeatY.get(); } }