分离选择材质,避免实体选中时,选中材质导致的内部拉槽显示问题.

修正未选中板件时,视图没有刷新的问题.
加入排钻显示.
This commit is contained in:
ChenX
2018-05-31 11:12:29 +08:00
parent 4f3d7a6388
commit cbe28efb08
10 changed files with 79 additions and 27 deletions

View File

@@ -8,6 +8,13 @@ export let boardMaterial = new MeshBasicMaterial({
polygonOffsetUnits: 1
});
export let selectMaterial = new MeshBasicMaterial({
color: new Color(0.1, 0.5, 0.5),
polygonOffset: true,
polygonOffsetFactor: 1, // positive value pushes polygon further away
polygonOffsetUnits: 1
});
//线框的材质
export let edgeMaterial = new LineBasicMaterial({ linewidth: 2, color: new Color(0, 0, 0) });

View File

@@ -3,7 +3,7 @@ import * as THREE from "three";
import { CameraUpdate } from "./CameraUpdate";
import { GetBox, GetBoxArr, cZeroVec } from "./GeUtils";
import { PlaneExt } from "./PlaneExt";
import { PointPick, boardMaterial, CameraControls } from ".";
import { PointPick, boardMaterial, CameraControls, selectMaterial } from ".";
import { MeshBasicMaterial, Color, Mesh } from "three";
export class Viewer
@@ -32,9 +32,6 @@ export class Viewer
this.OnSize();
});
//选中
let selectMaterial = new MeshBasicMaterial({ color: new Color(0.1, 0.5, 0.5) });
let oldMesh: Mesh;
this.m_Render.domElement.addEventListener("mousemove", (e: MouseEvent) =>
{
@@ -45,8 +42,8 @@ export class Viewer
{
oldMesh = mesh;
mesh.material = selectMaterial;
this.m_bNeedUpdate = true;
}
this.m_bNeedUpdate = true;
})
}

View File

@@ -1,5 +1,5 @@
import * as THREE from 'three';
import { Geometry, LineSegments, Shape, Vector2 } from 'three';
import { Geometry, LineSegments, Shape, Vector2, CylinderGeometry } from 'three';
import { polar } from './GeUtils';
import { boardMaterial, edgeMaterial } from './Material';
import { RotateUVs } from './RotateUV';
@@ -90,7 +90,6 @@ export function createBoard(boardData: object)
let matInv: THREE.Matrix4 = new THREE.Matrix4();
//InitBoardMat
{
let xD = getVec(boardData["XVec"]);
let yD = getVec(boardData["YVec"]);
let ZD = getVec(boardData["ZVec"]);
@@ -139,17 +138,39 @@ export function createBoard(boardData: object)
//外边.
let edges = [createEdge(ext)];
//差集
if (boardData["SubBoardLocal"].length > 0)
if (checkObjectArray(boardData, "SubBoardLocal")
|| checkObjectArray(boardData, "Drillings"))
{
let subBoardList = boardData["SubBoardLocal"].map(d => createBoard(d));
let thisCsg = new ThreeBSP(ext);
for (let br of subBoardList)
if (boardData["SubBoardLocal"])
{
edges.push(...br.edges);
let subCsg = new ThreeBSP(br.mesh);
thisCsg = thisCsg.subtract(subCsg);
let subBoardList = boardData["SubBoardLocal"].map(d => createBoard(d));
for (let br of subBoardList)
{
edges.push(...br.edges);
let subCsg = new ThreeBSP(br.mesh);
thisCsg = thisCsg.subtract(subCsg);
}
}
if (boardData["Drillings"])
{
let dris = boardData["Drillings"];
for (let dri of dris)
{
let geo = new CylinderGeometry(dri.r, dri.r, dri.h, 32);
geo.rotateX(Math.PI * 0.5);
geo.translate(dri.x, dri.y, 0);
geo.applyMatrix(boardMat);
edges.push(createEdge(geo));
let subCsg = new ThreeBSP(geo);
thisCsg = thisCsg.subtract(subCsg);
}
}
ext = thisCsg.toGeometry();
}
@@ -161,6 +182,11 @@ export function createBoard(boardData: object)
return { mesh, edges };
}
function checkObjectArray(obj: any, key: string)
{
return obj[key] && obj[key].length > 0;
}
export function createTemplateBoard(brDataList: any[])
{
let meshs = [];