!1121 功能:展开材质到板上

pull/1121/MERGE
ZoeLeeFZ 4 years ago committed by ChenX
parent b7c3e4f0fd
commit 1ee95de3b0

@ -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,

@ -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)

@ -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)

@ -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
}

@ -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)
];
}
}

@ -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;
}
}
}
}
}

@ -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; },
<Slider prompt="凹凸度" value={store.bumpScale} min={0} max={1} step={0.1} />
<Slider prompt="粗糙度" value={store.roughness} min={0} max={1} step={0.1} />
<Slider prompt="金属度" value={store.matalness} min={0} max={1} step={0.1} />
<Checkbox label="铺满到板件" checked={store.isFull} onChange={() => store.isFull = !store.isFull} />
<Divider />
<div style={{
overflowY: "auto",

@ -98,25 +98,18 @@ export class Texture extends React.Component<ITextureProps, {}>{
/>
</Label>
<div style={{ margin: 3, display: "flex" }}>
<span style={{ ...PromptStyle, width: 50 }}></span>
<span style={SpanStyle}>X</span>
<span style={{ ...PromptStyle, width: 50, whiteSpace: "nowrap" }}>(m)</span>
<span style={SpanStyle}></span>
<Input
value={textureStore.repeatX}
disabled={textureStore.warpS.get() === ClampToEdgeWrapping}
/>
<span style={SpanStyle}>Y</span>
<span style={SpanStyle}></span>
<Input
value={textureStore.repeatY}
disabled={textureStore.wrapT.get() === ClampToEdgeWrapping}
/>
</div>
<div style={{ margin: 3, display: "flex" }}>
<span style={{ ...PromptStyle, width: 50 }}></span>
<span style={SpanStyle}></span>
<input style={InputStyle} />
<span style={SpanStyle}></span>
<input style={InputStyle} />
</div>
</div>
</div>
</div>

@ -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);
}

@ -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();
}
}

Loading…
Cancel
Save