123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- var lineAB = new THREE.Vector3(0, 0, 0);
- var lineBC = new THREE.Vector3(0, 0, 0);
- var crossResult = new THREE.Vector3(0, 0, 0);
- // update view
- async function refreshClipMesh(plane, mesh, imageName, callback) {
- let points = LineIntersectionHelper.getLineIntersectionPoints(
- EdgesManager.getCubeEdges(),
- plane
- );
- if (points.length < 3) {
- return false;
- }
- //get clipPlaneData From WPF
- var clipPlaneData = await getClipPlaneData();
- if (clipPlaneData.ErrorCode != 1000) {
- console.error("get data error :" + clipPlaneData.ErrorCode);
- return false;
- } else {
- updateMesh();
- return true;
- }
- async function getClipPlaneData() {
- //convert points
- convertToVTKPoints(points);
- let mappingPoints = [];
- points.forEach((item) =>
- mappingPoints.push(
- new cefMappingPoint(
- Math.abs(item.x),
- Math.abs(item.y),
- Math.abs(item.z)
- )
- )
- );
- let inputData = {
- PointsList: mappingPoints,
- ClipImageName: imageName,
- };
- // let json = jsObj.GetClipPlaneData(
- // OSHelper.convertCefParameter(inputData));
- let json = await Dart_getClipPlaneData(JSON.stringify(inputData));
- // window.alert(json);
- return JSON.parse(json);
- }
- function updateMesh() {
- //get verticePoints
- convertBackToWorldPoints(clipPlaneData.WorldPoints);
- let verticesPoints = [];
- clipPlaneData.WorldPoints.forEach((item) =>
- verticesPoints.push(new THREE.Vector3(item.X, item.Y, item.Z))
- );
- //get imageVectors
- var imageVectors = [];
- clipPlaneData.ImagePoints.forEach((item) =>
- imageVectors.push(new THREE.Vector2(item.X, item.Y))
- );
- LoaderUtility.loadBase64Texture(clipPlaneData.ImageData, (texture) => {
- mesh.material.uniforms.tDiffuse.value.dispose();
- mesh.material.uniforms.tDiffuse.value = texture;
- updateMeshGeometry();
- if (callback != undefined) {
- callback();
- }
- });
- ///更新Mesh
- function updateMeshGeometry() {
- mesh.geometry.vertices = verticesPoints;
- mesh.geometry.faces = [];
- mesh.geometry.faceVertexUvs[0] = [];
- lineAB.subVectors(verticesPoints[1], verticesPoints[0]);
- lineBC.subVectors(verticesPoints[2], verticesPoints[1]);
- crossResult.crossVectors(lineAB, lineBC);
- let dotResult = crossResult.dot(plane.normal);
- let faceId = 0;
- for (let i = 2; i < verticesPoints.length; i++) {
- if (dotResult <= 0) {
- setMeshGeometryFace(0, i - 1, i);
- } else {
- setMeshGeometryFace(0, i, i - 1);
- }
- }
- mesh.material.needsUpdate = true;
- mesh.geometry.elementsNeedUpdate = true;
- mesh.geometry.computeBoundingSphere();
- ClipPlaneManager.drawActiveMeshEdges();
- function setMeshGeometryFace(x, y, z) {
- mesh.geometry.faces.push(new THREE.Face3(x, y, z));
- mesh.geometry.faceVertexUvs[0][faceId++] = [
- imageVectors[x],
- imageVectors[y],
- imageVectors[z],
- ];
- }
- }
- }
- }
|