Skip to content

Commit

Permalink
Merge branch 'dev-ct-slice' into dev-ct-slice-upd
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcope committed Sep 16, 2024
2 parents d52eb1d + c19fb39 commit 9233eb6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
2 changes: 2 additions & 0 deletions source/client/applications/coreTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -134,6 +135,7 @@ const types = [
CVGrid,
CVTape,
CVSlicer,
CVCTSlice,
CVTours,
CVSnapshots,
CVEnvironment,
Expand Down
43 changes: 39 additions & 4 deletions source/client/components/CVSlicer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
* 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";

import UberPBRMaterial from "../shaders/UberPBRMaterial";

import CVScene from "./CVScene";
import CVModel2 from "./CVModel2";
import CVAssetReader from "./CVAssetReader";

////////////////////////////////////////////////////////////////////////////////

Expand All @@ -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";

Expand All @@ -59,7 +61,7 @@ export default class CVSlicer extends Component
boundingBox: types.Object("Scene.BoundingBox", Box3),
};

ins = this.addInputs(CVSlicer.ins);
ins = this.addInputs<CObject3D, typeof CVSlicer.ins>(CVSlicer.ins);

get settingProperties() {
return [
Expand All @@ -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()
{
Expand All @@ -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();

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9233eb6

Please sign in to comment.