123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- var sprite = function (
- uncheckedImg,
- checkedImg,
- spriteButtonImage,
- spriteButtonText,
- execute
- ) {
- this.UncheckedImg = uncheckedImg;
- this.CheckedImg = checkedImg;
- this.SpriteButtonImage = spriteButtonImage;
- this.SpriteButtonText = spriteButtonText;
- this.display = function () {
- this.SpriteButtonImage.visible = true;
- this.SpriteButtonText.visible = true;
- };
- this.isVisible = function () {
- return this.SpriteButtonImage.visible;
- };
- this.hide = function () {
- this.SpriteButtonImage.visible = false;
- this.SpriteButtonText.visible = false;
- };
- this.checked = function () {
- EventCenter.emit("SelectedSpriteChanged", this);
- this.SpriteButtonImage.material.map = this.CheckedImg;
- execute();
- };
- this.hightLight = function () {
- this.SpriteButtonImage.material.map = this.CheckedImg;
- };
- this.unchecked = function () {
- this.SpriteButtonImage.material.map = this.UncheckedImg;
- };
- };
- var SpriteManager = {
- spriteMaxCount: 7,
- spriteInterval: 50,
- spriteRotateL: undefined,
- spriteRotateR: undefined,
- spriteQuickClip: undefined,
- spriteMove: undefined,
- spriteClip: undefined,
- isSpriteButtonAdded: false,
- spriteAreaWidth: undefined,
- spriteWidth: undefined,
- spriteHeight: undefined,
- clipType: undefined,
- allowClip: false,
- sprites: [],
- hightLightSprite: undefined,
- selectedSprite: undefined,
- infoHideTask: undefined,
- quickClipExecute: false,
- init: function () {
- this.initSpriteSize();
- EventCenter.addEventHandler(
- "SelectedSpriteChanged",
- this.selectSpriteChanged
- );
- this.spriteMove = this.createSprite(
- "3DWeb/ButtonImage/move.png",
- "3DWeb/ButtonImage/moveMouseDown.png",
- this.moveClipPlaneChecked,
- languageContent.Move
- );
- this.spriteClip = this.createSprite(
- "3DWeb/ButtonImage/clip.png",
- "3DWeb/ButtonImage/clipMouseDown.png",
- this.drawLineChecked,
- languageContent.Clip
- );
- this.spriteQuickClip = this.createSprite(
- "3DWeb/ButtonImage/AI.png",
- "3DWeb/ButtonImage/AIDown.png",
- this.quickClipChecked,
- languageContent.QuickClip
- );
- this.createSprite(
- "3DWeb/ButtonImage/reset.png",
- "3DWeb/ButtonImage/resetMouseDown.png",
- this.resetChecked,
- languageContent.Reset
- );
- this.createSprite(
- "3DWeb/ButtonImage/delete.png",
- "3DWeb/ButtonImage/deleteMouseDown.png",
- this.deleteChecked,
- languageContent.Delete
- );
- this.spriteRotateR = this.createSprite(
- "3DWeb/ButtonImage/rotate-.png",
- "3DWeb/ButtonImage/rotate-MouseDown.png",
- this.rotateRChecked,
- languageContent.RotateR
- );
- this.spriteRotateL = this.createSprite(
- "3DWeb/ButtonImage/rotate+.png",
- "3DWeb/ButtonImage/rotate+MouseDown.png",
- this.rotateLChecked,
- languageContent.RotateL
- );
- },
- initSpriteSize: function () {
- let windowWidth =
- window.innerWidth < OSHelper.windowWidthDefault
- ? OSHelper.windowWidthDefault
- : window.innerWidth;
- this.spriteInterval = windowWidth * 0.02;
- this.spriteAreaWidth = OSHelper.isPC ? windowWidth * 0.4 : windowWidth;
- this.spriteWidth =
- this.spriteAreaWidth / this.spriteMaxCount - this.spriteInterval;
- this.spriteHeight = this.spriteWidth;
- },
- selectSpriteChanged: function (selectItem) {
- if (SpriteManager.selectedSprite != undefined) {
- SpriteManager.selectedSprite.unchecked();
- }
- SpriteManager.selectedSprite = selectItem;
- },
- createSprite: function (originalImage, clickImage, execute, name) {
- let checkedTexture = LoaderUtility.loadTexture(originalImage);
- let uncheckedTexture = LoaderUtility.loadTexture(clickImage);
- let material = new THREE.SpriteMaterial({ map: checkedTexture });
- let spriteImage = new THREE.Sprite(material);
- spriteImage.scale.set(this.spriteWidth, this.spriteHeight, 1);
- let spriteText = this.createSpriteText(name);
- let info = new sprite(
- checkedTexture,
- uncheckedTexture,
- spriteImage,
- spriteText,
- execute
- );
- sceneOrtho.add(info.SpriteButtonImage);
- sceneOrtho.add(info.SpriteButtonText);
- info.hide();
- this.sprites.push(info);
- return info;
- },
- createSpriteText: function (text) {
- let canvas = document.createElement("canvas");
- canvas.width = 512;
- canvas.height = 512;
- let textCanvas = canvas.getContext("2d");
- textCanvas.textAlign = "center";
- textCanvas.fillStyle = "#FFF";
- textCanvas.font = "800 132px Microsoft YaHei";
- textCanvas.lineWidth = 1;
- textCanvas.fillText(text, 256, 128);
- let texture = new THREE.Texture(canvas);
- texture.needsUpdate = true;
- let material = new THREE.SpriteMaterial({ map: texture });
- let textObj = new THREE.Sprite(material);
- let size = this.spriteWidth + this.spriteInterval / 2;
- textObj.scale.set(size, size, 1);
- return textObj;
- },
- mdlFileLoaded: function (sourceenum, docarotidaiclip) {
- var hasAIClip = sourceenum == "Carotid" && docarotidaiclip == "True";
- if (!hasAIClip) {
- this.sprites.splice(2, 1);
- }
- this.resetSpritePosition();
- this.sprites.forEach((m) => {
- if (m != this.spriteRotateL && m != this.spriteRotateR) {
- m.display();
- }
- });
- this.sprites[0].checked();
- this.allowClip = true;
- //hide loading image
- var img = document.getElementById("image");
- img.style.display = "none";
- },
- waitMdlFileLoading: function () {
- this.sprites.forEach((m) => {
- m.hide();
- });
- //show loading image
- var img = document.getElementById("image");
- img.style.display = "block";
- },
- resetSpritePosition: function () {
- let spriteCount = this.sprites.length;
- if (!this.spriteRotateR.isVisible()) {
- spriteCount -= 2;
- }
- for (let i = 0; i < spriteCount; i++) {
- let positionX =
- (0.5 + i - spriteCount / 2) * (this.spriteWidth + this.spriteInterval);
- let positionY = window.innerHeight / 2 - 50;
- this.sprites[i].SpriteButtonImage.position.set(positionX, positionY, 1);
- this.sprites[i].SpriteButtonText.position.set(
- positionX,
- positionY - this.spriteHeight - 10,
- 1
- );
- }
- },
- showRotateSprite: function () {
- if (!this.spriteRotateR.isVisible()) {
- this.spriteRotateR.display();
- this.spriteRotateL.display();
- this.resetSpritePosition();
- }
- },
- hideRotateSprite: function () {
- if (this.spriteRotateR.isVisible()) {
- this.spriteRotateR.hide();
- this.spriteRotateL.hide();
- this.resetSpritePosition();
- }
- },
- mouseDown: function (rayCaster) {
- let intersectSprite = this.getIntersectSprite(rayCaster);
- if (intersectSprite != undefined) {
- intersectSprite.checked();
- document.addEventListener(OSHelper.touchEnd, this.mouseUp, false);
- return true;
- }
- return false;
- },
- mouseUp: function () {
- if (SpriteManager.clipType == ClipType.DrawLine) {
- SpriteManager.spriteClip.checked();
- }
- if (SpriteManager.clipType == ClipType.MoveClipPlane) {
- SpriteManager.spriteMove.checked();
- }
- document.removeEventListener(OSHelper.touchEnd, this.mouseUp, false);
- document.body.style.cursor = "default";
- },
- mouseMove: function (rayCaster) {
- if (
- this.hightLightSprite != undefined &&
- this.hightLightSprite != this.selectedSprite
- ) {
- let intersects = rayCaster.intersectObject(
- this.hightLightSprite.SpriteButtonImage
- );
- if (intersects.length > 0) {
- return;
- } else {
- this.hightLightSprite.unchecked();
- document.body.style.cursor = "default";
- this.hightLightSprite = undefined;
- }
- }
- let intersectSprite = this.getIntersectSprite(rayCaster);
- if (intersectSprite != undefined) {
- if (this.hightLightSprite == intersectSprite) return;
- this.hightLightSprite = intersectSprite;
- if (this.hightLightSprite != this.selectedSprite) {
- document.body.style.cursor = "pointer";
- intersectSprite.hightLight();
- }
- }
- },
- getIntersectSprite: function (rayCaster) {
- let intersects;
- for (let i = 0; i < this.sprites.length; i++) {
- intersects = rayCaster.intersectObject(this.sprites[i].SpriteButtonImage);
- if (intersects.length > 0) {
- return this.sprites[i];
- }
- }
- return undefined;
- },
- rotateLChecked: function () {
- addRotateTask(-1);
- },
- rotateRChecked: function () {
- addRotateTask(1);
- },
- resetChecked: function () {
- ClipPlaneManager.resetClipInfo();
- resetCubePosition();
- ClipPlaneManager.meshIsInactive();
- },
- ///AI 切割
- quickClipChecked: async function () {
- if (!SpriteManager.quickClipExecute) {
- SpriteManager.quickClipExecute = true;
- var success = await SpriteManager.executeQuickClip();
- if (!success) {
- //show info
- var info = document.getElementById("info");
- info.style.display = "block";
- SpriteManager.infoHideTask = setInterval(function () {
- var info = document.getElementById("info");
- info.style.display = "none";
- clearInterval(SpriteManager.infoHideTask);
- }, 5000);
- // jsObj.AIClipStateCallBack(success);
- Dart_aiClipStateCallBack(success);
- SpriteManager.quickClipExecute = false;
- } else {
- ClipPlaneManager.meshIsActive();
- Dart_aiClipStateCallBack(success);
- }
- }
- },
- executeQuickClip: async function () {
- // let json = jsObj.GetVesselClipPlanePoints();
- let json = await Dart_getVesselClipPlanePoints("useless arg");
- let clipPlaneData = JSON.parse(json);
- if (clipPlaneData.ErrorCode != 1000) {
- return false;
- }
- convertBackToWorldPoints(clipPlaneData.WorldPoints);
- let verticesPoints = [];
- clipPlaneData.WorldPoints.forEach((item) =>
- verticesPoints.push(new THREE.Vector3(item.X, item.Y, item.Z))
- );
- return ClipPlaneManager.generateClipPlaneByPoints(
- verticesPoints,
- function () {
- SpriteManager.quickClipExecute = false;
- }
- );
- },
- deleteChecked: function () {
- ClipPlaneManager.removeClipPlane();
- removeRotateInfo();
- LinesDrawingManager.hideClipLine();
- LinesDrawingManager.hideAll();
- ClipPlaneManager.meshIsInactive();
- },
- drawLineChecked: function () {
- SpriteManager.clipType = ClipType.DrawLine;
- },
- moveClipPlaneChecked: function () {
- SpriteManager.clipType = ClipType.MoveClipPlane;
- },
- };
|