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

Commit

Permalink
Merge remote-tracking branch 'origin/main' into sroberge/2_0_6
Browse files Browse the repository at this point in the history
  • Loading branch information
vim-sroberge committed Sep 25, 2024
2 parents fb49110 + 14b30a3 commit 49cf3e4
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 13 deletions.
62 changes: 62 additions & 0 deletions docs/ultra.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!--
Copyright (c) 2021 VIMaec LLC
This code is licensed under MIT license
This is a demonstration of the VIM 3D Model viewer and VIM file loader built using Three.JS
For more information and the latest version see: http://www.github.com/vimaec/vim-webgl-viewer
-->
<html>
<head>
<style>
/*Makes full screen and remove scrollbars*/
html,
body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
/*This prevents touches from being eaten up by the browser.*/
touch-action: none;
}
</style>
<title>VIM 3D Model Viewer</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
</head>
<body>
<div id="vim-app"></div>

<script>
window.process = { env: { NODE_ENV: 'development' } };
</script>
<script src="https://unpkg.com/react@18.2.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/vim-ultra-viewer@0.0.21"></script>
<script>
const container = document.getElementById('vim-app');

// Parse URL for source file
const params = new URLSearchParams(window.location.search)
const url = params.has('vim')
? params.get('vim')
: null

load(url ?? "https://vim02.azureedge.net/samples/residence.v1.2.75.vim")

