diff --git a/source/client/applications/coreTypes.ts b/source/client/applications/coreTypes.ts index 084efafa..5fde8b19 100644 --- a/source/client/applications/coreTypes.ts +++ b/source/client/applications/coreTypes.ts @@ -64,6 +64,7 @@ import CVFloor from "../components/CVFloor"; import CVGrid from "../components/CVGrid"; import CVTape from "../components/CVTape"; import CVSlicer from "../components/CVSlicer"; +import CVCTSlice from "../components/CVCTSlice"; import CVTours from "../components/CVTours"; import CVSnapshots from "../components/CVSnapshots"; import CVEnvironment from "../components/CVEnvironment"; @@ -134,6 +135,7 @@ const types = [ CVGrid, CVTape, CVSlicer, + CVCTSlice, CVTours, CVSnapshots, CVEnvironment, diff --git a/source/client/components/CVSlicer.ts b/source/client/components/CVSlicer.ts index a97b49a4..e01bee5e 100644 --- a/source/client/components/CVSlicer.ts +++ b/source/client/components/CVSlicer.ts @@ -15,9 +15,10 @@ * limitations under the License. */ -import { Box3, Mesh } from "three"; +import { Box3, DoubleSide, Euler, Mesh, MeshBasicMaterial, PlaneGeometry, Texture } from "three"; -import Component, { types } from "@ff/graph/Component"; +import { types } from "@ff/graph/Component"; +import CObject3D from "@ff/scene/components/CObject3D"; import { ISlicer, ESliceAxis, TSliceAxis } from "client/schema/setup"; @@ -25,6 +26,7 @@ import UberPBRMaterial from "../shaders/UberPBRMaterial"; import CVScene from "./CVScene"; import CVModel2 from "./CVModel2"; +import CVAssetReader from "./CVAssetReader"; //////////////////////////////////////////////////////////////////////////////// @@ -43,7 +45,7 @@ const _planes = [ /** * Component controlling global slicing parameters for all [[CVModel2]] components in a scene. */ -export default class CVSlicer extends Component +export default class CVSlicer extends CObject3D { static readonly typeName: string = "CVSlicer"; @@ -59,7 +61,7 @@ export default class CVSlicer extends Component boundingBox: types.Object("Scene.BoundingBox", Box3), }; - ins = this.addInputs(CVSlicer.ins); + ins = this.addInputs(CVSlicer.ins); get settingProperties() { return [ @@ -77,8 +79,16 @@ export default class CVSlicer extends Component ]; } + protected get assetReader() { + return this.getMainComponent(CVAssetReader); + } + protected plane: number[] = null; protected axisIndex = -1; + protected xSliceSprites: Texture = null; + protected sliceDimU = 43; + protected sliceDimV = 11; + protected sliceCount = 469; create() { @@ -92,6 +102,10 @@ export default class CVSlicer extends Component { const ins = this.ins; + if(this.xSliceSprites == null) { + this.assetReader.getTexture("xSlice.jpg").then((texture) => this.xSliceSprites = texture); + } + if (ins.axis.changed) { const axisIndex = ins.axis.getValidatedValue(); @@ -125,6 +139,27 @@ export default class CVSlicer extends Component const value = 1 - ins.position.value; this.plane[3] = axisInverted ? value * (max - min) - max : max - value * (max - min); + // init slice plane + const angle = Math.PI*0.5; + if(!this.object3D && isFinite(min) && isFinite(max)) { + const geometry = new PlaneGeometry( max-min, max-min ); + const material = new MeshBasicMaterial( {side: DoubleSide} ); + this.xSliceSprites.repeat.set(1/this.sliceDimU,1/this.sliceDimV); + material.map = this.xSliceSprites; + const plane = new Mesh( geometry, material ); + this.object3D = plane; + } + // update slice plane + if(this.object3D) { + const sliceIdx = Math.round(value * (this.sliceCount-1)); + this.xSliceSprites.offset.set((sliceIdx%this.sliceDimU)/this.sliceDimU, (1-(1/this.sliceDimV))-Math.floor(sliceIdx/this.sliceDimU)/this.sliceDimV); + + const pos = max - value * (max - min); + this.object3D.setRotationFromEuler(new Euler(this.plane[1]*angle,this.plane[0]*angle,0)); + this.object3D.position.set(Math.abs(this.plane[0])*pos, Math.abs(this.plane[1])*pos, Math.abs(this.plane[2])*pos); + this.object3D.updateMatrix(); + } + const models = this.getGraphComponents(CVModel2); // set the slicing plane in the Uber materials of each scene model