-
Notifications
You must be signed in to change notification settings - Fork 15
Plan2D #247
base: main
Are you sure you want to change the base?
Plan2D #247
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -115,7 +115,7 @@ export class Mesh { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Returns submesh for given index. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getSubMesh (index: number) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return new StandardSubmesh(this, index) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return new SealedSubmesh(this, index) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -126,15 +126,15 @@ export class Mesh { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
throw new Error('Can only be called when mesh.merged = true') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const index = this.binarySearch(this.submeshes, faceIndex * 3) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return new StandardSubmesh(this, index) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return new SealedSubmesh(this, index) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @returns Returns all submeshes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getSubmeshes () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return this.instances.map((s, i) => new StandardSubmesh(this, i)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return this.instances.map((s, i) => new SealedSubmesh(this, i)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private binarySearch (array: number[], element: number) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -164,7 +164,8 @@ export class Mesh { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// eslint-disable-next-line no-use-before-define | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export type MergedSubmesh = StandardSubmesh | InsertableSubmesh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export type MergedSubmesh = SealedSubmesh | InsertableSubmesh | SimpleMesh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// eslint-disable-next-line no-use-before-define | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export type Submesh = MergedSubmesh | InstancedSubmesh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export class SimpleInstanceSubmesh { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -179,7 +180,21 @@ export class SimpleInstanceSubmesh { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export class StandardSubmesh { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export class SimpleMesh { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mesh: THREE.Mesh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
get three () { return this.mesh } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
readonly index : number = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
readonly merged = true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
readonly meshStart = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
readonly meshEnd : number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
constructor (mesh: THREE.Mesh) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.mesh = mesh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.meshEnd = mesh.geometry.index!.count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+183
to
+195
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle potential null reference of 'mesh.geometry.index' In the Consider modifying the constructor to handle undefined constructor (mesh: THREE.Mesh) {
this.mesh = mesh
- this.meshEnd = mesh.geometry.index!.count
+ if (mesh.geometry.index) {
+ this.meshEnd = mesh.geometry.index.count
+ } else {
+ this.meshEnd = mesh.geometry.attributes.position.count / mesh.geometry.attributes.position.itemSize
+ }
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export class SealedSubmesh { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mesh: Mesh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
index: number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -115,6 +115,11 @@ export interface ICamera { | |||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
stop () : void | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||
* Immediately stops the camera movement. And prevents any further movement until set to false. | ||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
freeze: boolean | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||
* The target at which the camera is looking at and around which it rotates. | ||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
|
@@ -152,6 +157,7 @@ export class Camera implements ICamera { | |||||||||||||||||||||||||||||
private _inputVelocity = new THREE.Vector3() | ||||||||||||||||||||||||||||||
private _velocity = new THREE.Vector3() | ||||||||||||||||||||||||||||||
private _speed: number = 0 | ||||||||||||||||||||||||||||||
private _freeze: boolean = false | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// orbit | ||||||||||||||||||||||||||||||
private _orthographic: boolean = false | ||||||||||||||||||||||||||||||
|
@@ -204,13 +210,25 @@ export class Camera implements ICamera { | |||||||||||||||||||||||||||||
/** Ignore movement permissions when true */ | ||||||||||||||||||||||||||||||
private _force: boolean = false | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
get freeze () { | ||||||||||||||||||||||||||||||
return this._freeze | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
set freeze (value: boolean) { | ||||||||||||||||||||||||||||||
this._freeze = value | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||
* Represents allowed movement along each axis using a Vector3 object. | ||||||||||||||||||||||||||||||
* Each component of the Vector3 should be either 0 or 1 to enable/disable movement along the corresponding axis. | ||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
private _allowedMovement = new THREE.Vector3(1, 1, 1) | ||||||||||||||||||||||||||||||
get allowedMovement () { | ||||||||||||||||||||||||||||||
return this._force ? new THREE.Vector3(1, 1, 1) : this._allowedMovement | ||||||||||||||||||||||||||||||
return this._force | ||||||||||||||||||||||||||||||
? new THREE.Vector3(1, 1, 1) | ||||||||||||||||||||||||||||||
: this._freeze | ||||||||||||||||||||||||||||||
? new THREE.Vector3(0, 0, 0) | ||||||||||||||||||||||||||||||
: this._allowedMovement | ||||||||||||||||||||||||||||||
Comment on lines
+227
to
+231
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve readability by replacing nested ternary operators with if-else statements Nested ternary operators can be hard to read and maintain. Consider refactoring the getter to use if-else statements for better clarity. Apply this diff to improve readability: get allowedMovement () {
- return this._force
- ? new THREE.Vector3(1, 1, 1)
- : this._freeze
- ? new THREE.Vector3(0, 0, 0)
- : this._allowedMovement
+ if (this._force) {
+ return new THREE.Vector3(1, 1, 1)
+ } else if (this._freeze) {
+ return new THREE.Vector3(0, 0, 0)
+ } else {
+ return this._allowedMovement
+ }
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
set allowedMovement (axes: THREE.Vector3) { | ||||||||||||||||||||||||||||||
|
@@ -225,7 +243,11 @@ export class Camera implements ICamera { | |||||||||||||||||||||||||||||
* Each component of the Vector2 should be either 0 or 1 to enable/disable rotation around the corresponding axis. | ||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
get allowedRotation () { | ||||||||||||||||||||||||||||||
return this._force ? new THREE.Vector2(1, 1) : this._allowedRotation | ||||||||||||||||||||||||||||||
return this._force | ||||||||||||||||||||||||||||||
? new THREE.Vector2(1, 1) | ||||||||||||||||||||||||||||||
: this._freeze | ||||||||||||||||||||||||||||||
? new THREE.Vector2(0, 0) | ||||||||||||||||||||||||||||||
: this._allowedRotation | ||||||||||||||||||||||||||||||
Comment on lines
+246
to
+250
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve readability by replacing nested ternary operators with if-else statements Nested ternary operators can be hard to read and maintain. Consider refactoring the getter to use if-else statements for better clarity. Apply this diff to improve readability: get allowedRotation () {
- return this._force
- ? new THREE.Vector2(1, 1)
- : this._freeze
- ? new THREE.Vector2(0, 0)
- : this._allowedRotation
+ if (this._force) {
+ return new THREE.Vector2(1, 1)
+ } else if (this._freeze) {
+ return new THREE.Vector2(0, 0)
+ } else {
+ return this._allowedRotation
+ }
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
set allowedRotation (axes: THREE.Vector2) { | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider parameterizing plan URLs and colors
The addition of plans to the viewer's gizmos enhances its capabilities. However, there are a few points to consider:
Here's a suggestion to improve this section:
This approach allows for easier management of multiple plans and their colors.