-
-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #452 from Kitware/webvr_support
feat(Rendering): Add initial support for WebVR
- Loading branch information
Showing
12 changed files
with
473 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<table> | ||
<tr> | ||
<td> | ||
<button class='vrbutton' style="width: 100%">Send To VR</button> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<select class='representations' style="width: 100%"> | ||
<option value='0'>Points</option> | ||
<option value='1'>Wireframe</option> | ||
<option value='2' selected>Surface</option> | ||
</select> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<input class='resolution' type='range' min='4' max='80' value='6' /> | ||
</td> | ||
</tr> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import 'vtk.js/Sources/favicon'; | ||
|
||
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor'; | ||
import vtkCalculator from 'vtk.js/Sources/Filters/General/Calculator'; | ||
import vtkConeSource from 'vtk.js/Sources/Filters/Sources/ConeSource'; | ||
import vtkFullScreenRenderWindow from 'vtk.js/Sources/Rendering/Misc/FullScreenRenderWindow'; | ||
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper'; | ||
import { AttributeTypes } from 'vtk.js/Sources/Common/DataModel/DataSetAttributes/Constants'; | ||
import { FieldDataTypes } from 'vtk.js/Sources/Common/DataModel/DataSet/Constants'; | ||
|
||
import controlPanel from './controller.html'; | ||
|
||
// ---------------------------------------------------------------------------- | ||
// Standard rendering code setup | ||
// ---------------------------------------------------------------------------- | ||
|
||
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({ background: [0, 0, 0] }); | ||
const renderer = fullScreenRenderer.getRenderer(); | ||
const renderWindow = fullScreenRenderer.getRenderWindow(); | ||
|
||
// ---------------------------------------------------------------------------- | ||
// Example code | ||
// ---------------------------------------------------------------------------- | ||
// create a filter on the fly, sort of cool, this is a random scalars | ||
// filter we create inline, for a simple cone you would not need | ||
// this | ||
// ---------------------------------------------------------------------------- | ||
|
||
const coneSource = vtkConeSource.newInstance({ height: 100.0, radius: 50.0 }); | ||
// const coneSource = vtkConeSource.newInstance({ height: 1.0, radius: 0.5 }); | ||
const filter = vtkCalculator.newInstance(); | ||
|
||
filter.setInputConnection(coneSource.getOutputPort()); | ||
// filter.setFormulaSimple(FieldDataTypes.CELL, [], 'random', () => Math.random()); | ||
filter.setFormula({ | ||
getArrays: inputDataSets => ({ | ||
input: [], | ||
output: [ | ||
{ location: FieldDataTypes.CELL, name: 'Random', dataType: 'Float32Array', attribute: AttributeTypes.SCALARS }, | ||
], | ||
}), | ||
evaluate: (arraysIn, arraysOut) => { | ||
const [scalars] = arraysOut.map(d => d.getData()); | ||
for (let i = 0; i < scalars.length; i++) { | ||
scalars[i] = Math.random(); | ||
} | ||
}, | ||
}); | ||
|
||
const mapper = vtkMapper.newInstance(); | ||
mapper.setInputConnection(filter.getOutputPort()); | ||
|
||
const actor = vtkActor.newInstance(); | ||
actor.setMapper(mapper); | ||
actor.setPosition(20.0, 0.0, 0.0); | ||
|
||
renderer.addActor(actor); | ||
renderer.resetCamera(); | ||
renderWindow.render(); | ||
|
||
// ----------------------------------------------------------- | ||
// UI control handling | ||
// ----------------------------------------------------------- | ||
|
||
fullScreenRenderer.addController(controlPanel); | ||
const representationSelector = document.querySelector('.representations'); | ||
const resolutionChange = document.querySelector('.resolution'); | ||
const vrbutton = document.querySelector('.vrbutton'); | ||
|
||
representationSelector.addEventListener('change', (e) => { | ||
const newRepValue = Number(e.target.value); | ||
actor.getProperty().setRepresentation(newRepValue); | ||
renderWindow.render(); | ||
}); | ||
|
||
resolutionChange.addEventListener('input', (e) => { | ||
const resolution = Number(e.target.value); | ||
coneSource.setResolution(resolution); | ||
renderWindow.render(); | ||
}); | ||
|
||
vrbutton.addEventListener('click', (e) => { | ||
if (vrbutton.textContent === 'Send To VR') { | ||
fullScreenRenderer.getOpenGLRenderWindow().startVR(); | ||
vrbutton.textContent = 'Return From VR'; | ||
} else { | ||
fullScreenRenderer.getOpenGLRenderWindow().stopVR(); | ||
vrbutton.textContent = 'Send To VR'; | ||
} | ||
}); | ||
|
||
// ----------------------------------------------------------- | ||
// Make some variables global so that you can inspect and | ||
// modify objects in your browser's developer console: | ||
// ----------------------------------------------------------- | ||
|
||
global.source = coneSource; | ||
global.mapper = mapper; | ||
global.actor = actor; | ||
global.renderer = renderer; | ||
global.renderWindow = renderWindow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.