async function load (url) {
const ref = await ULTRA.createComponent(container)
await ref.connect()
const request = ref.load(url)
await request.wait()
if(request.isSuccess()){
const vim = request.getVim()
ref.viewer.frameAll(0)
}
if(request.isError()){
console.error('Could not open vim file at: ' + url)
}
}
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vim-webgl-viewer",
"version": "2.0.2",
"version": "2.0.2-d",
"description": "A high-performance 3D viewer and VIM file loader built on top of Three.JS.",
"files": [
"dist"
Expand Down
8 changes: 7 additions & 1 deletion src/vim-webgl-viewer/camera/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export interface ICamera {
*/
get forward () : THREE.Vector3

get isLerping () : boolean

/**
* The camera speed factor.
*/
Expand Down Expand Up @@ -182,7 +184,10 @@ export class Camera implements ICamera {
}
private _hasMoved: boolean


get isLerping(){
return this._lerp.isLerping
}

/**
* A signal that is dispatched when the camera is moved.
*/
Expand Down Expand Up @@ -372,6 +377,7 @@ export class Camera implements ICamera {
* Immediately stops the camera movement.
*/
stop () {
this._lerp.cancel()
this._inputVelocity.set(0, 0, 0)
this._velocity.set(0, 0, 0)
}
Expand Down
4 changes: 4 additions & 0 deletions src/vim-webgl-viewer/camera/cameraMovementLerp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export class CameraLerp extends CameraMovement {
this._movement = movement
}

get isLerping(){
return this._clock.running
}

init (duration: number) {
this.cancel()
this._duration = duration
Expand Down
14 changes: 10 additions & 4 deletions src/vim-webgl-viewer/gizmos/gizmoAxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import * as THREE from 'three'
import { Camera } from '../camera/camera'
import { Viewport } from '../viewport'

// TODO make things private cleanup api.
export class Axis {
Expand Down Expand Up @@ -85,6 +86,7 @@ export class GizmoAxes {
private _canvas: HTMLCanvasElement
private context: CanvasRenderingContext2D
private rect: DOMRect
private _reparentConnection: Function

// state
private isDragging: boolean
Expand All @@ -99,13 +101,14 @@ export class GizmoAxes {
/**
* The canvas on which the axes are drawn.
*/
get canvas() {
get canvas () {
return this._canvas
}

constructor (camera: Camera, options?: Partial<GizmoOptions>) {
constructor (camera: Camera, viewport: Viewport, options?: Partial<GizmoOptions>) {
this.options = new GizmoOptions(options)
this.camera = camera
this._reparentConnection = viewport.onReparent.subscribe(() => viewport.parent.appendChild(this._canvas))
this.pointer = new THREE.Vector3()
this.dragStart = new THREE.Vector2()
this.dragLast = new THREE.Vector2()
Expand Down Expand Up @@ -258,7 +261,7 @@ export class GizmoAxes {
}
}

private toMouseVector (e: MouseEvent, target: THREE.Vector3) {
private toMouseVector (e: MouseEvent, target: THREE.Vector3) {
return target.set(e.clientX - this.rect.left, e.clientY - this.rect.top, 0)
}

Expand Down Expand Up @@ -417,7 +420,10 @@ export class GizmoAxes {
/**
* Disposes of the gizmo, removing event listeners and cleaning up resources.
*/
dispose(){
dispose () {
this._reparentConnection?.()
this._reparentConnection = undefined

this._canvas.removeEventListener('pointerdown', this.onPointerDown, false)
this._canvas.removeEventListener('pointerenter', this.onPointerEnter, false)
this._canvas.removeEventListener('pointermove', this.onPointerDrag, false)
Expand Down
2 changes: 1 addition & 1 deletion src/vim-webgl-viewer/gizmos/gizmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class Gizmos {
viewer.settings
)
this.rectangle = new GizmoRectangle(viewer)
this.axes = new GizmoAxes(camera, viewer.settings.axes)
this.axes = new GizmoAxes(camera, viewer.viewport, viewer.settings.axes)
this.markers = new GizmoMarkers(viewer)
viewer.viewport.canvas.parentElement?.prepend(this.axes.canvas)
}
Expand Down
2 changes: 1 addition & 1 deletion src/vim-webgl-viewer/inputs/mouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class MouseHandler extends InputHandler {
}

private onMouseMove = (event: any) => {
event.stopImmediatePropagation()
// We don't stop propagation, mouse move is harmless.
this._lastPosition = new THREE.Vector2(event.offsetX, event.offsetY)

if (
Expand Down
6 changes: 2 additions & 4 deletions src/vim-webgl-viewer/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { RenderScene } from './rendering/renderScene'
import { Viewport } from './viewport'
import { Gizmos } from './gizmos/gizmos'


// loader
import { Renderer } from './rendering/renderer'
import { ISignal, SignalDispatcher } from 'ste-signals'
Expand Down Expand Up @@ -84,7 +83,7 @@ export class Viewer {
/**
* A signal that is dispatched when a new Vim object is loaded or unloaded.
*/
get onVimLoaded () : ISignal{
get onVimLoaded () : ISignal {
return this._onVimLoaded.asEvent()
}

Expand Down Expand Up @@ -117,7 +116,7 @@ export class Viewer {
this.gizmos = new Gizmos(this, this._camera)
this.materials.applySettings(this.settings)

// Ground plane and lights
// Ground plane and lights
this._environment = new Environment(this.settings)
this._environment.getObjects().forEach((o) => this.renderer.add(o))
this.renderer.onBoxUpdated.subscribe((_) => {
Expand Down Expand Up @@ -164,7 +163,6 @@ export class Viewer {
return this._vims.size
}


/**
* Adds a Vim object to the renderer, triggering the appropriate actions and dispatching events upon successful addition.
* @param {Vim} vim - The Vim object to add to the renderer.
Expand Down
21 changes: 20 additions & 1 deletion src/vim-webgl-viewer/viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ export class Viewport {
/** HTML Element in which text is rendered */
readonly textRenderer : CSS2DRenderer

get text(){
get text () {
return this.textRenderer.domElement
}

private _unregisterResize: Function | undefined
private _ownedCanvas: boolean
private _onResize: SignalDispatcher = new SignalDispatcher()
private _onReparent: SignalDispatcher = new SignalDispatcher()

/**
* Signal dispatched when the canvas reparented.
*/
get onReparent () {
return this._onReparent.asEvent()
}

/**
* Signal dispatched when the canvas is resized.
Expand Down Expand Up @@ -83,6 +91,17 @@ export class Viewport {
return renderer
}

get parent () {
return this.canvas.parentElement
}

reparent (parent: HTMLElement) {
if (this.parent === parent) return
parent.appendChild(this.canvas)
parent.appendChild(this.text)
this._onReparent.dispatch()
}

/**
* Removes the canvas if it's owned by the viewer.
*/
Expand Down

0 comments on commit 49cf3e4

Please sign in to comment.