Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Sroberge/2 0 6 #244

Merged
merged 7 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import './style.css'
export * as THREE from 'three'

export {IProgressLogs} from 'vim-format'
export { IProgressLogs } from 'vim-format'
export * from './vim-loader/progressive/open'
export * from './vim-loader/progressive/vimx'
export * from './vim-webgl-viewer/viewer'
Expand All @@ -25,8 +25,7 @@ export * from './vim-loader/progressive/g3dSubset'
export * from './vim-loader/geometry'
export * from './vim-loader/legacy/vimBuilder'
export * from './vim-loader/materials/viewerMaterials'
export * from './vim-loader/object'
export * from './vim-loader/objectInterface'
export * from './vim-loader/object3D'
export * from './vim-loader/scene'
export * from './vim-loader/vim'
export * from './vim-loader/vimSettings'
Expand Down
10 changes: 5 additions & 5 deletions src/vim-loader/mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,17 @@ export class Mesh {
}
}

// eslint-disable-next-line no-use-before-define
export type MergedSubmesh = StandardSubmesh | InsertableSubmesh
export type Submesh = MergedSubmesh | InstancedSubmesh
export type Submesh = MergedSubmesh | InstancedSubmesh

export class SimpleInstanceSubmesh
{
export class SimpleInstanceSubmesh {
mesh: THREE.InstancedMesh
get three() {return this.mesh}
get three () { return this.mesh }
index : number
readonly merged = false

constructor(mesh: THREE.InstancedMesh, index : number){
constructor (mesh: THREE.InstancedMesh, index : number) {
this.mesh = mesh
this.index = index
}
Expand Down
14 changes: 5 additions & 9 deletions src/vim-loader/object.ts → src/vim-loader/object3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import { IElement, VimHelpers } from 'vim-format'
import { ObjectAttribute } from './objectAttributes'
import { ColorAttribute } from './colorAttributes'
import { Submesh } from './mesh'
import { IObject, ObjectType } from './objectInterface'

/**
* High level api to interact with the loaded vim geometry and data.
*/
export class Object implements IObject {

export class Object3D {
private _color: THREE.Color | undefined
private _boundingBox: THREE.Box3 | undefined
private _meshes: Submesh[] | undefined
Expand All @@ -31,8 +29,8 @@ export class Object implements IObject {
/**
* Indicate whether this object is architectural or markup.
*/
public readonly type: ObjectType = "Architectural"
public readonly type = 'Architectural'

/**
* The vim object from which this object came from.
*/
Expand Down Expand Up @@ -62,7 +60,7 @@ export class Object implements IObject {
get hasMesh () {
return (this._meshes?.length ?? 0) > 0
}

/**
* Determines whether to render selection outline for this object or not.
*/
Expand Down Expand Up @@ -90,7 +88,7 @@ export class Object implements IObject {
}
}

/**
/**
* Determines whether to render this object or not.
*/
get visible () {
Expand All @@ -115,7 +113,6 @@ export class Object implements IObject {
set color (color: THREE.Color | undefined) {
this._color = color
this.vim.scene.setDirty()
this._color = this._color
this._coloredAttribute.apply(this._color !== undefined)
this._colorAttribute.apply(this._color)
}
Expand Down Expand Up @@ -254,4 +251,3 @@ export class Object implements IObject {
this._colorAttribute.updateMeshes(meshes)
}
}

1 change: 0 additions & 1 deletion src/vim-loader/objectAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { MergedSubmesh, SimpleInstanceSubmesh, Submesh } from './mesh'

export type AttributeTarget = Submesh | SimpleInstanceSubmesh


export class ObjectAttribute<T> {
readonly vertexAttribute: string
readonly instanceAttribute: string
Expand Down
94 changes: 0 additions & 94 deletions src/vim-loader/objectInterface.ts

This file was deleted.

26 changes: 13 additions & 13 deletions src/vim-loader/vim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as THREE from 'three'
import { VimDocument, G3d, VimHeader, FilterModeNext, FilterMode } from 'vim-format'
import { Scene } from './scene'
import { VimSettings } from './vimSettings'
import { Object } from './object'
import { Object3D } from './object3D'
import {
ElementMapping,
ElementMapping2,
Expand Down Expand Up @@ -71,7 +71,7 @@ export class Vim {

private readonly _builder: SubsetBuilder
private readonly _loadedInstances = new Set<number>()
private readonly _elementToObject = new Map<number, Object>()
private readonly _elementToObject = new Map<number, Object3D>()

/**
* Getter for accessing the event dispatched whenever a subset begins or finishes loading.
Expand Down Expand Up @@ -165,15 +165,15 @@ export class Vim {
const elements = this.map.getElementsFromElementId(id)
return elements
?.map((e) => this.getObjectFromElement(e))
.filter((o): o is Object => o !== undefined) ?? []
.filter((o): o is Object3D => o !== undefined) ?? []
}

/**
* Retrieves the Vim object associated with the given Vim element index.
* @param {number} element - The index of the Vim element.
* @returns {Object | undefined} The Vim object corresponding to the element index, or undefined if not found.
* @returns {Object3D | undefined} The Vim object corresponding to the element index, or undefined if not found.
*/
getObjectFromElement (element: number): Object | undefined {
getObjectFromElement (element: number): Object3D | undefined {
if (!this.map.hasElement(element)) return

if (this._elementToObject.has(element)) {
Expand All @@ -183,18 +183,18 @@ export class Vim {
const instances = this.map.getInstancesFromElement(element)
const meshes = this.scene.getMeshesFromInstances(instances)

const result = new Object(this, element, instances, meshes)
const result = new Object3D(this, element, instances, meshes)
this._elementToObject.set(element, result)
return result
}

/**
* Retrieves an array containing all Vim objects strictly contained within the specified bounding box.
* @param {THREE.Box3} box - The bounding box to search within.
* @returns {Object[]} An array of Vim objects strictly contained within the bounding box.
* @returns {Object3D[]} An array of Vim objects strictly contained within the bounding box.
*/
getObjectsInBox (box: THREE.Box3) {
const result: Object[] = []
const result: Object3D[] = []

for (const obj of this.getObjects()) {
const b = obj.getBoundingBox()
Expand All @@ -208,10 +208,10 @@ export class Vim {

/**
* Retrieves an array of all objects within the Vim.
* @returns {Object[]} An array containing all objects within the Vim.
* @returns {Object3D[]} An array containing all objects within the Vim.
*/
getObjects () {
const result = new Array<Object>()
const result = new Array<Object3D>()
for (const e of this.map.getElements()) {
const obj = this.getObjectFromElement(e)
result.push(obj)
Expand All @@ -222,11 +222,11 @@ export class Vim {
/**
* Retrieves an array containing all objects within the specified subset.
* @param {G3dSubset} subset - The subset to retrieve objects from.
* @returns {Object[]} An array of objects within the specified subset.
* @returns {Object3D[]} An array of objects within the specified subset.
*/
getObjectsInSubset (subset: G3dSubset) {
const set = new Set<Object>()
const result = new Array<Object>()
const set = new Set<Object3D>()
const result = new Array<Object3D>()
const count = subset.getInstanceCount()
for (let i = 0; i < count; i++) {
const instance = subset.getVimInstance(i)
Expand Down
34 changes: 16 additions & 18 deletions src/vim-webgl-viewer/camera/cameraMovement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/

import { Camera } from './camera'
import { Object } from '../../vim-loader/object'
import { IObject } from '../../vim-loader/objectInterface'
import { Object3D } from '../../vim-loader/object3D'
import { SelectableObject } from '../../vim-webgl-viewer/selection'
import * as THREE from 'three'
import { GizmoMarker } from '../gizmos/markers/gizmoMarker'
import { Vim } from '../../vim-loader/vim'
Expand All @@ -21,7 +21,7 @@ export abstract class CameraMovement {
* @param {THREE.Vector3} vector - The 3D vector representing the direction and distance of movement.
*/
abstract move3(vector: THREE.Vector3): void

/**
* Moves the camera in a specified 2D direction within a plane defined by the given axes.
* @param {THREE.Vector2} vector - The 2D vector representing the direction of movement.
Expand Down Expand Up @@ -86,22 +86,22 @@ export abstract class CameraMovement {

// Clone to avoid side effect on argument
const _direction = direction.clone()

// Makes the azimuth be zero for vertical directions
// This avoids weird spin around the axis.
if(_direction.x === 0 && _direction.z ===0){
if (_direction.x === 0 && _direction.z === 0) {
_direction.x = this._camera.forward.x * 0.001
_direction.z = this._camera.forward.z * 0.001
_direction.normalize()
}

// Remove Y component.
const flatForward = forward.clone().setY(0)
const flatDirection = _direction.clone().setY(0)

// Compute angle between vectors on a flat plane.
const cross = flatForward.clone().cross(flatDirection)
const clockwise = cross.y == 0 ? 1 : Math.sign(cross.y)
const clockwise = cross.y === 0 ? 1 : Math.sign(cross.y)
const azimuth = flatForward.angleTo(flatDirection) * clockwise

// Compute the declination angle between the two vectors.
Expand All @@ -119,9 +119,9 @@ export abstract class CameraMovement {

/**
* Rotates the camera without moving so that it looks at the specified target.
* @param {Object | THREE.Vector3} target - The target object or position to look at.
* @param {Object3D | THREE.Vector3} target - The target object or position to look at.
*/
abstract target(target: Object | THREE.Vector3): void
abstract target(target: Object3D | THREE.Vector3): void

/**
* Resets the camera to its last saved position and orientation.
Expand All @@ -135,21 +135,19 @@ export abstract class CameraMovement {
*/
abstract set(position: THREE.Vector3, target?: THREE.Vector3)


/**
* Sets the camera's orientation and position to focus on the specified target.
* @param {IObject | Vim | THREE.Sphere | THREE.Box3 | 'all' | undefined} target - The target object, or 'all' to frame all objects.
* @param {THREE.Vector3} [forward] - Optional forward direction after framing.
*/
frame (
target: IObject | Vim | THREE.Sphere | THREE.Box3 | 'all' | undefined,
target: SelectableObject | Vim | THREE.Sphere | THREE.Box3 | 'all' | undefined,
forward?: THREE.Vector3
): void {

if ((target instanceof GizmoMarker) || (target instanceof Object)) {
if ((target instanceof GizmoMarker) || (target instanceof Object3D)) {
target = target.getBoundingBox()
}
if ((target instanceof Vim) ) {
if ((target instanceof Vim)) {
target = target.scene.getBoundingBox()
}
if (target === 'all') {
Expand All @@ -164,7 +162,7 @@ export abstract class CameraMovement {
}

protected frameSphere (sphere: THREE.Sphere, forward?: THREE.Vector3) {
var direction = this.getNormalizedDirection(forward)
const direction = this.getNormalizedDirection(forward)
// Compute best distance to frame sphere
const fov = (this._camera.camPerspective.camera.fov * Math.PI) / 180
const dist = (sphere.radius * 1.2) / Math.tan(fov / 2)
Expand All @@ -174,11 +172,11 @@ export abstract class CameraMovement {
this.set(pos, sphere.center)
}

private getNormalizedDirection(forward?: THREE.Vector3){
if(!forward){
private getNormalizedDirection (forward?: THREE.Vector3) {
if (!forward) {
return this._camera.forward
}
if(forward.x ===0 && forward.y === 0 && forward.z ===0){
if (forward.x === 0 && forward.y === 0 && forward.z === 0) {
return this._camera.forward
}
return forward.clone().normalize()
Expand Down
Loading