Merge pull request #35 from potree/threejs_plugin
promoting threejs rewrite to master
5
.gitignore
vendored
@ -1,8 +1,9 @@
|
||||
build
|
||||
./build
|
||||
node_modules
|
||||
docs/.marking_your_own_pointcloud_loader.md.html
|
||||
docs/.file_format.md.html
|
||||
docs/.doc.md.html
|
||||
docs/.how_does_loading_nodes_work.md.html
|
||||
docs/.materials_and_rendermodes.md.html
|
||||
docs/.how_to_create_your_own_pointcloud_loader.md.html
|
||||
docs/.how_to_create_your_own_pointcloud_loader.md.html
|
||||
.project
|
||||
@ -1,18 +0,0 @@
|
||||
# How to use gulp.js to build the library
|
||||
|
||||
## Installation
|
||||
|
||||
npm install -g gulp
|
||||
npm install --save-dev
|
||||
|
||||
## Usage
|
||||
|
||||
gulp clean // Deletes the build directory
|
||||
gulp test // Runs Javascript test "jshint"
|
||||
gulp docs // Build documentation
|
||||
|
||||
gulp debug // Builds script files, watches for changes
|
||||
// and starts a simple webserver (port:3000)
|
||||
gulp build // Builds script files
|
||||
|
||||
If Gulp.js is watching for changes, stop with `ctrl+c`.
|
||||
85
docs/doc.md
@ -1,85 +0,0 @@
|
||||
# Documentation
|
||||
|
||||
* [File Format Description](./file_format.md)
|
||||
* [Materials and Rendermodes](./materials_and_rendermodes.md)
|
||||
* [How Does Loading Nodes Work?](./how_does_loading_nodes_work.md)
|
||||
* [How to create or load your own pointclouds](how_to_create_or_load_your_own_pointclouds.md)
|
||||
* [gulp builds (testing, building documentation and single minified script file, ...)](build.md)
|
||||
|
||||
## Introduction
|
||||
|
||||
Potree is a WebGL based viewer for large point clouds. The idea is that, similar to Google Maps, only visible parts up to a certain level of detail
|
||||
will be loaded and displayed. In order to achieve this, points are partitioned into an octree.
|
||||
The root node r contains a sparse subset of the data. All of its children contain another sparse subset which, combined, will gradualy increase
|
||||
the level of detail.
|
||||
|
||||
|  |  |  |  |
|
||||
| ------------- |:-------------:| -----:| --- |
|
||||
| root | r0, first child of root | root and r0 combined | root and all its children combined |
|
||||
|
||||
## Getting Started
|
||||
|
||||
1. Deploy potree on a webserver.
|
||||
2. Open lion.html.
|
||||
|
||||
This should be the result:
|
||||
|
||||

|
||||
|
||||
And this is what happens inside lion.html:
|
||||
|
||||
Initialize potree inside the canvas element:
|
||||
|
||||
var canvas = document.getElementById("canvas");
|
||||
var success = Potree.init(canvas);
|
||||
if(!success){
|
||||
return;
|
||||
}
|
||||
|
||||
Load a point cloud and add it to the scene:
|
||||
|
||||
var scene = Potree.currentScene;
|
||||
var cloudURL = "resources/pointclouds/lion_takanawa/cloud.js";
|
||||
var pcoNode = POCLoader.load(cloudURL);
|
||||
scene.rootNode.addChild(pcoNode);
|
||||
|
||||
Directly manipulate the transformation matrix of the point cloud node:
|
||||
In this case, the point cloud was upside down so it has to be mirrored along the y-axis.
|
||||
|
||||
pcoNode.transform = [1, 0, 0, 0,
|
||||
0, -1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1];
|
||||
|
||||
Transform the camera:
|
||||
|
||||
var cam = scene.activeCamera;
|
||||
cam.rotateY(Math.PI/2);
|
||||
cam.translate(-1,-1,-1);
|
||||
|
||||
Set the point Size:
|
||||
|
||||
var material = MaterialManager.getMaterial("pointCloud");
|
||||
material.pointSize = 1;
|
||||
|
||||
A high LOD multiplicator will display more nodes that are small or far away:
|
||||
|
||||
Potree.Settings.LODMultiplicator = 20.0;
|
||||
|
||||
|
||||
|
||||
## Compatibility
|
||||
|
||||
| Browser | Result |
|
||||
| -------------------- |:-------------:|
|
||||
| Chrome 32 | works |
|
||||
| Firefox 26 | works |
|
||||
| Safari | works |
|
||||
| Opera 19 | works |
|
||||
| Internet Explorer 11 | does not work |
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Potree is available under the [FreeBSD License](http://en.wikipedia.org/wiki/BSD_licenses) license.
|
||||
|
||||
@ -1,93 +0,0 @@
|
||||
|
||||
# How Does Loading Nodes Work?
|
||||
|
||||
Relevant classes are:
|
||||
|
||||
* <b>PointCloudOctree</b> <br>
|
||||
Manages the octree. Contains methods that finds currently visible nodes for rendering
|
||||
or loading.
|
||||
* <b>PointCloudOctreeNode</b><br>
|
||||
The hierarchy consists of instances of this class. Contains methods to load or unload
|
||||
point cloud data.
|
||||
* <b>PointCloudOctreeSceneNode</b><br>
|
||||
A subclass of SceneNode that can be attached to the scenegraph.
|
||||
Contains the PointCloudOctree instance.
|
||||
* <b>POCLoader</b><br>
|
||||
Loads the point cloud hierarchy from a file.
|
||||
|
||||
## Loading Data
|
||||
|
||||
At first, <b>POCLoader.load(file)</b> reads the point cloud hierarchy from cloud.js and
|
||||
builds a graph of _PointcloudOctreeNode_ instances.
|
||||
This graph will be attached to a _PointCloudOctree_ instance.
|
||||
During rendering, <b>PointCloudOctree.prepareRender()</b> traverses through nodes that
|
||||
are visible from the current point of view. If it encounters a node whose point cloud data
|
||||
has not been loaded, it will stop traversing further down the hierarchy and schedule
|
||||
it for loading by adding it to _loadQueue_.
|
||||
|
||||
// schedule loading of missing point cloud data
|
||||
if (shouldBeRendered && current.pointCloud == null) {
|
||||
if(!current.isLoading){
|
||||
this.loadQueue.push(current);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
The last step of _prepareRender() is a call to <b>PointcloudOctree.processLoadQueue()</b>.
|
||||
Nodes in _loadQueue_ are sorted by their size and we want to load larger nodes first so
|
||||
_processLoadQueue()_ will tell the first few nodes in _loadQueue_ to start loading
|
||||
point cloud data by calling _PointcloudOctreeNode.loadCloudAjax(node)_.
|
||||
The remaining nodes in the queue will be ignored.
|
||||
They'll be loaded at a later time once all their ancestors have been loaded.
|
||||
Additionaly, there are checks to make sure that the size of all loaded nodes does not
|
||||
exceed the point cloud memory limit and that no more than _loadingNodesLimit_
|
||||
nodes are loaded at a time.
|
||||
|
||||
// process the first x nodes in the queue.
|
||||
if(this.loadQueue.length > 0 ){
|
||||
for(var i = 0; i < Math.min(x, this.loadQueue.length); i++){
|
||||
if(lru.byteSize + this.loadQueue[i].sizeInBytes() < PointcloudOctreeNode.memoryThreshold){
|
||||
if(this.nodesBeeingLoaded.length < this.loadingNodesLimit){
|
||||
PointcloudOctreeNode.loadCloudAjax(this.loadQueue[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<b>PointcloudOctreeNode.loadCloudAjax(node)</b> creates an asynchronous XMLHttpRequest
|
||||
to read the point cloud data from the corresponding file in _./data_.
|
||||
Read more about loading point data through XMLHttpRequests in
|
||||
[How To Create Your Own Pointcloud Loader](how_to_create_your_own_pointcloud_loader.md).
|
||||
Once the request is finished, _PointcloudOctreeNode.loadCloudData(node, buffer, url)_
|
||||
is called to send the data directly to the GPU.
|
||||
|
||||
## Cleanup Data
|
||||
|
||||
Pointcloud data can be very large and often it might be necessary to unload some data
|
||||
to create space for new data.
|
||||
_PointcloudOctreeNode.memoryThreshold_ defines a limit for how much point cloud data
|
||||
potree will load. If loading a new node exceeds this limit, potree will first remove
|
||||
some old nodes that weren't rendered in a while.
|
||||
<b>PointcloudOctreeNode.lruNodes</b> (least-recently-used nodes) contains a list of all loaded nodes, ordered by
|
||||
the last time they've been rendered. Recently rendered nodes are at the end of the list.
|
||||
<b>PointcloudOctree.cleanupCache(bytesNeeded, exceptionsRenderQueue)</b>
|
||||
checks if the byte size of all currently loaded nodes, plus the additional size of
|
||||
_bytesNeeded_ exceeds the limit. If it does, it will remove the first few nodes
|
||||
of _lruNodes_, except nodes contained in _exceptionsRenderQueue_.
|
||||
This is done to avoid removing nodes that were scheduled to be rendered.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,130 +0,0 @@
|
||||
# How To Create Or Load Your Own Pointclouds
|
||||
|
||||
This section will explain some approaches to create and display your own point cloud data without using
|
||||
the PointCloudOctree and some important things to consider regarding performance.
|
||||
|
||||
* Use [Typed Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays) for your point data.<br>
|
||||
They're fast and since the last step is to send point data as a typed array to the GPU,
|
||||
it's best to use them at all times.
|
||||
* Allocate all the memory you need to store your points at the beginning. <br>
|
||||
Avoid resizing arrays. Each point usually requires 16 bytes so initialize your ArrayBuffer with numPoints*16.
|
||||
|
||||
## Building A Buffer From Scratch
|
||||
|
||||
In this example, we'll create a procedurally generated patch. <br>
|
||||

|
||||
|
||||
Each point needs 16 bytes. The first step is to create a buffer that can store all points,
|
||||
as well as 2 views. floatView is required to write xyz coordinates in the buffer and byte view
|
||||
is required to write rgba colors.
|
||||
|
||||
var width = 100;
|
||||
var depth = 100;
|
||||
var numPoints = width*depth;
|
||||
var buffer = new ArrayBuffer(numPoints*16);
|
||||
var floatView = new Float32Array(buffer);
|
||||
var byteView = new Uint8Array(buffer);
|
||||
|
||||
In the next step, we'll write coordinates and colors into the buffer.
|
||||
|
||||
var offset = 0;
|
||||
for(var i = 0; i < width; i++){
|
||||
for(var j = 0; j < depth; j++){
|
||||
var x = 10*((i / width)-0.5);
|
||||
var z = 10*((j / depth)-0.5);
|
||||
var y = Math.cos(x) * Math.sin(z);
|
||||
|
||||
var r = 100*(y+1);
|
||||
var g = 0;
|
||||
var b = 0;
|
||||
|
||||
floatView[4*offset+0] = x;
|
||||
floatView[4*offset+1] = y;
|
||||
floatView[4*offset+2] = z;
|
||||
byteView[16*offset+12] = r;
|
||||
byteView[16*offset+13] = g;
|
||||
byteView[16*offset+14] = b;
|
||||
byteView[16*offset+15] = 255;
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
Now that the buffer is finished, you'll have to describe its contents with some PointAttributes:
|
||||
|
||||
var pointAttributes = new PointAttributes();
|
||||
pointAttributes.add(PointAttribute.POSITION_CARTESIAN);
|
||||
pointAttributes.add(PointAttribute.RGBA_PACKED);
|
||||
|
||||
And send the data to the GPU. This is done by creating a PointCloud object and
|
||||
setting the vertex buffer data:
|
||||
|
||||
var pointCloud = new PointCloud("cloud", pointAttributes);
|
||||
pointCloud.setVertexBufferData(buffer);
|
||||
pointCloud.size = numPoints;
|
||||
|
||||
In the last step, we create a PointCloudSceneNode from our pointCloud data and attach it to the rootNode:
|
||||
|
||||
var sceneNode = new PointCloudSceneNode("procedural patch", scene.rootNode, pointCloud);
|
||||
|
||||
## Loading A Buffer With XMLHttpRequests
|
||||
|
||||
XMLHttpRequests can be used to fetch data from a page or file on a webserver.
|
||||
It's usually used to load html or text files but it is also possible to load array buffers
|
||||
that contain point cloud data.
|
||||
|
||||
First, create a request to an URL. We're about to request arraybuffer data so
|
||||
we have to use an asynchronous request.
|
||||
|
||||
var url = ...
|
||||
var async = true;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, async);
|
||||
|
||||
These 2 settings specify that we want arraybuffer data:
|
||||
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
||||
|
||||
Since we're using an asynchronous request, we must specify a function that is called when
|
||||
our request state changes. Once the request is finished, xhr.readyState is set to 4 so we will check
|
||||
for this case. We also have to check xhr.status. A value of 200 means, that the request was successfull.
|
||||
If it was, we retrieve the buffer from xhr.response and do something with it inside displayPointCloud(buffer, url).
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == 4) {
|
||||
// when accessing local files, req.status will be 0
|
||||
if (xhr.status == 200 || xhr.status == 0) {
|
||||
var buffer = xhr.response;
|
||||
displayPointCloud(buffer, url);
|
||||
} else {
|
||||
console.log('Failed to load file! HTTP status: ' + xhr.status + ", file: " + url);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Let's say, buffer is already in the correct format. We can send it directly to the GPU without
|
||||
further processing and then attach it to the scene:
|
||||
|
||||
displayPointCloud = function(buffer, name) {
|
||||
var pointAttributes = new PointAttributes();
|
||||
pointAttributes.add(PointAttribute.POSITION_CARTESIAN);
|
||||
pointAttributes.add(PointAttribute.RGBA_PACKED);
|
||||
|
||||
var pointCloud = new PointCloud(name, pointAttributes);
|
||||
pointCloud.setVertexBufferData(buffer);
|
||||
pointCloud.size = buffer.byteLength / pointAttributes.byteSize;
|
||||
|
||||
var sceneNode = new PointCloudSceneNode("pointcloud node", Potree.currentScene.rootNode, pointCloud);
|
||||
};
|
||||
|
||||
|
||||
|
||||
## Unloading a PointCloud
|
||||
|
||||
Sometimes it's necessary to delete unused point clouds in order to free memory for new point clouds.
|
||||
Use PointCloud.unload to delete data from the GPU.
|
||||
|
||||
var pointcloud = ...
|
||||
pointcloud.unload()
|
||||
|
||||
|
||||
@ -1,77 +0,0 @@
|
||||
# Materials And Rendermodes
|
||||
|
||||
The default material for point clouds is an instance of PointCloudMaterial with the name "pointCloud".
|
||||
In order to change its attributes, you have to retrieve it by calling:
|
||||
|
||||
var material = MaterialManager.getMaterial("pointCloud");
|
||||
|
||||
There are 3 rendermodes available:
|
||||
|
||||
* <b>FIXED_CIRCLE</b>
|
||||
Render points as circles with a fixed size. The pointSize attribute indicates the pixel diameter.
|
||||
* <b>WEIGHTED_CIRCLE</b>
|
||||
Render points as circles with a size depending on the distance to the viewer.
|
||||
* <b>FILTERED_SPLAT</b>
|
||||
Interpolates between overlapping points. High quality but very slow.
|
||||
|
||||
You can change the render mode by calling
|
||||
|
||||
material.renderMode = PointCloudRenderMode.FIXED_CIRCLE;
|
||||
|
||||
|  |  |  |
|
||||
| --------------------------------------- | ------------------------------------------ | ----------------------------------------- |
|
||||
| FIXED_CIRCLES with point-size 2. All points have pixel diameter 2.| WEIGHTED_CIRCLES with point-size 1. Size varies depending on distance from camera. | FILTERED_SPLATS with point-size 1. In this mode, points have the same size as with WEIGHTED_CIRCLES, but overlapping points are interpolated. |
|
||||
|
||||
|
||||
## PointCloudMaterial
|
||||
|
||||
PointCloudMaterial is actually a combination of other materials.
|
||||
It dispatches render calls to the material in use.
|
||||
|
||||
## FixedPointSizeMaterial
|
||||
|
||||
Used when rendermode is set to FIXED_CIRCLE.
|
||||
The _render(sceneNode, renderer)_ function extracts extracts all pointCloud from sceneNode,
|
||||
that should be rendered. The _renderPointClouds()_ function invokes the WebGL
|
||||
draw calls.
|
||||
|
||||
## WeightedPointSizeMaterial
|
||||
|
||||
Used when rendermode is set to WEIGHTED_CIRCLE.
|
||||
It works the same way as FixedPointSizeMaterial, except with a different vertex shader
|
||||
that adjusts the point size according to the distance from the viewer.
|
||||
|
||||
## FilteredSplatsMaterial
|
||||
|
||||
Used when rendermode is set to FILTERED_SPLATS.
|
||||
This material is based on the paper [High Quality Splatting on Today's GPUs](http://graphics.ucsd.edu/~matthias/Papers/HighQualitySplattingOnGPUs.pdf).
|
||||
|
||||
The idea is, that overlapping points should be blended together, if their distance to the viewer is roughly the same.
|
||||
Simple point rendering usualy leads to overlapping points:<br>
|
||||

|
||||
|
||||
This material consists of 3 passes:
|
||||
|
||||
1. <b>Depth-Pass</b> Renders the point cloud into a depth buffer. Depth values are pushed away from the viewer with an offset given by uBlendDepth.
|
||||
Fragments within this offset-range will be blended together. Fragments that are farther away will be discarded during the depth test.
|
||||
2. <b>Attribute-Pass</b> Renders the point cloud with weighted attributes and blend mode set to ADD.
|
||||
The weight function gives fragments that are closer to the center a higher weight.<br>
|
||||
The result of this pass is a weighted sum of overlapping attributes, stored in the RGB component:<br>
|
||||

|
||||
And the sum of weights, stored in the alpha component:<br>
|
||||

|
||||
3. <b>Normalization-Pass</b> In this pass, the output of the previous pass is normalized by
|
||||
dividing the weighted sum of colors in the RGB component by the sum of weights in the alpha component.
|
||||
It's essentially a screen-space filter so this time, not the point cloud is rendered but
|
||||
a rectangle that spans the whole screen with the output of the previous pass
|
||||
as the its texture. This is one possible result:<br>
|
||||
<br>
|
||||
The smoothness of the transition depends on the weight function. By adjusting the weight function, you can get
|
||||
very smooth or relatively sharp borders.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
208
examples/distance_measure.html
Normal file
@ -0,0 +1,208 @@
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<script src="../libs/three.js/build/three.js"></script>
|
||||
<script src="../libs/other/OrbitControls.js"></script>
|
||||
<script src="../src/Potree.js"></script>
|
||||
<script src="../src/PointCloudOctree.js"></script>
|
||||
<script src="../src/PointCloudOctreeGeometry.js"></script>
|
||||
<script src="../src/loader/POCLoader.js"></script>
|
||||
<script src="../src/loader/PointAttributes.js"></script>
|
||||
<script src="../src/utils.js"></script>
|
||||
<script src="../src/LRU.js"></script>
|
||||
|
||||
</head>
|
||||
<body style="margin: 0px; padding: 0px;">
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
#lblDistance{
|
||||
color:white;
|
||||
font-weight: bold;
|
||||
text-shadow: 2px 2px 2px black,
|
||||
2px -2px 2px black,
|
||||
-2px 2px 2px black,
|
||||
-2px -2px 2px black;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var renderer;
|
||||
var camera;
|
||||
var scene;
|
||||
var mouse = { x: 1, y: 1 };
|
||||
var projector, raycaster;
|
||||
var pointcloud;
|
||||
var spStart, spEnd, sConnection;
|
||||
var placeStartMode = false;
|
||||
var placeEndMode = false;
|
||||
|
||||
function init() {
|
||||
scene = new THREE.Scene();
|
||||
camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
|
||||
|
||||
projector = new THREE.Projector();
|
||||
raycaster = new THREE.Raycaster();
|
||||
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
document.body.appendChild(renderer.domElement);
|
||||
|
||||
// pointcloud
|
||||
var material = new THREE.PointCloudMaterial( { size: 0.02, vertexColors: true } );
|
||||
var pco = POCLoader.load("../resources/pointclouds/lion_takanawa/cloud.js");
|
||||
pointcloud = new Potree.PointCloudOctree(pco, material);
|
||||
pointcloud.LODDistance = 80;
|
||||
pointcloud.rotation.x = Math.PI;
|
||||
pointcloud.position.x = 8;
|
||||
pointcloud.position.z = -2;
|
||||
pointcloud.position.y = 4;
|
||||
scene.add(pointcloud);
|
||||
|
||||
// grid
|
||||
scene.add(createGrid(8,8,1));
|
||||
|
||||
// measurement
|
||||
var sphereGeometry = new THREE.SphereGeometry(0.05, 32, 32);
|
||||
var sphereMaterial = new THREE.MeshBasicMaterial({color: 0xbb0000, shading: THREE.FlatShading});
|
||||
spStart = new THREE.Mesh(sphereGeometry, sphereMaterial);
|
||||
spEnd = new THREE.Mesh(sphereGeometry, sphereMaterial);
|
||||
spStart.position.set(-1.1,1.05,2);
|
||||
spEnd.position.set(1.3,1.0,1.15);
|
||||
scene.add(spStart);
|
||||
scene.add(spEnd);
|
||||
|
||||
var lc = new THREE.Color( 0xff0000 );
|
||||
var lineGeometry = new THREE.Geometry();
|
||||
lineGeometry.vertices.push(spStart.position.clone(), spEnd.position.clone());
|
||||
lineGeometry.colors.push(lc, lc, lc);
|
||||
var lineMaterial = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
|
||||
sConnection = new THREE.Line(lineGeometry, lineMaterial);
|
||||
scene.add(sConnection);
|
||||
|
||||
// controls
|
||||
camera.position.set(5,5,2);
|
||||
controls = new THREE.OrbitControls(camera);
|
||||
controls.target.set( 0, 3, 0 );
|
||||
camera.lookAt(new THREE.Vector3(0,3,0));
|
||||
|
||||
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
|
||||
renderer.domElement.addEventListener( 'click', onClick, false );
|
||||
}
|
||||
|
||||
function createGrid(width, length, spacing){
|
||||
var material = new THREE.LineBasicMaterial({
|
||||
color: 0xBBBBBB
|
||||
});
|
||||
|
||||
var geometry = new THREE.Geometry();
|
||||
for(var i = 0; i <= length; i++){
|
||||
geometry.vertices.push(new THREE.Vector3(-(spacing*width)/2, 0, i*spacing-(spacing*length)/2));
|
||||
geometry.vertices.push(new THREE.Vector3(+(spacing*width)/2, 0, i*spacing-(spacing*length)/2));
|
||||
}
|
||||
|
||||
for(var i = 0; i <= width; i++){
|
||||
geometry.vertices.push(new THREE.Vector3(i*spacing-(spacing*width)/2, 0, -(spacing*length)/2));
|
||||
geometry.vertices.push(new THREE.Vector3(i*spacing-(spacing*width)/2, 0, +(spacing*length)/2));
|
||||
}
|
||||
|
||||
var line = new THREE.Line(geometry, material, THREE.LinePieces);
|
||||
line.receiveShadow = true;
|
||||
return line;
|
||||
}
|
||||
|
||||
function onDocumentMouseMove( event ) {
|
||||
event.preventDefault();
|
||||
|
||||
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
|
||||
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
|
||||
}
|
||||
|
||||
function render() {
|
||||
requestAnimationFrame(render);
|
||||
|
||||
camera.updateMatrixWorld(true);
|
||||
|
||||
vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
|
||||
projector.unprojectVector( vector, camera );
|
||||
raycaster.params = {"PointCloud" : {threshold: 0.1}};
|
||||
raycaster.ray.set( camera.position, vector.sub( camera.position ).normalize() );
|
||||
|
||||
scene.traverse( function ( object ) {
|
||||
if ( object instanceof Potree.PointCloudOctree ) {
|
||||
object.update( camera );
|
||||
}
|
||||
} );
|
||||
|
||||
if(placeStartMode || placeEndMode){
|
||||
var intersects = raycaster.intersectObject(pointcloud, true);
|
||||
|
||||
if(intersects.length > 0){
|
||||
var I = intersects[0];
|
||||
|
||||
if(placeStartMode){
|
||||
spStart.position = I.point;
|
||||
}else if(placeEndMode){
|
||||
spEnd.position = I.point;
|
||||
}
|
||||
sConnection.geometry.vertices[0].copy(spStart.position);
|
||||
sConnection.geometry.vertices[1].copy(spEnd.position);
|
||||
sConnection.geometry.verticesNeedUpdate = true;
|
||||
sConnection.geometry.computeBoundingSphere();
|
||||
}
|
||||
}
|
||||
|
||||
// placing distance label
|
||||
var labelPos = spStart.position.clone().add(spEnd.position).multiplyScalar(0.5);
|
||||
projector.projectVector(labelPos, camera);
|
||||
labelPos.x = (labelPos.x + 1)/2 * window.innerWidth;
|
||||
labelPos.y = -(labelPos.y - 1)/2 * window.innerHeight;
|
||||
|
||||
var distance = spStart.position.distanceTo(spEnd.position);
|
||||
var lblDistance = document.getElementById("lblDistance");
|
||||
lblDistance.style.left = labelPos.x;
|
||||
lblDistance.style.top = labelPos.y;
|
||||
lblDistance.innerHTML = distance.toFixed(2);
|
||||
|
||||
renderer.render(scene, camera);
|
||||
};
|
||||
|
||||
init();
|
||||
render();
|
||||
|
||||
function placeStart(){
|
||||
placeStartMode = true;
|
||||
placeEndMode = false;
|
||||
}
|
||||
|
||||
function placeEnd(){
|
||||
placeStartMode = false;
|
||||
placeEndMode = true;
|
||||
}
|
||||
|
||||
function onClick(){
|
||||
placeStartMode = false;
|
||||
placeEndMode = false;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<input type="button" value="place start"
|
||||
style="position:absolute; left: 10px; top: 10px; width: 100px; z-index: 100"
|
||||
onclick="placeStart()">
|
||||
<input type="button" value="place end"
|
||||
style="position:absolute; left: 10px; top: 40px; width: 100px; z-index: 100"
|
||||
onclick="placeEnd()">
|
||||
|
||||
<div id="lblDistance" style="position: absolute; width: 20px; z-index: 100;">abc</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>Potree.js Examples</title>
|
||||
<meta name="description" content="Potree.js Examples">
|
||||
<meta name="author" content="Potree.org">
|
||||
|
||||
<!--[if lt IE 9]>
|
||||
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Potree.js Examples</h1>
|
||||
<!-- build:toc -->
|
||||
<!-- endbuild -->
|
||||
|
||||
<p><a href="docs/doc.html">Documentation</a></p>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,85 +1,131 @@
|
||||
|
||||
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="../resources/css/potree.css" />
|
||||
<script type="text/javascript" src="../src/Potree.js"></script>
|
||||
<script type="text/javascript" >Potree.importScripts("..");</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function DemoKeyListener(material){
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
DemoKeyListener.prototype.invokeKeyPress = function(event){
|
||||
if(event.keyCode == KeyCodes.NUMBER_1){
|
||||
this.material.renderMode = PointCloudRenderMode.WEIGHTED_CIRCLE;
|
||||
}else if(event.keyCode == KeyCodes.NUMBER_2){
|
||||
this.material.renderMode = PointCloudRenderMode.FILTERED_SPLAT;
|
||||
}
|
||||
}
|
||||
DemoKeyListener.prototype.invokeKeyDown = function(){}
|
||||
DemoKeyListener.prototype.invokeKeyUp = function(){}
|
||||
|
||||
function init() {
|
||||
|
||||
// init potree
|
||||
var canvas = document.getElementById("canvas");
|
||||
Potree.shaderDir = "../resources/shader";
|
||||
var success = Potree.init(canvas);
|
||||
if(!success){
|
||||
return;
|
||||
}
|
||||
|
||||
// load point cloud
|
||||
var scene = Potree.currentScene;
|
||||
var cloudURL = "../resources/pointclouds/lion_takanawa/cloud.js";
|
||||
var pcoNode = POCLoader.load(cloudURL);
|
||||
scene.rootNode.addChild(pcoNode);
|
||||
|
||||
// mirror point cloud along a-axis
|
||||
pcoNode.transform = [1, 0, 0, 0,
|
||||
0, -1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1];
|
||||
|
||||
// transform camera
|
||||
var pivot = V3.$(-9,-1,-1.5);
|
||||
var cam = scene.activeCamera;
|
||||
cam.translate(pivot.x, pivot.y, pivot.z);
|
||||
cam.translate(0,0,8);
|
||||
cam.rotateAroundPivot(2, -0.3,pivot);
|
||||
|
||||
// OrbitCamHandler rotates the camera around a pivot point
|
||||
Potree.camHandler = new OrbitCamHandler(cam);
|
||||
Potree.camHandler.pivot = pivot;
|
||||
|
||||
// set point size
|
||||
var material = MaterialManager.getMaterial("pointCloud");
|
||||
material.pointSize = 1;
|
||||
|
||||
// set Level of Detail
|
||||
Potree.Settings.LODMultiplicator = 20.0;
|
||||
|
||||
KeyListener.addListener(new DemoKeyListener(material));
|
||||
canvas.focus();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<title>lion</title>
|
||||
<style>canvas { width: 100%; height: 100% }</style>
|
||||
</head>
|
||||
<body onload="init()" class="claro" style="font-size: 62.5%;">
|
||||
<body style="margin: 0; padding: 0">
|
||||
<script src="../libs/three.js/build/three.js"></script>
|
||||
<script src="../libs/other/OrbitControls.js"></script>
|
||||
<script src="../src/Potree.js"></script>
|
||||
<script src="../src/PointCloudOctree.js"></script>
|
||||
<script src="../src/PointCloudOctreeGeometry.js"></script>
|
||||
<script src="../src/loader/POCLoader.js"></script>
|
||||
<script src="../src/loader/PointAttributes.js"></script>
|
||||
<script src="../src/utils.js"></script>
|
||||
<script src="../src/LRU.js"></script>
|
||||
<script>
|
||||
var renderer;
|
||||
var camera;
|
||||
var cube;
|
||||
var scene;
|
||||
var octreeNodesVisible = 0;
|
||||
var pointsVisible = 0;
|
||||
var pointCloud;
|
||||
var pointClouds = [];
|
||||
|
||||
function initThree(){
|
||||
scene = new THREE.Scene();
|
||||
camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
|
||||
|
||||
<div id="workarea" style="width: 100%; height: 100%">
|
||||
<canvas id="canvas" width="800" height="600" tabIndex="1">
|
||||
Your Browser does not support WebGL. Try the newest version of Firefox or Google Chrome.
|
||||
</canvas>
|
||||
</div>
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
document.body.appendChild(renderer.domElement);
|
||||
|
||||
camera.position.z = 6;
|
||||
camera.position.y = 4;
|
||||
camera.position.x = 4;
|
||||
|
||||
var pointLight = new THREE.PointLight(0xffffff);
|
||||
pointLight.position.set(10, 10, 10);
|
||||
scene.add(pointLight);
|
||||
|
||||
var ambientLight = new THREE.AmbientLight(0x111111);
|
||||
scene.add(ambientLight);
|
||||
|
||||
controls = new THREE.OrbitControls(camera);
|
||||
controls.target.set( 0, 3, 0 );
|
||||
camera.lookAt(new THREE.Vector3(0,3,0));
|
||||
|
||||
var material = new THREE.PointCloudMaterial( { size: 0.02, vertexColors: true } );
|
||||
var pco = POCLoader.load("../resources/pointclouds/lion_takanawa/cloud.js");
|
||||
|
||||
pointCloud = new Potree.PointCloudOctree(pco, material);
|
||||
pointCloud.LODDistance = 80;
|
||||
pointCloud.rotation.x = Math.PI;
|
||||
pointCloud.position.x = 8;
|
||||
pointCloud.position.z = -2;
|
||||
pointCloud.position.y = 4;
|
||||
scene.add(pointCloud);
|
||||
|
||||
scene.add(createGrid(8,8,1));
|
||||
}
|
||||
|
||||
function onDocumentMouseMove( event ) {
|
||||
event.preventDefault();
|
||||
|
||||
<div id="infos" style="top: 0; bottom: 0; left: 10; right: 0; position: absolute; z-index: 100; font-size: 150%; background: #fff; top: 10px; width: 300px; height: 70px; padding: 10px 10px 15px 10px; border-radius: 4px">
|
||||
Hold the left mouse button to rotate around the object. Use the scroll wheel to zoom in and out.<br>
|
||||
1: default rendermode<br>
|
||||
2: filtered splats (slow)
|
||||
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
|
||||
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
|
||||
}
|
||||
|
||||
function createGrid(width, length, spacing){
|
||||
var material = new THREE.LineBasicMaterial({
|
||||
color: 0xBBBBBB
|
||||
});
|
||||
|
||||
var geometry = new THREE.Geometry();
|
||||
for(var i = 0; i <= length; i++){
|
||||
geometry.vertices.push(new THREE.Vector3(-(spacing*width)/2, 0, i*spacing-(spacing*length)/2));
|
||||
geometry.vertices.push(new THREE.Vector3(+(spacing*width)/2, 0, i*spacing-(spacing*length)/2));
|
||||
}
|
||||
|
||||
for(var i = 0; i <= width; i++){
|
||||
geometry.vertices.push(new THREE.Vector3(i*spacing-(spacing*width)/2, 0, -(spacing*length)/2));
|
||||
geometry.vertices.push(new THREE.Vector3(i*spacing-(spacing*width)/2, 0, +(spacing*length)/2));
|
||||
}
|
||||
|
||||
var line = new THREE.Line(geometry, material, THREE.LinePieces);
|
||||
line.receiveShadow = true;
|
||||
return line;
|
||||
}
|
||||
|
||||
|
||||
var toggle = 0;
|
||||
function render() {
|
||||
requestAnimationFrame(render);
|
||||
|
||||
octreeNodesVisible = 0;
|
||||
pointsVisible = 0;
|
||||
scene.traverse( function ( object ) {
|
||||
if ( object instanceof Potree.PointCloudOctree ) {
|
||||
object.update( camera );
|
||||
}else if(object instanceof THREE.PointCloud){
|
||||
if(object.visible){
|
||||
octreeNodesVisible++;
|
||||
pointsVisible += object.numPoints;
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
renderer.render(scene, camera);
|
||||
|
||||
document.getElementById("lblNumVisibleNodes").innerHTML = "visible nodes: " + octreeNodesVisible;
|
||||
document.getElementById("lblNumVisiblePoints").innerHTML = "visible points: " + pointsVisible;
|
||||
};
|
||||
|
||||
initThree();
|
||||
render();
|
||||
|
||||
</script>
|
||||
|
||||
<div id="lblNumVisibleNodes" style="position: absolute; left: 10px; top: 20px; width: 400px; color:white"></div>
|
||||
<div id="lblNumVisiblePoints" style="position: absolute; left: 10px; top: 40px; width: 400px; color:white"></div>
|
||||
<div id="lblControl" style="position:absolute; left: 10px; top: 80px; width: 400px; color: white">
|
||||
Orbit Controls:<br>
|
||||
left mouse button: rotate object<br>
|
||||
right mouse button: pan the screen<br>
|
||||
scrool wheel: zoom in and out
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
128
examples/point_picking.html
Normal file
@ -0,0 +1,128 @@
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<script src="../libs/three.js/build/three.js"></script>
|
||||
<script src="../libs/other/OrbitControls.js"></script>
|
||||
<script src="../src/Potree.js"></script>
|
||||
<script src="../src/PointCloudOctree.js"></script>
|
||||
<script src="../src/loader/POCLoader.js"></script>
|
||||
<script src="../src/loader/PointAttributes.js"></script>
|
||||
<script src="../src/utils.js"></script>
|
||||
|
||||
</head>
|
||||
<body style="margin: 0px; padding: 0px;">
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var renderer;
|
||||
var camera;
|
||||
var scene;
|
||||
var pickLocation;
|
||||
var mouse = { x: 1, y: 1 };
|
||||
var projector, raycaster;
|
||||
|
||||
function generatePointcloud(){
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
var width = 200;
|
||||
var length = 200;
|
||||
var numPoints = width*length;
|
||||
|
||||
var positions = new Float32Array(numPoints*3);
|
||||
var colors = new Float32Array(numPoints*3);
|
||||
|
||||
var color = new THREE.Color();
|
||||
var k = 0;
|
||||
for(var i = 0; i < width; i++){
|
||||
for(var j = 0; j < length; j++){
|
||||
var u = i/width;
|
||||
var v = j/length;
|
||||
var x = 10*u - 5;
|
||||
var y = (Math.cos(u*Math.PI*8) + Math.sin(v*Math.PI*8))/2;
|
||||
var z = 10*v - 5;
|
||||
|
||||
positions[3*k] = x;
|
||||
positions[3*k+1] = y;
|
||||
positions[3*k+2] = z;
|
||||
|
||||
var intensity = y+1;
|
||||
color.setRGB(u*intensity, v*intensity, 0);
|
||||
colors[3*k] = color.r;
|
||||
colors[3*k+1] = color.g;
|
||||
colors[3*k+2] = color.b;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
geometry.addAttribute('position', new THREE.Float32Attribute(positions, 3));
|
||||
geometry.addAttribute('color', new THREE.Float32Attribute(colors, 3));
|
||||
|
||||
var material = new THREE.PointCloudMaterial({ size: 0.01, vertexColors: true });
|
||||
var pointcloud = new THREE.PointCloud(geometry, material);
|
||||
|
||||
return pointcloud;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function init() {
|
||||
scene = new THREE.Scene();
|
||||
camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
|
||||
|
||||
projector = new THREE.Projector();
|
||||
raycaster = new THREE.Raycaster();
|
||||
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
document.body.appendChild(renderer.domElement);
|
||||
|
||||
pointcloud = generatePointcloud();
|
||||
scene.add(pointcloud);
|
||||
|
||||
var sphereGeometry = new THREE.SphereGeometry(0.1, 32, 32);
|
||||
var sphereMaterial = new THREE.MeshBasicMaterial({color: 0xff0000, shading: THREE.FlatShading});
|
||||
pickLocation = new THREE.Mesh(sphereGeometry, sphereMaterial);
|
||||
scene.add(pickLocation);
|
||||
|
||||
// controls
|
||||
camera.position.set(5,5,2);
|
||||
controls = new THREE.OrbitControls(camera);
|
||||
controls.target.set( 0, 0, 0 );
|
||||
camera.lookAt(new THREE.Vector3(0,0,0));
|
||||
|
||||
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
|
||||
}
|
||||
|
||||
function onDocumentMouseMove( event ) {
|
||||
event.preventDefault();
|
||||
|
||||
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
|
||||
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
|
||||
}
|
||||
|
||||
function render() {
|
||||
requestAnimationFrame(render);
|
||||
|
||||
camera.updateMatrixWorld(true);
|
||||
|
||||
vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
|
||||
projector.unprojectVector( vector, camera );
|
||||
raycaster.params = {"PointCloud" : {threshold: 0.1}};
|
||||
raycaster.ray.set( camera.position, vector.sub( camera.position ).normalize() );
|
||||
|
||||
var intersects = raycaster.intersectObject(pointcloud);
|
||||
if(intersects.length > 0){
|
||||
var I = intersects[0];
|
||||
pickLocation.position = I.point;
|
||||
}
|
||||
|
||||
renderer.render(scene, camera);
|
||||
};
|
||||
|
||||
init();
|
||||
render();
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -1,104 +1,95 @@
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="../resources/css/potree.css" />
|
||||
<script type="text/javascript" src="../src/Potree.js"></script>
|
||||
<script type="text/javascript" >Potree.importScripts("..");</script>
|
||||
<script src="../libs/three.js/build/three.js"></script>
|
||||
<script src="../libs/other/OrbitControls.js"></script>
|
||||
<script src="../src/Potree.js"></script>
|
||||
<script src="../src/PointCloudOctree.js"></script>
|
||||
<script src="../src/loader/POCLoader.js"></script>
|
||||
<script src="../src/loader/PointAttributes.js"></script>
|
||||
<script src="../src/utils.js"></script>
|
||||
|
||||
</head>
|
||||
<body style="margin: 0px; padding: 0px;">
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function generatePointCloud(){
|
||||
var uStart = -Math.PI;
|
||||
var uEnd = Math.PI;
|
||||
var uSteps = 150;
|
||||
var vStart = -Math.PI;
|
||||
var vEnd = Math.PI;
|
||||
var vSteps = 150;
|
||||
var numPoints = uSteps * vSteps;
|
||||
var renderer;
|
||||
var camera;
|
||||
var scene;
|
||||
|
||||
function generatePointcloud(){
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
var width = 200;
|
||||
var length = 200;
|
||||
var numPoints = width*length;
|
||||
|
||||
var buffer = new ArrayBuffer(numPoints*16);
|
||||
var floatView = new Float32Array(buffer);
|
||||
var byteView = new Uint8Array(buffer);
|
||||
var pointAttributes = new PointAttributes();
|
||||
pointAttributes.add(PointAttribute.POSITION_CARTESIAN);
|
||||
pointAttributes.add(PointAttribute.RGBA_PACKED);
|
||||
var positions = new Float32Array(numPoints*3);
|
||||
var colors = new Float32Array(numPoints*3);
|
||||
|
||||
var offset = 0;
|
||||
for(var i = 0; i < uSteps; i++){
|
||||
for(var j = 0; j < vSteps; j++){
|
||||
var u = uStart + (uEnd - uStart) * (i/uSteps);
|
||||
var v = vStart + (vEnd - vStart) * (j/vSteps);
|
||||
var color = new THREE.Color();
|
||||
var k = 0;
|
||||
for(var i = 0; i < width; i++){
|
||||
for(var j = 0; j < length; j++){
|
||||
var u = i/width;
|
||||
var v = j/length;
|
||||
var x = 10*u - 5;
|
||||
var y = (Math.cos(u*Math.PI*8) + Math.sin(v*Math.PI*8))/2;
|
||||
var z = 10*v - 5;
|
||||
|
||||
var x = u;
|
||||
var y = Math.cos(2*v) * Math.sin(2*u);
|
||||
var z = v;
|
||||
positions[3*k] = x;
|
||||
positions[3*k+1] = y;
|
||||
positions[3*k+2] = z;
|
||||
|
||||
var p = (v - vStart) / (vEnd-vStart);
|
||||
var q = (u - uStart) / (uEnd-uStart);
|
||||
var r = 255*p * (y+1.3)/2.3;
|
||||
var g = 255*q * (y+1.3)/2.3;
|
||||
var b = 0;
|
||||
|
||||
floatView[4*offset+0] = x;
|
||||
floatView[4*offset+1] = y;
|
||||
floatView[4*offset+2] = z;
|
||||
byteView[16*offset+12] = r;
|
||||
byteView[16*offset+13] = g;
|
||||
byteView[16*offset+14] = b;
|
||||
byteView[16*offset+15] = 255;
|
||||
offset++;
|
||||
var intensity = y+1;
|
||||
color.setRGB(u*intensity, v*intensity, 0);
|
||||
colors[3*k] = color.r;
|
||||
colors[3*k+1] = color.g;
|
||||
colors[3*k+2] = color.b;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
var pointCloud = new PointCloud("cloud", pointAttributes);
|
||||
pointCloud.setVertexBufferData(buffer);
|
||||
pointCloud.size = numPoints;
|
||||
|
||||
return pointCloud;
|
||||
geometry.addAttribute('position', new THREE.Float32Attribute(positions, 3));
|
||||
geometry.addAttribute('color', new THREE.Float32Attribute(colors, 3));
|
||||
|
||||
var material = new THREE.PointCloudMaterial({ size: 0.01, vertexColors: true });
|
||||
var pointcloud = new THREE.PointCloud(geometry, material);
|
||||
|
||||
return pointcloud;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function init() {
|
||||
|
||||
// init potree
|
||||
var canvas = document.getElementById("canvas");
|
||||
Potree.shaderDir = "../resources/shader";
|
||||
var success = Potree.init(canvas);
|
||||
if(!success){
|
||||
return;
|
||||
}
|
||||
|
||||
// load point cloud
|
||||
var scene = Potree.currentScene;
|
||||
var pointcloud = generatePointCloud();
|
||||
var pcoNode = new PointCloudSceneNode("pointcloud", scene.rootNode, pointcloud);
|
||||
pcoNode.scale(0.6, 0.6, 0.6);
|
||||
|
||||
// transform camera
|
||||
var cam = scene.activeCamera;
|
||||
cam.translate(0,-0.2,4);
|
||||
cam.rotateX(-0.7);
|
||||
cam.rotateY(0.8);
|
||||
|
||||
|
||||
// set point size
|
||||
var material = MaterialManager.getMaterial("pointCloud");
|
||||
material.pointSize = 2;
|
||||
scene = new THREE.Scene();
|
||||
camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
|
||||
|
||||
canvas.focus();
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
document.body.appendChild(renderer.domElement);
|
||||
|
||||
pointcloud = generatePointcloud();
|
||||
scene.add(pointcloud);
|
||||
|
||||
// controls
|
||||
camera.position.set(5,5,2);
|
||||
controls = new THREE.OrbitControls(camera);
|
||||
controls.target.set( 0, 0, 0 );
|
||||
camera.lookAt(new THREE.Vector3(0,0,0));
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body onload="init()" class="claro" style="font-size: 62.5%;">
|
||||
function render() {
|
||||
requestAnimationFrame(render);
|
||||
|
||||
<div id="workarea" style="width: 100%; height: 100%">
|
||||
<canvas id="canvas" width="800" height="600" tabIndex="1">
|
||||
Your Browser does not support WebGL. Try the newest version of Firefox or Google Chrome.
|
||||
</canvas>
|
||||
</div>
|
||||
|
||||
renderer.render(scene, camera);
|
||||
};
|
||||
|
||||
init();
|
||||
render();
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -1,109 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="../resources/css/potree.css" />
|
||||
<script type="text/javascript" src="../src/Potree.js"></script>
|
||||
<script type="text/javascript" >Potree.importScripts("..");</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function generatePointCloud(){
|
||||
var uStart = 0;
|
||||
var uEnd = 2*Math.PI;
|
||||
var uSteps = 100;
|
||||
var vStart = -15;
|
||||
var vEnd = 6;
|
||||
var vSteps = 300;
|
||||
var numPoints = uSteps * vSteps;
|
||||
|
||||
var buffer = new ArrayBuffer(numPoints*16);
|
||||
var floatView = new Float32Array(buffer);
|
||||
var byteView = new Uint8Array(buffer);
|
||||
var pointAttributes = new PointAttributes();
|
||||
pointAttributes.add(PointAttribute.POSITION_CARTESIAN);
|
||||
pointAttributes.add(PointAttribute.RGBA_PACKED);
|
||||
|
||||
var offset = 0;
|
||||
for(var i = 0; i < uSteps; i++){
|
||||
for(var j = 0; j < vSteps; j++){
|
||||
var u = uStart + (uEnd - uStart) * (i/uSteps);
|
||||
var v = vStart + (vEnd - vStart) * (j/vSteps);
|
||||
|
||||
var x = Math.pow(1.16,v) * Math.cos(v) * (1 + Math.cos(u));
|
||||
var y = -Math.pow(1.16,v) * Math.sin(v) * (1 + Math.cos(u));
|
||||
var z = -2*Math.pow(1.16,v) * (1 + Math.sin(u));
|
||||
|
||||
var p = (v - vStart) / (vEnd-vStart);
|
||||
var q = (u - uStart) / (uEnd-uStart);
|
||||
var r = (q + 0.5)*255;
|
||||
var g = 0;
|
||||
var b = p*255;
|
||||
|
||||
floatView[4*offset+0] = x;
|
||||
floatView[4*offset+1] = y;
|
||||
floatView[4*offset+2] = z;
|
||||
byteView[16*offset+12] = r;
|
||||
byteView[16*offset+13] = g;
|
||||
byteView[16*offset+14] = b;
|
||||
byteView[16*offset+15] = 255;
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(floatView);
|
||||
|
||||
var pointCloud = new PointCloud("cloud", pointAttributes);
|
||||
pointCloud.setVertexBufferData(buffer);
|
||||
pointCloud.size = numPoints;
|
||||
|
||||
return pointCloud;
|
||||
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
// init potree
|
||||
var canvas = document.getElementById("canvas");
|
||||
Potree.shaderDir = "../resources/shader";
|
||||
var success = Potree.init(canvas);
|
||||
if(!success){
|
||||
return;
|
||||
}
|
||||
|
||||
// load point cloud
|
||||
var scene = Potree.currentScene;
|
||||
var pointcloud = generatePointCloud();
|
||||
var pcoNode = new PointCloudSceneNode("pointcloud", scene.rootNode, pointcloud);
|
||||
pcoNode.scale(0.2, 0.2, 0.2);
|
||||
|
||||
// transform camera
|
||||
var pivot = V3.$(0,0,-0.5);
|
||||
var cam = scene.activeCamera;
|
||||
cam.translate(0,0,2);
|
||||
cam.rotateAroundPivot(1,-0.5, pivot);
|
||||
|
||||
// OrbitCamHandler rotates the camera around a pivot point
|
||||
Potree.camHandler = new OrbitCamHandler(cam);
|
||||
Potree.camHandler.pivot = pivot;
|
||||
|
||||
// set point size
|
||||
var material = MaterialManager.getMaterial("pointCloud");
|
||||
material.pointSize = 0.5;
|
||||
|
||||
canvas.focus();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body onload="init()" class="claro" style="font-size: 62.5%;">
|
||||
|
||||
<div id="workarea" style="width: 100%; height: 100%">
|
||||
<canvas id="canvas" width="800" height="600" tabIndex="1">
|
||||
Your Browser does not support WebGL. Try the newest version of Firefox or Google Chrome.
|
||||
</canvas>
|
||||
</div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -1,105 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="../resources/css/potree.css" />
|
||||
<script type="text/javascript" src="../src/Potree.js"></script>
|
||||
<script type="text/javascript" >Potree.importScripts("..");</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function generatePointCloud(){
|
||||
var uStart = -Math.PI;
|
||||
var uEnd = Math.PI;
|
||||
var uSteps = 500;
|
||||
var vStart = -Math.PI;
|
||||
var vEnd = Math.PI;
|
||||
var vSteps = 40;
|
||||
var numPoints = uSteps * vSteps;
|
||||
|
||||
var buffer = new ArrayBuffer(numPoints*16);
|
||||
var floatView = new Float32Array(buffer);
|
||||
var byteView = new Uint8Array(buffer);
|
||||
var pointAttributes = new PointAttributes();
|
||||
pointAttributes.add(PointAttribute.POSITION_CARTESIAN);
|
||||
pointAttributes.add(PointAttribute.RGBA_PACKED);
|
||||
|
||||
var offset = 0;
|
||||
for(var i = 0; i < uSteps; i++){
|
||||
for(var j = 0; j < vSteps; j++){
|
||||
var u = uStart + (uEnd - uStart) * (i/uSteps);
|
||||
var v = vStart + (vEnd - vStart) * (j/vSteps);
|
||||
|
||||
var x = Math.sin(u)*Math.sin(v);
|
||||
var y = Math.cos(u)*Math.sin(v);
|
||||
var z = Math.cos(v);
|
||||
|
||||
var p = (v - vStart) / (vEnd-vStart);
|
||||
var q = (u - uStart) / (uEnd-uStart);
|
||||
var r = 255*(x+1)/2;
|
||||
var g = 150*(y+1)/2;
|
||||
var b = 0;
|
||||
|
||||
|
||||
floatView[4*offset+0] = x;
|
||||
floatView[4*offset+1] = y;
|
||||
floatView[4*offset+2] = z;
|
||||
byteView[16*offset+12] = r;
|
||||
byteView[16*offset+13] = g;
|
||||
byteView[16*offset+14] = b;
|
||||
byteView[16*offset+15] = 255;
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(floatView);
|
||||
|
||||
var pointCloud = new PointCloud("cloud", pointAttributes);
|
||||
pointCloud.setVertexBufferData(buffer);
|
||||
pointCloud.size = numPoints;
|
||||
|
||||
return pointCloud;
|
||||
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
// init potree
|
||||
var canvas = document.getElementById("canvas");
|
||||
Potree.shaderDir = "../resources/shader";
|
||||
var success = Potree.init(canvas);
|
||||
if(!success){
|
||||
return;
|
||||
}
|
||||
|
||||
// load point cloud
|
||||
var scene = Potree.currentScene;
|
||||
var pointcloud = generatePointCloud();
|
||||
var pcoNode = new PointCloudSceneNode("pointcloud", scene.rootNode, pointcloud);
|
||||
pcoNode.scale(0.6, 0.6, 0.6);
|
||||
|
||||
// transform camera
|
||||
var cam = scene.activeCamera;
|
||||
cam.translate(0,0.1,2);
|
||||
cam.rotateY(0.8);
|
||||
|
||||
// set point size
|
||||
var material = MaterialManager.getMaterial("pointCloud");
|
||||
material.pointSize = 0.4;
|
||||
|
||||
canvas.focus();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body onload="init()" class="claro" style="font-size: 62.5%;">
|
||||
|
||||
<div id="workarea" style="width: 100%; height: 100%">
|
||||
<canvas id="canvas" width="800" height="600" tabIndex="1">
|
||||
Your Browser does not support WebGL. Try the newest version of Firefox or Google Chrome.
|
||||
</canvas>
|
||||
</div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
152
examples/skybox.html
Normal file
@ -0,0 +1,152 @@
|
||||
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Skybox</title>
|
||||
<style>canvas { width: 100%; height: 100% }</style>
|
||||
</head>
|
||||
<body style="margin: 0; padding: 0">
|
||||
<script src="../libs/three.js/build/three.js"></script>
|
||||
<script src="../libs/other/OrbitControls.js"></script>
|
||||
<script src="../src/Potree.js"></script>
|
||||
<script src="../src/PointCloudOctree.js"></script>
|
||||
<script src="../src/PointCloudOctreeGeometry.js"></script>
|
||||
<script src="../src/loader/POCLoader.js"></script>
|
||||
<script src="../src/loader/PointAttributes.js"></script>
|
||||
<script src="../src/utils.js"></script>
|
||||
<script src="../src/LRU.js"></script>
|
||||
<script>
|
||||
var renderer;
|
||||
var camera;
|
||||
var cube;
|
||||
var scene;
|
||||
var pointCloud;
|
||||
var cameraCube, sceneCube;
|
||||
|
||||
/**
|
||||
* see three.js cubemap examples
|
||||
*/
|
||||
function loadSkybox(){
|
||||
cameraCube = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 100000 );
|
||||
sceneCube = new THREE.Scene();
|
||||
|
||||
var path = "../resources/textures/skybox/";
|
||||
var format = ".jpg";
|
||||
var urls = [
|
||||
path + 'px' + format, path + 'nx' + format,
|
||||
path + 'py' + format, path + 'ny' + format,
|
||||
path + 'pz' + format, path + 'nz' + format
|
||||
];
|
||||
|
||||
var textureCube = THREE.ImageUtils.loadTextureCube( urls, new THREE.CubeRefractionMapping() );
|
||||
var material = new THREE.MeshBasicMaterial( { color: 0xffffff, envMap: textureCube, refractionRatio: 0.95 } );
|
||||
|
||||
var shader = THREE.ShaderLib[ "cube" ];
|
||||
shader.uniforms[ "tCube" ].value = textureCube;
|
||||
|
||||
var material = new THREE.ShaderMaterial( {
|
||||
|
||||
fragmentShader: shader.fragmentShader,
|
||||
vertexShader: shader.vertexShader,
|
||||
uniforms: shader.uniforms,
|
||||
depthWrite: false,
|
||||
side: THREE.BackSide
|
||||
|
||||
} ),
|
||||
|
||||
mesh = new THREE.Mesh( new THREE.BoxGeometry( 100, 100, 100 ), material );
|
||||
sceneCube.add( mesh );
|
||||
}
|
||||
|
||||
function initThree(){
|
||||
scene = new THREE.Scene();
|
||||
camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 100000);
|
||||
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
renderer.autoClear = false;
|
||||
document.body.appendChild(renderer.domElement);
|
||||
|
||||
loadSkybox();
|
||||
|
||||
camera.position.z = 5;
|
||||
camera.position.y = 5;
|
||||
camera.position.x = -6;
|
||||
|
||||
var pointLight = new THREE.PointLight(0xffffff);
|
||||
pointLight.position.set(10, 10, 10);
|
||||
scene.add(pointLight);
|
||||
|
||||
var ambientLight = new THREE.AmbientLight(0x111111);
|
||||
scene.add(ambientLight);
|
||||
|
||||
controls = new THREE.OrbitControls(camera);
|
||||
controls.target.set( 0, 3, 0 );
|
||||
camera.lookAt(new THREE.Vector3(0,3,0));
|
||||
|
||||
var material = new THREE.PointCloudMaterial( { size: 0.05, vertexColors: true } );
|
||||
var pco = POCLoader.load("../resources/pointclouds/lion_takanawa/cloud.js");
|
||||
|
||||
var pointCloud = new Potree.PointCloudOctree(pco, material);
|
||||
pointCloud.LODDistance = 80;
|
||||
pointCloud.rotation.x = Math.PI;
|
||||
pointCloud.rotation.y = 2;
|
||||
pointCloud.position.x = -2;
|
||||
pointCloud.position.z = 8;
|
||||
pointCloud.position.y = 4;
|
||||
scene.add(pointCloud);
|
||||
|
||||
scene.add(createGrid(8,8,1));
|
||||
}
|
||||
|
||||
function createGrid(width, length, spacing){
|
||||
var material = new THREE.LineBasicMaterial({
|
||||
color: 0x666666
|
||||
});
|
||||
|
||||
var geometry = new THREE.Geometry();
|
||||
for(var i = 0; i <= length; i++){
|
||||
geometry.vertices.push(new THREE.Vector3(-(spacing*width)/2, 0, i*spacing-(spacing*length)/2));
|
||||
geometry.vertices.push(new THREE.Vector3(+(spacing*width)/2, 0, i*spacing-(spacing*length)/2));
|
||||
}
|
||||
|
||||
for(var i = 0; i <= width; i++){
|
||||
geometry.vertices.push(new THREE.Vector3(i*spacing-(spacing*width)/2, 0, -(spacing*length)/2));
|
||||
geometry.vertices.push(new THREE.Vector3(i*spacing-(spacing*width)/2, 0, +(spacing*length)/2));
|
||||
}
|
||||
|
||||
var line = new THREE.Line(geometry, material, THREE.LinePieces);
|
||||
line.receiveShadow = true;
|
||||
return line;
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
requestAnimationFrame(render);
|
||||
|
||||
scene.traverse( function ( object ) {
|
||||
if ( object instanceof Potree.PointCloudOctree ) {
|
||||
object.update( camera );
|
||||
}
|
||||
} );
|
||||
|
||||
cameraCube.rotation.copy( camera.rotation );
|
||||
renderer.render( sceneCube, cameraCube );
|
||||
renderer.render(scene, camera);
|
||||
|
||||
};
|
||||
|
||||
initThree();
|
||||
render();
|
||||
|
||||
</script>
|
||||
|
||||
<div id="lblControl" style="position:absolute; left: 10px; top: 10px; width: 400px; color: black">
|
||||
Orbit Controls:<br>
|
||||
left mouse button: rotate object<br>
|
||||
right mouse button: pan the screen<br>
|
||||
scrool wheel: zoom in and out
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -1,96 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="../resources/css/potree.css" />
|
||||
<script type="text/javascript" src="../src/Potree.js"></script>
|
||||
<script type="text/javascript" >Potree.importScripts("..");</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function generatePointCloud(){
|
||||
var width = 100;
|
||||
var depth = 100;
|
||||
var numPoints = width*depth;
|
||||
|
||||
var buffer = new ArrayBuffer(numPoints*16);
|
||||
var floatView = new Float32Array(buffer);
|
||||
var byteView = new Uint8Array(buffer);
|
||||
var pointAttributes = new PointAttributes();
|
||||
pointAttributes.add(PointAttribute.POSITION_CARTESIAN);
|
||||
pointAttributes.add(PointAttribute.RGBA_PACKED);
|
||||
|
||||
|
||||
var offset = 0;
|
||||
for(var i = 0; i < width; i++){
|
||||
for(var j = 0; j < depth; j++){
|
||||
var x = 10*((i / width)-0.5);
|
||||
var z = 10*((j / depth)-0.5);
|
||||
var y = Math.cos(x) * Math.sin(z);
|
||||
|
||||
var r = 100*(y+1);
|
||||
var g = 0;
|
||||
var b = 0;
|
||||
|
||||
floatView[4*offset+0] = x;
|
||||
floatView[4*offset+1] = y;
|
||||
floatView[4*offset+2] = z;
|
||||
byteView[16*offset+12] = r;
|
||||
byteView[16*offset+13] = g;
|
||||
byteView[16*offset+14] = b;
|
||||
byteView[16*offset+15] = 255;
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
var pointCloud = new PointCloud("cloud", pointAttributes);
|
||||
pointCloud.setVertexBufferData(buffer);
|
||||
pointCloud.size = numPoints;
|
||||
|
||||
return pointCloud;
|
||||
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
// init potree
|
||||
var canvas = document.getElementById("canvas");
|
||||
Potree.shaderDir = "../resources/shader";
|
||||
var success = Potree.init(canvas);
|
||||
if(!success){
|
||||
return;
|
||||
}
|
||||
|
||||
// load point cloud
|
||||
var scene = Potree.currentScene;
|
||||
var pointcloud = generatePointCloud();
|
||||
var pcoNode = new PointCloudSceneNode("pointcloud", scene.rootNode, pointcloud);
|
||||
pcoNode.scale(0.6, 0.6, 0.6);
|
||||
|
||||
// transform camera
|
||||
var cam = scene.activeCamera;
|
||||
cam.translate(0,-0.2,4);
|
||||
cam.rotateX(-0.7);
|
||||
cam.rotateY(0.8);
|
||||
|
||||
|
||||
// set point size
|
||||
var material = MaterialManager.getMaterial("pointCloud");
|
||||
material.pointSize = 2;
|
||||
|
||||
canvas.focus();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body onload="init()" class="claro" style="font-size: 62.5%;">
|
||||
|
||||
<div id="workarea" style="width: 100%; height: 100%">
|
||||
<canvas id="canvas" width="800" height="600" tabIndex="1">
|
||||
Your Browser does not support WebGL. Try the newest version of Firefox or Google Chrome.
|
||||
</canvas>
|
||||
</div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
174
gulpfile.js
@ -1,174 +0,0 @@
|
||||
/**
|
||||
* gulp.js to build the library
|
||||
*/
|
||||
var path = require('path');
|
||||
var gulp = require('gulp');
|
||||
var gutil = require('gulp-util');
|
||||
|
||||
var tap = require('gulp-tap');
|
||||
var size = require('gulp-size');
|
||||
var clean = require('gulp-clean');
|
||||
var serve = require('gulp-serve');
|
||||
var mdown = require('gulp-markdown');
|
||||
var concat = require('gulp-concat');
|
||||
var uglify = require('gulp-uglify');
|
||||
var jshint = require('gulp-jshint');
|
||||
var rename = require('gulp-rename');
|
||||
var minify = require('gulp-minify-css');
|
||||
var htmlreplace = require('gulp-html-replace');
|
||||
|
||||
var paths = {
|
||||
mjs: [
|
||||
"./libs/mjs/mjs.js"
|
||||
],
|
||||
potree: [
|
||||
"./src/License.js",
|
||||
"./src/extensions/Array.js",
|
||||
"./src/extensions/mjs.js",
|
||||
"./src/extensions/String.js",
|
||||
"./src/extensions/ArrayBuffer.js",
|
||||
"./src/extensions/Float32Array.js",
|
||||
"./src/utils/utils.js",
|
||||
"./src/KeyListener.js",
|
||||
"./src/KeyCodes.js",
|
||||
"./src/MouseListener.js",
|
||||
"./src/Mouse.js",
|
||||
"./src/ResourceManager/TextureManager.js",
|
||||
"./src/ResourceManager/MaterialManager.js",
|
||||
"./src/shader/Shader.js",
|
||||
"./src/utils/Plane.js",
|
||||
"./src/utils/Frustum.js",
|
||||
"./src/rendering/Renderer.js",
|
||||
"./src/scenegraph/AABB.js",
|
||||
"./src/scenegraph/SceneNode.js",
|
||||
"./src/scenegraph/Camera.js",
|
||||
"./src/scenegraph/Scene.js",
|
||||
"./src/scenegraph/MeshNode.js",
|
||||
"./src/sce -anegraph/Light.js",
|
||||
"./src/scenegraph/Sphere.js",
|
||||
"./src/objects/Mesh.js",
|
||||
"./src/navigation/CamHandler.js",
|
||||
"./src/navigation/FreeFlightCamHandler.js",
|
||||
"./src/navigation/OrbitCamHandler.js",
|
||||
"./src/Framebuffer.js",
|
||||
"./src/FramebufferFloat32.js",
|
||||
"./src/ResourceManager/ShaderManager.js",
|
||||
"./src/utils/MeshUtils.js",
|
||||
"./src/scenegraph/PointcloudOctreeSceneNode.js",
|
||||
"./src/scenegraph/PointCloudSceneNode.js",
|
||||
"./src/objects/PointCloud.js",
|
||||
"./src/objects/PointcloudOctreeNode.js",
|
||||
"./src/objects/PointcloudOctree.js",
|
||||
"./src/materials/Material.js",
|
||||
"./src/materials/WeightedPointSizeMaterial.js",
|
||||
"./src/materials/FixedPointSizeMaterial.js",
|
||||
"./src/materials/PointCloudMaterial.js",
|
||||
"./src/materials/FlatMaterial.js",
|
||||
"./src/materials/PhongMaterial.js",
|
||||
"./src/materials/FilteredSplatsMaterial.js",
|
||||
"./src/materials/GaussFillMaterial.js",
|
||||
"./src/loader/POCLoader.js",
|
||||
"./src/loader/PointAttributes.js",
|
||||
"./src/loader/PlyLoader.js",
|
||||
"./src/utils/LRU.js",
|
||||
"./src/Potree.js"
|
||||
]
|
||||
};
|
||||
|
||||
gulp.task('scripts', function() {
|
||||
// Copy all JavaScript into build directory
|
||||
gulp.src(paths.mjs)
|
||||
.pipe(concat('mjs.js'))
|
||||
.pipe(size({showFiles: true}))
|
||||
.pipe(gulp.dest('build/js'))
|
||||
.pipe(rename({suffix: '.min'}))
|
||||
.pipe(uglify({preserveComments: 'some'}))
|
||||
.pipe(size({showFiles: true}))
|
||||
.pipe(gulp.dest('build/js'));
|
||||
|
||||
gulp.src(paths.potree)
|
||||
.pipe(concat('potree.js'))
|
||||
.pipe(size({showFiles: true}))
|
||||
.pipe(gulp.dest('build/js'))
|
||||
.pipe(rename({suffix: '.min'}))
|
||||
.pipe(uglify({preserveComments: 'some'}))
|
||||
.pipe(size({showFiles: true}))
|
||||
.pipe(gulp.dest('build/js'));
|
||||
return;
|
||||
});
|
||||
|
||||
gulp.task('styles', function() {
|
||||
// Copy all Stylesheets into build directory
|
||||
return gulp.src('./resources/css/*.css')
|
||||
.pipe(concat('potree.css'))
|
||||
.pipe(gulp.dest('build/css'))
|
||||
.pipe(rename({suffix: '.min'}))
|
||||
.pipe(minify())
|
||||
.pipe(gulp.dest('build/css'));
|
||||
});
|
||||
|
||||
gulp.task('docs', function() {
|
||||
// Build documentation
|
||||
gulp.src('./docs/*.md')
|
||||
.pipe(mdown())
|
||||
.pipe(gulp.dest('build/docs'));
|
||||
|
||||
gulp.src('./docs/images/*')
|
||||
.pipe(gulp.dest('build/docs/images'));
|
||||
return;
|
||||
});
|
||||
|
||||
gulp.task('examples', function() {
|
||||
// Build examples
|
||||
var list = [];
|
||||
gulp.src('./examples/*.html')
|
||||
.pipe(tap(function (file,t) {
|
||||
var name = path.basename(file.path);
|
||||
var item = '<a href="' + name + '">' + name + '</a>';
|
||||
list.push('<li>' + item + '</li>');
|
||||
}))
|
||||
.pipe(gulp.dest('build'))
|
||||
.on('end', function () {
|
||||
gulp.src('./examples/index.tpl')
|
||||
.pipe(htmlreplace('toc', list.join(''), '<ul>%s</ul>'))
|
||||
.pipe(rename({extname: '.html'}))
|
||||
.pipe(gulp.dest('build'))
|
||||
});
|
||||
|
||||
// Copy resources
|
||||
gulp.src('./resources/**/*')
|
||||
.pipe(gulp.dest('build'));
|
||||
});
|
||||
|
||||
gulp.task('test', function() {
|
||||
// Test Javascript source files
|
||||
gulp.src(paths.mjs)
|
||||
.pipe(jshint())
|
||||
.pipe(jshint.reporter('default'));
|
||||
|
||||
gulp.src(paths.potree)
|
||||
.pipe(jshint())
|
||||
.pipe(jshint.reporter('default'));
|
||||
return;
|
||||
});
|
||||
|
||||
gulp.task('clean', function() {
|
||||
// Clean the following directories
|
||||
return gulp.src(['build'], { read: false })
|
||||
.pipe(clean());
|
||||
});
|
||||
|
||||
gulp.task('watch', function () {
|
||||
// Watch the following files for changes
|
||||
gulp.watch(paths.mjs, ['debug']);
|
||||
gulp.watch(paths.potree, ['debug']);
|
||||
});
|
||||
|
||||
// Simple webserver
|
||||
gulp.task('serve', serve('build'));
|
||||
|
||||
// called when you run `gulp` from cli
|
||||
gulp.task('build', ['examples', 'scripts', 'styles', 'docs']);
|
||||
gulp.task('debug', ['build', 'watch', 'serve'], function () {
|
||||
gutil.log('Webserver started:', gutil.colors.cyan('http://localhost:3000'));
|
||||
});
|
||||
1231
libs/mjs/mjs.js
625
libs/other/OrbitControls.js
Normal file
@ -0,0 +1,625 @@
|
||||
/**
|
||||
* @author qiao / https://github.com/qiao
|
||||
* @author mrdoob / http://mrdoob.com
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
* @author erich666 / http://erichaines.com
|
||||
*/
|
||||
/*global THREE, console */
|
||||
|
||||
// This set of controls performs orbiting, dollying (zooming), and panning. It maintains
|
||||
// the "up" direction as +Y, unlike the TrackballControls. Touch on tablet and phones is
|
||||
// supported.
|
||||
//
|
||||
// Orbit - left mouse / touch: one finger move
|
||||
// Zoom - middle mouse, or mousewheel / touch: two finger spread or squish
|
||||
// Pan - right mouse, or arrow keys / touch: three finter swipe
|
||||
//
|
||||
// This is a drop-in replacement for (most) TrackballControls used in examples.
|
||||
// That is, include this js file and wherever you see:
|
||||
// controls = new THREE.TrackballControls( camera );
|
||||
// controls.target.z = 150;
|
||||
// Simple substitute "OrbitControls" and the control should work as-is.
|
||||
|
||||
THREE.OrbitControls = function ( object, domElement ) {
|
||||
|
||||
this.object = object;
|
||||
this.domElement = ( domElement !== undefined ) ? domElement : document;
|
||||
|
||||
// API
|
||||
|
||||
// Set to false to disable this control
|
||||
this.enabled = true;
|
||||
|
||||
// "target" sets the location of focus, where the control orbits around
|
||||
// and where it pans with respect to.
|
||||
this.target = new THREE.Vector3();
|
||||
|
||||
// center is old, deprecated; use "target" instead
|
||||
this.center = this.target;
|
||||
|
||||
// This option actually enables dollying in and out; left as "zoom" for
|
||||
// backwards compatibility
|
||||
this.noZoom = false;
|
||||
this.zoomSpeed = 1.0;
|
||||
|
||||
// Limits to how far you can dolly in and out
|
||||
this.minDistance = 0;
|
||||
this.maxDistance = Infinity;
|
||||
|
||||
// Set to true to disable this control
|
||||
this.noRotate = false;
|
||||
this.rotateSpeed = 1.0;
|
||||
|
||||
// Set to true to disable this control
|
||||
this.noPan = false;
|
||||
this.keyPanSpeed = 7.0; // pixels moved per arrow key push
|
||||
|
||||
// Set to true to automatically rotate around the target
|
||||
this.autoRotate = false;
|
||||
this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
|
||||
|
||||
// How far you can orbit vertically, upper and lower limits.
|
||||
// Range is 0 to Math.PI radians.
|
||||
this.minPolarAngle = 0; // radians
|
||||
this.maxPolarAngle = Math.PI; // radians
|
||||
|
||||
// Set to true to disable use of the keys
|
||||
this.noKeys = false;
|
||||
|
||||
// The four arrow keys
|
||||
this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
|
||||
|
||||
////////////
|
||||
// internals
|
||||
|
||||
var scope = this;
|
||||
|
||||
var EPS = 0.000001;
|
||||
|
||||
var rotateStart = new THREE.Vector2();
|
||||
var rotateEnd = new THREE.Vector2();
|
||||
var rotateDelta = new THREE.Vector2();
|
||||
|
||||
var panStart = new THREE.Vector2();
|
||||
var panEnd = new THREE.Vector2();
|
||||
var panDelta = new THREE.Vector2();
|
||||
var panOffset = new THREE.Vector3();
|
||||
|
||||
var offset = new THREE.Vector3();
|
||||
|
||||
var dollyStart = new THREE.Vector2();
|
||||
var dollyEnd = new THREE.Vector2();
|
||||
var dollyDelta = new THREE.Vector2();
|
||||
|
||||
var phiDelta = 0;
|
||||
var thetaDelta = 0;
|
||||
var scale = 1;
|
||||
var pan = new THREE.Vector3();
|
||||
|
||||
var lastPosition = new THREE.Vector3();
|
||||
|
||||
var STATE = { NONE : -1, ROTATE : 0, DOLLY : 1, PAN : 2, TOUCH_ROTATE : 3, TOUCH_DOLLY : 4, TOUCH_PAN : 5 };
|
||||
|
||||
var state = STATE.NONE;
|
||||
|
||||
// for reset
|
||||
|
||||
this.target0 = this.target.clone();
|
||||
this.position0 = this.object.position.clone();
|
||||
|
||||
// events
|
||||
|
||||
var changeEvent = { type: 'change' };
|
||||
var startEvent = { type: 'start'};
|
||||
var endEvent = { type: 'end'};
|
||||
|
||||
this.rotateLeft = function ( angle ) {
|
||||
|
||||
if ( angle === undefined ) {
|
||||
|
||||
angle = getAutoRotationAngle();
|
||||
|
||||
}
|
||||
|
||||
thetaDelta -= angle;
|
||||
|
||||
};
|
||||
|
||||
this.rotateUp = function ( angle ) {
|
||||
|
||||
if ( angle === undefined ) {
|
||||
|
||||
angle = getAutoRotationAngle();
|
||||
|
||||
}
|
||||
|
||||
phiDelta -= angle;
|
||||
|
||||
};
|
||||
|
||||
// pass in distance in world space to move left
|
||||
this.panLeft = function ( distance ) {
|
||||
|
||||
var te = this.object.matrix.elements;
|
||||
|
||||
// get X column of matrix
|
||||
panOffset.set( te[ 0 ], te[ 1 ], te[ 2 ] );
|
||||
panOffset.multiplyScalar( - distance );
|
||||
|
||||
pan.add( panOffset );
|
||||
|
||||
};
|
||||
|
||||
// pass in distance in world space to move up
|
||||
this.panUp = function ( distance ) {
|
||||
|
||||
var te = this.object.matrix.elements;
|
||||
|
||||
// get Y column of matrix
|
||||
panOffset.set( te[ 4 ], te[ 5 ], te[ 6 ] );
|
||||
panOffset.multiplyScalar( distance );
|
||||
|
||||
pan.add( panOffset );
|
||||
|
||||
};
|
||||
|
||||
// pass in x,y of change desired in pixel space,
|
||||
// right and down are positive
|
||||
this.pan = function ( deltaX, deltaY ) {
|
||||
|
||||
var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
|
||||
|
||||
if ( scope.object.fov !== undefined ) {
|
||||
|
||||
// perspective
|
||||
var position = scope.object.position;
|
||||
var offset = position.clone().sub( scope.target );
|
||||
var targetDistance = offset.length();
|
||||
|
||||
// half of the fov is center to top of screen
|
||||
targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
|
||||
|
||||
// we actually don't use screenWidth, since perspective camera is fixed to screen height
|
||||
scope.panLeft( 2 * deltaX * targetDistance / element.clientHeight );
|
||||
scope.panUp( 2 * deltaY * targetDistance / element.clientHeight );
|
||||
|
||||
} else if ( scope.object.top !== undefined ) {
|
||||
|
||||
// orthographic
|
||||
scope.panLeft( deltaX * (scope.object.right - scope.object.left) / element.clientWidth );
|
||||
scope.panUp( deltaY * (scope.object.top - scope.object.bottom) / element.clientHeight );
|
||||
|
||||
} else {
|
||||
|
||||
// camera neither orthographic or perspective
|
||||
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.dollyIn = function ( dollyScale ) {
|
||||
|
||||
if ( dollyScale === undefined ) {
|
||||
|
||||
dollyScale = getZoomScale();
|
||||
|
||||
}
|
||||
|
||||
scale /= dollyScale;
|
||||
|
||||
};
|
||||
|
||||
this.dollyOut = function ( dollyScale ) {
|
||||
|
||||
if ( dollyScale === undefined ) {
|
||||
|
||||
dollyScale = getZoomScale();
|
||||
|
||||
}
|
||||
|
||||
scale *= dollyScale;
|
||||
|
||||
};
|
||||
|
||||
this.update = function () {
|
||||
|
||||
var position = this.object.position;
|
||||
|
||||
offset.copy( position ).sub( this.target );
|
||||
|
||||
// angle from z-axis around y-axis
|
||||
|
||||
var theta = Math.atan2( offset.x, offset.z );
|
||||
|
||||
// angle from y-axis
|
||||
|
||||
var phi = Math.atan2( Math.sqrt( offset.x * offset.x + offset.z * offset.z ), offset.y );
|
||||
|
||||
if ( this.autoRotate ) {
|
||||
|
||||
this.rotateLeft( getAutoRotationAngle() );
|
||||
|
||||
}
|
||||
|
||||
theta += thetaDelta;
|
||||
phi += phiDelta;
|
||||
|
||||
// restrict phi to be between desired limits
|
||||
phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, phi ) );
|
||||
|
||||
// restrict phi to be betwee EPS and PI-EPS
|
||||
phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
|
||||
|
||||
var radius = offset.length() * scale;
|
||||
|
||||
// restrict radius to be between desired limits
|
||||
radius = Math.max( this.minDistance, Math.min( this.maxDistance, radius ) );
|
||||
|
||||
// move target to panned location
|
||||
this.target.add( pan );
|
||||
|
||||
offset.x = radius * Math.sin( phi ) * Math.sin( theta );
|
||||
offset.y = radius * Math.cos( phi );
|
||||
offset.z = radius * Math.sin( phi ) * Math.cos( theta );
|
||||
|
||||
position.copy( this.target ).add( offset );
|
||||
|
||||
this.object.lookAt( this.target );
|
||||
|
||||
thetaDelta = 0;
|
||||
phiDelta = 0;
|
||||
scale = 1;
|
||||
pan.set( 0, 0, 0 );
|
||||
|
||||
if ( lastPosition.distanceTo( this.object.position ) > 0 ) {
|
||||
|
||||
this.dispatchEvent( changeEvent );
|
||||
|
||||
lastPosition.copy( this.object.position );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
this.reset = function () {
|
||||
|
||||
state = STATE.NONE;
|
||||
|
||||
this.target.copy( this.target0 );
|
||||
this.object.position.copy( this.position0 );
|
||||
|
||||
this.update();
|
||||
|
||||
};
|
||||
|
||||
function getAutoRotationAngle() {
|
||||
|
||||
return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
|
||||
|
||||
}
|
||||
|
||||
function getZoomScale() {
|
||||
|
||||
return Math.pow( 0.95, scope.zoomSpeed );
|
||||
|
||||
}
|
||||
|
||||
function onMouseDown( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
event.preventDefault();
|
||||
|
||||
if ( event.button === 0 ) {
|
||||
if ( scope.noRotate === true ) return;
|
||||
|
||||
state = STATE.ROTATE;
|
||||
|
||||
rotateStart.set( event.clientX, event.clientY );
|
||||
|
||||
} else if ( event.button === 1 ) {
|
||||
if ( scope.noZoom === true ) return;
|
||||
|
||||
state = STATE.DOLLY;
|
||||
|
||||
dollyStart.set( event.clientX, event.clientY );
|
||||
|
||||
} else if ( event.button === 2 ) {
|
||||
if ( scope.noPan === true ) return;
|
||||
|
||||
state = STATE.PAN;
|
||||
|
||||
panStart.set( event.clientX, event.clientY );
|
||||
|
||||
}
|
||||
|
||||
scope.domElement.addEventListener( 'mousemove', onMouseMove, false );
|
||||
scope.domElement.addEventListener( 'mouseup', onMouseUp, false );
|
||||
scope.dispatchEvent( startEvent );
|
||||
|
||||
}
|
||||
|
||||
function onMouseMove( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
|
||||
|
||||
if ( state === STATE.ROTATE ) {
|
||||
|
||||
if ( scope.noRotate === true ) return;
|
||||
|
||||
rotateEnd.set( event.clientX, event.clientY );
|
||||
rotateDelta.subVectors( rotateEnd, rotateStart );
|
||||
|
||||
// rotating across whole screen goes 360 degrees around
|
||||
scope.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
|
||||
|
||||
// rotating up and down along whole screen attempts to go 360, but limited to 180
|
||||
scope.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
|
||||
|
||||
rotateStart.copy( rotateEnd );
|
||||
|
||||
} else if ( state === STATE.DOLLY ) {
|
||||
|
||||
if ( scope.noZoom === true ) return;
|
||||
|
||||
dollyEnd.set( event.clientX, event.clientY );
|
||||
dollyDelta.subVectors( dollyEnd, dollyStart );
|
||||
|
||||
if ( dollyDelta.y > 0 ) {
|
||||
|
||||
scope.dollyIn();
|
||||
|
||||
} else {
|
||||
|
||||
scope.dollyOut();
|
||||
|
||||
}
|
||||
|
||||
dollyStart.copy( dollyEnd );
|
||||
|
||||
} else if ( state === STATE.PAN ) {
|
||||
|
||||
if ( scope.noPan === true ) return;
|
||||
|
||||
panEnd.set( event.clientX, event.clientY );
|
||||
panDelta.subVectors( panEnd, panStart );
|
||||
|
||||
scope.pan( panDelta.x, panDelta.y );
|
||||
|
||||
panStart.copy( panEnd );
|
||||
|
||||
}
|
||||
|
||||
scope.update();
|
||||
|
||||
}
|
||||
|
||||
function onMouseUp( /* event */ ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
scope.domElement.removeEventListener( 'mousemove', onMouseMove, false );
|
||||
scope.domElement.removeEventListener( 'mouseup', onMouseUp, false );
|
||||
scope.dispatchEvent( endEvent );
|
||||
state = STATE.NONE;
|
||||
|
||||
}
|
||||
|
||||
function onMouseWheel( event ) {
|
||||
|
||||
if ( scope.enabled === false || scope.noZoom === true ) return;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
var delta = 0;
|
||||
|
||||
if ( event.wheelDelta !== undefined ) { // WebKit / Opera / Explorer 9
|
||||
|
||||
delta = event.wheelDelta;
|
||||
|
||||
} else if ( event.detail !== undefined ) { // Firefox
|
||||
|
||||
delta = - event.detail;
|
||||
|
||||
}
|
||||
|
||||
if ( delta > 0 ) {
|
||||
|
||||
scope.dollyOut();
|
||||
|
||||
} else {
|
||||
|
||||
scope.dollyIn();
|
||||
|
||||
}
|
||||
|
||||
scope.update();
|
||||
scope.dispatchEvent( startEvent );
|
||||
scope.dispatchEvent( endEvent );
|
||||
|
||||
}
|
||||
|
||||
function onKeyDown( event ) {
|
||||
|
||||
if ( scope.enabled === false || scope.noKeys === true || scope.noPan === true ) return;
|
||||
|
||||
switch ( event.keyCode ) {
|
||||
|
||||
case scope.keys.UP:
|
||||
scope.pan( 0, scope.keyPanSpeed );
|
||||
scope.update();
|
||||
break;
|
||||
|
||||
case scope.keys.BOTTOM:
|
||||
scope.pan( 0, - scope.keyPanSpeed );
|
||||
scope.update();
|
||||
break;
|
||||
|
||||
case scope.keys.LEFT:
|
||||
scope.pan( scope.keyPanSpeed, 0 );
|
||||
scope.update();
|
||||
break;
|
||||
|
||||
case scope.keys.RIGHT:
|
||||
scope.pan( - scope.keyPanSpeed, 0 );
|
||||
scope.update();
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function touchstart( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
switch ( event.touches.length ) {
|
||||
|
||||
case 1: // one-fingered touch: rotate
|
||||
|
||||
if ( scope.noRotate === true ) return;
|
||||
|
||||
state = STATE.TOUCH_ROTATE;
|
||||
|
||||
rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
|
||||
break;
|
||||
|
||||
case 2: // two-fingered touch: dolly
|
||||
|
||||
if ( scope.noZoom === true ) return;
|
||||
|
||||
state = STATE.TOUCH_DOLLY;
|
||||
|
||||
var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
|
||||
var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
|
||||
var distance = Math.sqrt( dx * dx + dy * dy );
|
||||
dollyStart.set( 0, distance );
|
||||
break;
|
||||
|
||||
case 3: // three-fingered touch: pan
|
||||
|
||||
if ( scope.noPan === true ) return;
|
||||
|
||||
state = STATE.TOUCH_PAN;
|
||||
|
||||
panStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
state = STATE.NONE;
|
||||
|
||||
}
|
||||
|
||||
scope.dispatchEvent( startEvent );
|
||||
|
||||
}
|
||||
|
||||
function touchmove( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
|
||||
|
||||
switch ( event.touches.length ) {
|
||||
|
||||
case 1: // one-fingered touch: rotate
|
||||
|
||||
if ( scope.noRotate === true ) return;
|
||||
if ( state !== STATE.TOUCH_ROTATE ) return;
|
||||
|
||||
rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
|
||||
rotateDelta.subVectors( rotateEnd, rotateStart );
|
||||
|
||||
// rotating across whole screen goes 360 degrees around
|
||||
scope.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
|
||||
// rotating up and down along whole screen attempts to go 360, but limited to 180
|
||||
scope.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
|
||||
|
||||
rotateStart.copy( rotateEnd );
|
||||
|
||||
scope.update();
|
||||
break;
|
||||
|
||||
case 2: // two-fingered touch: dolly
|
||||
|
||||
if ( scope.noZoom === true ) return;
|
||||
if ( state !== STATE.TOUCH_DOLLY ) return;
|
||||
|
||||
var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
|
||||
var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
|
||||
var distance = Math.sqrt( dx * dx + dy * dy );
|
||||
|
||||
dollyEnd.set( 0, distance );
|
||||
dollyDelta.subVectors( dollyEnd, dollyStart );
|
||||
|
||||
if ( dollyDelta.y > 0 ) {
|
||||
|
||||
scope.dollyOut();
|
||||
|
||||
} else {
|
||||
|
||||
scope.dollyIn();
|
||||
|
||||
}
|
||||
|
||||
dollyStart.copy( dollyEnd );
|
||||
|
||||
scope.update();
|
||||
break;
|
||||
|
||||
case 3: // three-fingered touch: pan
|
||||
|
||||
if ( scope.noPan === true ) return;
|
||||
if ( state !== STATE.TOUCH_PAN ) return;
|
||||
|
||||
panEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
|
||||
panDelta.subVectors( panEnd, panStart );
|
||||
|
||||
scope.pan( panDelta.x, panDelta.y );
|
||||
|
||||
panStart.copy( panEnd );
|
||||
|
||||
scope.update();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
state = STATE.NONE;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function touchend( /* event */ ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
scope.dispatchEvent( endEvent );
|
||||
state = STATE.NONE;
|
||||
|
||||
}
|
||||
|
||||
this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
|
||||
this.domElement.addEventListener( 'mousedown', onMouseDown, false );
|
||||
this.domElement.addEventListener( 'mousewheel', onMouseWheel, false );
|
||||
this.domElement.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox
|
||||
|
||||
this.domElement.addEventListener( 'touchstart', touchstart, false );
|
||||
this.domElement.addEventListener( 'touchend', touchend, false );
|
||||
this.domElement.addEventListener( 'touchmove', touchmove, false );
|
||||
|
||||
window.addEventListener( 'keydown', onKeyDown, false );
|
||||
|
||||
};
|
||||
|
||||
THREE.OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );
|
||||
82
libs/other/dat.gui.min.js
vendored
Normal file
6
libs/other/stats.min.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
// stats.js - http://github.com/mrdoob/stats.js
|
||||
var Stats=function(){var l=Date.now(),m=l,g=0,n=Infinity,o=0,h=0,p=Infinity,q=0,r=0,s=0,f=document.createElement("div");f.id="stats";f.addEventListener("mousedown",function(b){b.preventDefault();t(++s%2)},!1);f.style.cssText="width:80px;opacity:0.9;cursor:pointer";var a=document.createElement("div");a.id="fps";a.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#002";f.appendChild(a);var i=document.createElement("div");i.id="fpsText";i.style.cssText="color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px";
|
||||
i.innerHTML="FPS";a.appendChild(i);var c=document.createElement("div");c.id="fpsGraph";c.style.cssText="position:relative;width:74px;height:30px;background-color:#0ff";for(a.appendChild(c);74>c.children.length;){var j=document.createElement("span");j.style.cssText="width:1px;height:30px;float:left;background-color:#113";c.appendChild(j)}var d=document.createElement("div");d.id="ms";d.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#020;display:none";f.appendChild(d);var k=document.createElement("div");
|
||||
k.id="msText";k.style.cssText="color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px";k.innerHTML="MS";d.appendChild(k);var e=document.createElement("div");e.id="msGraph";e.style.cssText="position:relative;width:74px;height:30px;background-color:#0f0";for(d.appendChild(e);74>e.children.length;)j=document.createElement("span"),j.style.cssText="width:1px;height:30px;float:left;background-color:#131",e.appendChild(j);var t=function(b){s=b;switch(s){case 0:a.style.display=
|
||||
"block";d.style.display="none";break;case 1:a.style.display="none",d.style.display="block"}};return{REVISION:11,domElement:f,setMode:t,begin:function(){l=Date.now()},end:function(){var b=Date.now();g=b-l;n=Math.min(n,g);o=Math.max(o,g);k.textContent=g+" MS ("+n+"-"+o+")";var a=Math.min(30,30-30*(g/200));e.appendChild(e.firstChild).style.height=a+"px";r++;b>m+1E3&&(h=Math.round(1E3*r/(b-m)),p=Math.min(p,h),q=Math.max(q,h),i.textContent=h+" FPS ("+p+"-"+q+")",a=Math.min(30,30-30*(h/100)),c.appendChild(c.firstChild).style.height=
|
||||
a+"px",m=b,r=0);return b},update:function(){l=this.end()}}};
|
||||
21
libs/three.js/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License
|
||||
|
||||
Copyright © 2010-2014 three.js authors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
69
libs/three.js/README.md
Normal file
@ -0,0 +1,69 @@
|
||||
three.js
|
||||
========
|
||||
|
||||
#### JavaScript 3D library ####
|
||||
|
||||
The aim of the project is to create a lightweight 3D library with a very low level of complexity — in other words, for dummies. The library provides <canvas>, <svg>, CSS3D and WebGL renderers.
|
||||
|
||||
[Examples](http://threejs.org/) — [Documentation](http://threejs.org/docs/) — [Migrating](https://github.com/mrdoob/three.js/wiki/Migration) — [Help](http://stackoverflow.com/questions/tagged/three.js)
|
||||
|
||||
|
||||
### Usage ###
|
||||
|
||||
Download the [minified library](http://threejs.org/build/three.min.js) and include it in your html.
|
||||
Alternatively see [how to build the library yourself](https://github.com/mrdoob/three.js/wiki/build.py,-or-how-to-generate-a-compressed-Three.js-file).
|
||||
|
||||
```html
|
||||
<script src="js/three.min.js"></script>
|
||||
```
|
||||
|
||||
This code creates a scene, a camera, and a geometric cube, and it adds the cube to the scene. It then creates a <canvas> renderer for the scene and camera, and it adds that viewport to the document.body element. Finally it animates the cube within the scene for the camera.
|
||||
|
||||
```html
|
||||
<script>
|
||||
|
||||
var scene, camera, renderer;
|
||||
var geometry, material, mesh;
|
||||
|
||||
init();
|
||||
animate();
|
||||
|
||||
function init() {
|
||||
|
||||
scene = new THREE.Scene();
|
||||
|
||||
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
|
||||
camera.position.z = 1000;
|
||||
|
||||
geometry = new THREE.BoxGeometry( 200, 200, 200 );
|
||||
material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );
|
||||
mesh = new THREE.Mesh( geometry, material );
|
||||
|
||||
scene.add( mesh );
|
||||
|
||||
renderer = new THREE.CanvasRenderer();
|
||||
renderer.setSize( window.innerWidth, window.innerHeight );
|
||||
|
||||
document.body.appendChild( renderer.domElement );
|
||||
|
||||
}
|
||||
|
||||
function animate() {
|
||||
|
||||
// note: three.js includes requestAnimationFrame shim
|
||||
requestAnimationFrame( animate );
|
||||
|
||||
mesh.rotation.x += 0.01;
|
||||
mesh.rotation.y += 0.02;
|
||||
|
||||
renderer.render( scene, camera );
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
```
|
||||
If everything went well you should see [this](http://jsfiddle.net/Gy4w7/).
|
||||
|
||||
### Change log ###
|
||||
|
||||
[releases](https://github.com/mrdoob/three.js/releases)
|
||||
37373
libs/three.js/build/three.js
Normal file
37372
libs/three.js/build/three.min.js
vendored
Normal file
39
package.json
@ -1,39 +0,0 @@
|
||||
{
|
||||
"name": "gulp-potree",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"description": "Packages required by build process",
|
||||
"dependencies": {
|
||||
"gulp": "*",
|
||||
"gulp-tap": "*",
|
||||
"gulp-util": "*",
|
||||
"gulp-size": "*",
|
||||
"gulp-clean": "*",
|
||||
"gulp-serve": "*",
|
||||
"gulp-jsdoc": "*",
|
||||
"gulp-concat": "*",
|
||||
"gulp-uglify": "*",
|
||||
"gulp-rename": "*",
|
||||
"gulp-jshint": "*",
|
||||
"gulp-inject": "*",
|
||||
"gulp-flatten": "*",
|
||||
"gulp-markdown": "*",
|
||||
"gulp-minify-css": "*",
|
||||
"gulp-html-replace": "*"
|
||||
},
|
||||
"author": {},
|
||||
"license": "",
|
||||
"devDependencies": {
|
||||
"gulp-rename": "~1.0.0",
|
||||
"gulp-concat": "~2.1.7",
|
||||
"gulp-uglify": "~0.2.1",
|
||||
"gulp-jshint": "~1.4.2",
|
||||
"gulp-sass": "~0.7.0",
|
||||
"gulp": "~3.5.2",
|
||||
"gulp-util": "~2.2.14",
|
||||
"gulp-clean": "~0.2.4",
|
||||
"gulp-serve": "~0.1.1",
|
||||
"gulp-markdown": "~0.1.2",
|
||||
"gulp-minify-css": "~0.3.0"
|
||||
}
|
||||
}
|
||||
@ -1,79 +0,0 @@
|
||||
|
||||
body{
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#output{
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
/*
|
||||
#workarea{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}*/
|
||||
|
||||
pre{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#pointclouds{
|
||||
background-color: rgb(200, 200, 230);
|
||||
position: fixed;
|
||||
z-index:199;
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
width:100%;
|
||||
height:140;
|
||||
}
|
||||
|
||||
#settingsContainer{
|
||||
background-color: rgb(200, 200, 230);
|
||||
position: fixed;
|
||||
z-index:199;
|
||||
top: 140px;
|
||||
left: 0px;
|
||||
width:200;
|
||||
bottom:0px;
|
||||
}
|
||||
|
||||
#canvas{
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#borderContainer {
|
||||
background-color: rgb(77, 77, 102);
|
||||
position: fixed;
|
||||
top: 140px;
|
||||
left: 200px;
|
||||
width: 100%;
|
||||
bottom: 0px;
|
||||
}
|
||||
|
||||
.thumbPointCloudContainer{
|
||||
width: 128px;
|
||||
height: 128px;
|
||||
border-radius: 5px;
|
||||
border: 2px solid black;
|
||||
box-shadow: 3px 3px 3px 0px #555;
|
||||
margin: 3px;
|
||||
}
|
||||
|
||||
.thumbPointCloudLabel{
|
||||
font-size: large;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
color: #FFF;
|
||||
text-shadow:black 0 0 5px,
|
||||
black 0 0 5px,
|
||||
black 0 0 5px,
|
||||
black 0 0 5px,
|
||||
black 0 0 5px,
|
||||
black 0 0 5px;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
varying vec3 vVertexColour;
|
||||
varying vec3 vNormal;
|
||||
|
||||
void main(void){
|
||||
float a = pow(2.0*(gl_PointCoord.x - 0.5), 2.0);
|
||||
float b = pow(2.0*(gl_PointCoord.y - 0.5), 2.0);
|
||||
float c = 1.0 - (a + b);
|
||||
|
||||
if(c < 0.0){
|
||||
discard;
|
||||
}
|
||||
|
||||
gl_FragColor = vec4( vVertexColour.xyz, 1.0 );
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec4 aVertexColour;
|
||||
//attribute vec3 aNormal;
|
||||
|
||||
uniform mat4 world;
|
||||
uniform mat4 view;
|
||||
uniform mat4 proj;
|
||||
uniform float uOpacity;
|
||||
uniform float uPointSize;
|
||||
uniform float uPointSizeMultiplicator;
|
||||
|
||||
varying vec3 vVertexColour;
|
||||
varying vec3 vNormal;
|
||||
varying vec3 vWorldPos;
|
||||
varying vec2 vDepth;
|
||||
|
||||
void main(void){
|
||||
vec4 worldPos = world * vec4(aVertexPosition, 1.0);
|
||||
vec4 pos = view * worldPos;
|
||||
//vNormal = (worldPos * vec4(aNormal, 0.0)).xyz;
|
||||
vWorldPos = worldPos.xyz;
|
||||
|
||||
// calculate point size depending on the distance from viewport
|
||||
// or rather: take a point in view space, translate it by {trans} along the x and y axis
|
||||
// and then calculate the translated distance in projected space.
|
||||
// this distance, multiplied by a user defined factor, gives the desired point size.
|
||||
float trans = 0.5 + max(length(pos)-10.0, 0.0) / 30.0;
|
||||
vec4 p1 = proj * pos;
|
||||
vec4 p2 = proj * (pos + vec4(trans,trans,0.0,0.0));
|
||||
p1.xyz = p1.xyz / p1.w;
|
||||
p2.xyz = p2.xyz / p1.w;
|
||||
vec2 dist = p1.xy - p2.xy;
|
||||
float ps = length(dist) * 30.0;
|
||||
ps = max(3.0, ps);
|
||||
ps = ps * uPointSizeMultiplicator;
|
||||
|
||||
gl_PointSize = ps;
|
||||
gl_Position = proj * pos;;
|
||||
vVertexColour = aVertexColour.xyz / 256.0;
|
||||
vDepth = vec2( gl_Position.w, gl_Position.z / gl_Position.w * 0.5 + 0.5 );
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
varying vec2 vTextureCoord;
|
||||
|
||||
uniform sampler2D uTexture;
|
||||
uniform sampler2D uDepth;
|
||||
uniform float uWidth;
|
||||
uniform float uHeight;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 col = texture2D(uTexture, vTextureCoord);
|
||||
gl_FragColor = vec4(col.xyz, col.w);
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
|
||||
precision highp float;
|
||||
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec2 aTexcoord;
|
||||
|
||||
varying vec2 vTextureCoord;
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_PointSize = 50.0;
|
||||
gl_Position = vec4(aVertexPosition, 1.0);
|
||||
vTextureCoord = aTexcoord;
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec4 aVertexColour;
|
||||
attribute vec3 aNormal;
|
||||
|
||||
uniform float uNear;
|
||||
uniform float uFar;
|
||||
uniform mat4 uWorld;
|
||||
uniform mat4 uView;
|
||||
uniform mat4 uProj;
|
||||
uniform float uPointSize;
|
||||
|
||||
varying vec3 vVertexColour;
|
||||
varying vec3 vPos;
|
||||
varying vec3 vNormal;
|
||||
|
||||
// calculate point size depending on the distance from viewport
|
||||
// or rather: take a point in view space, translate it by {trans} along the x and y axis
|
||||
// and then calculate the translated distance in projected space.
|
||||
// this distance, multiplied by a user defined factor, gives the desired point size.
|
||||
float pointSize(vec4 pos){
|
||||
float trans = 0.5 + max(length(pos)-10.0, 0.0) / 30.0;
|
||||
vec4 p1 = uProj * pos;
|
||||
vec4 p2 = uProj * (pos + vec4(trans,trans,0.0,0.0));
|
||||
p1.xyz = p1.xyz / p1.w;
|
||||
p2.xyz = p2.xyz / p1.w;
|
||||
vec2 dist = p1.xy - p2.xy;
|
||||
float ps = length(dist) * 30.0;
|
||||
ps = max(3.0, ps);
|
||||
ps = ps * uPointSize;
|
||||
|
||||
return ps;
|
||||
}
|
||||
|
||||
void main(void){
|
||||
vec4 worldPos = uWorld * vec4(aVertexPosition, 1.0);
|
||||
vPos = worldPos.xyz;
|
||||
vec4 pos = uView * worldPos;
|
||||
|
||||
vVertexColour = aVertexColour.xyz / 256.0;
|
||||
vNormal = (uWorld*vec4(aNormal, 0.0)).xyz;
|
||||
|
||||
gl_PointSize = pointSize(pos);
|
||||
|
||||
// calculate xy and linear z
|
||||
pos = uProj * pos;
|
||||
float w = pos.w;
|
||||
pos = pos / w;
|
||||
pos.z = 2.0*((w-uNear) / uFar)-1.0;
|
||||
gl_Position = pos;
|
||||
|
||||
}
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
varying vec3 vVertexColour;
|
||||
|
||||
float getDistance(){
|
||||
float a = pow(2.0*(gl_PointCoord.x - 0.5), 2.0);
|
||||
float b = pow(2.0*(gl_PointCoord.y - 0.5), 2.0);
|
||||
float c = 1.0 - (a + b);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void main(void){
|
||||
float c = getDistance();
|
||||
if(c <= 0.0){
|
||||
discard;
|
||||
}
|
||||
|
||||
float weight = pow(c+0.2, 40.0);
|
||||
|
||||
gl_FragColor = vec4( weight * vVertexColour, weight );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
varying vec3 vPos;
|
||||
|
||||
void main(void){
|
||||
float a = pow(2.0*(gl_PointCoord.x - 0.5), 2.0);
|
||||
float b = pow(2.0*(gl_PointCoord.y - 0.5), 2.0);
|
||||
float c = 1.0 - (a + b);
|
||||
|
||||
if(c < 0.0){
|
||||
discard;
|
||||
}
|
||||
|
||||
vec3 id = vec3(1.0,1.0,1.0);
|
||||
gl_FragColor = vec4(vPos, 1.0);
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
|
||||
precision highp float;
|
||||
|
||||
attribute vec3 aVertexPosition;
|
||||
|
||||
uniform float uNear;
|
||||
uniform float uFar;
|
||||
uniform mat4 uWorld;
|
||||
uniform mat4 uView;
|
||||
uniform mat4 uProj;
|
||||
uniform float uPointSize;
|
||||
uniform float uBlendDepth;
|
||||
|
||||
varying vec3 vPos;
|
||||
|
||||
// calculate point size depending on the distance from viewport
|
||||
// or rather: take a point in view space, translate it by {trans} along the x and y axis
|
||||
// and then calculate the translated distance in projected space.
|
||||
// this distance, multiplied by a user defined factor, gives the desired point size.
|
||||
float pointSize(vec4 pos){
|
||||
float trans = 0.5 + max(length(pos)-10.0, 0.0) / 30.0;
|
||||
vec4 p1 = uProj * pos;
|
||||
vec4 p2 = uProj * (pos + vec4(trans,trans,0.0,0.0));
|
||||
p1.xyz = p1.xyz / p1.w;
|
||||
p2.xyz = p2.xyz / p1.w;
|
||||
vec2 dist = p1.xy - p2.xy;
|
||||
float ps = length(dist) * 30.0;
|
||||
ps = max(3.0, ps);
|
||||
ps = ps * uPointSize;
|
||||
|
||||
return ps;
|
||||
}
|
||||
|
||||
void main(void){
|
||||
vec4 worldPos = uWorld * vec4(aVertexPosition, 1.0);
|
||||
vPos = (uWorld * vec4(aVertexPosition, 1.0)).xyz;
|
||||
vec4 pos = uView * worldPos;
|
||||
|
||||
gl_PointSize = pointSize(pos);
|
||||
pos = uProj * pos;
|
||||
float w = pos.w;
|
||||
float depth = pos.z;
|
||||
pos = pos / w;
|
||||
pos.z = 2.0*((w+uBlendDepth-uNear) / uFar)-1.0;
|
||||
gl_Position = pos;
|
||||
}
|
||||
@ -1,88 +0,0 @@
|
||||
|
||||
precision highp float;
|
||||
|
||||
//varying vec3 vVertexColour;
|
||||
varying vec3 vNormal;
|
||||
//varying vec3 vViewNormal;
|
||||
//varying vec3 vPos;
|
||||
//varying vec3 vViewPos;
|
||||
//varying vec3 vViewTangent1;
|
||||
//varying vec3 vViewTangent2;
|
||||
|
||||
//uniform vec2 uWindowSize;
|
||||
//uniform vec2 uNearWindowSize;
|
||||
//uniform float uNear;
|
||||
|
||||
//float getDistance(){
|
||||
// float u = 2.0*(gl_PointCoord.x - 0.5);
|
||||
// float v = 2.0*(gl_PointCoord.y - 0.5);
|
||||
// vec2 uv = vec2(u,v);
|
||||
//
|
||||
// vec2 a = normalize(vec2(-vViewNormal.y, vViewNormal.x));
|
||||
// vec2 b = normalize(vec2(vViewNormal.x, vViewNormal.y));
|
||||
// b = b * (1.0/vViewNormal.z);
|
||||
//
|
||||
// float val = pow(dot(a, uv), 2.0) + pow(dot(b, uv), 2.0);
|
||||
// return 1.0 - val;
|
||||
//}
|
||||
|
||||
float getDistance(){
|
||||
float a = pow(2.0*(gl_PointCoord.x - 0.5), 2.0);
|
||||
float b = pow(2.0*(gl_PointCoord.y - 0.5), 2.0);
|
||||
float c = 1.0 - (a + b);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
//float getDistance(){
|
||||
// vec3 N = normalize(vViewNormal);
|
||||
// vec3 P = vec3(0.0, 0.0, 0.0);
|
||||
// vec3 Cc = vViewPos;
|
||||
// vec3 T1 = vViewTangent1;
|
||||
// vec3 T2 = vViewTangent2;
|
||||
// T1 = N.yzx;
|
||||
// T2 = N.zxy;
|
||||
//
|
||||
// float u = (gl_FragCoord.x / uWindowSize.x)-0.5;
|
||||
// float v = (gl_FragCoord.y / uWindowSize.y)-0.5;
|
||||
//// float u = 2.0*(gl_PointCoord.x - 0.5);
|
||||
//// float v = 2.0*((1.0-gl_PointCoord.y)-0.5);
|
||||
//
|
||||
// vec3 V = vec3(0,0,0);
|
||||
// V.x = u*uNearWindowSize.x;
|
||||
// V.y = v*uNearWindowSize.y;
|
||||
// V.z = -uNear;
|
||||
// V = normalize(V);
|
||||
//
|
||||
// float d = -dot(N, Cc);
|
||||
//// d = 2.0;
|
||||
// float t = -(dot(P,N)+d)/dot(V, N);
|
||||
// t = max(t, 0.0);
|
||||
// vec3 I = P + V*t - Cc;
|
||||
////
|
||||
// float val = pow(dot(T1, I), 2.0) + pow(dot(T2, I), 2.0);
|
||||
// val = val * 5000.0;
|
||||
//
|
||||
// return 1.0 - val;
|
||||
//}
|
||||
|
||||
void main(void){
|
||||
float c = getDistance();
|
||||
if(c <= 0.0){
|
||||
discard;
|
||||
}
|
||||
|
||||
// calculate weight
|
||||
// float d = 5.0*(c + 0.5);
|
||||
// float weight = exp(d*d);
|
||||
|
||||
// interpolate normals smoother than color
|
||||
float weight = pow(c, 2.0);
|
||||
// float weight = pow(c+0.2, 40.0);
|
||||
|
||||
gl_FragColor = vec4( weight * vNormal, weight );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
uniform sampler2D uNormal;
|
||||
uniform sampler2D uColor;
|
||||
uniform sampler2D uPosition;
|
||||
|
||||
uniform vec3 uLightPos;
|
||||
uniform vec3 uLightColor;
|
||||
uniform int uIlluminationMode;
|
||||
|
||||
varying vec2 vTextureCoord;
|
||||
|
||||
vec3 phongIllumination(vec3 N, vec3 color, vec3 pos){
|
||||
vec3 L = normalize(uLightPos - pos);
|
||||
float nDotL = clamp(dot(N, L), 0.0, 1.0);
|
||||
vec3 diffuse = uLightColor * color * (nDotL*0.8 + 0.2);
|
||||
vec3 ambient = vec3(0.0,0.0,0.0);
|
||||
|
||||
return diffuse;
|
||||
}
|
||||
|
||||
void main(void){
|
||||
vec4 weightedColor = texture2D(uColor, vTextureCoord);
|
||||
if(weightedColor.a <= 0.0){
|
||||
discard;
|
||||
}
|
||||
|
||||
vec4 weightedNormal = texture2D( uNormal, vTextureCoord );
|
||||
vec3 N = normalize(weightedNormal.xyz / weightedNormal.w);
|
||||
vec3 color = weightedColor.rgb / weightedColor.a;
|
||||
vec3 pos = texture2D(uPosition, vTextureCoord).xyz;
|
||||
|
||||
if(uIlluminationMode == 0){
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}else if(uIlluminationMode == 1){
|
||||
gl_FragColor = vec4(phongIllumination(N, color, pos), 1.0);
|
||||
}else if(uIlluminationMode == 2){
|
||||
gl_FragColor = vec4(N, 1.0);
|
||||
}else if(uIlluminationMode == 3){
|
||||
gl_FragColor = vec4(pos, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec4 aVertexColour;
|
||||
//attribute vec3 aNormal;
|
||||
|
||||
uniform mat4 uWorld;
|
||||
uniform mat4 uView;
|
||||
uniform mat4 uProj;
|
||||
uniform float uPointSize;
|
||||
|
||||
varying vec3 vVertexColour;
|
||||
//varying vec3 vNormal;
|
||||
varying vec3 vWorldPos;
|
||||
// vDepth.x: The linear depth.
|
||||
// vDepth.y: DepthMap depth.
|
||||
varying vec2 vDepth;
|
||||
|
||||
void main(void){
|
||||
vec4 worldPos = uWorld * vec4(aVertexPosition, 1.0);
|
||||
vec4 pos = uView * worldPos;
|
||||
//vNormal = (worldPos * vec4(aNormal, 0.0)).xyz;
|
||||
vWorldPos = worldPos.xyz;
|
||||
|
||||
gl_PointSize = uPointSize;
|
||||
gl_Position = uProj * pos;
|
||||
vVertexColour = aVertexColour.xyz / 256.0;
|
||||
vDepth = vec2( gl_Position.w, gl_Position.z / gl_Position.w * 0.5 + 0.5 );
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
|
||||
precision highp float;
|
||||
|
||||
uniform vec4 uColor;
|
||||
|
||||
void main(void){
|
||||
gl_FragColor = uColor;
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
attribute vec3 aVertexPosition;
|
||||
|
||||
uniform mat4 uWorld;
|
||||
uniform mat4 uView;
|
||||
uniform mat4 uProj;
|
||||
|
||||
void main(void){
|
||||
vec4 pos = uProj * uView * uWorld * vec4(aVertexPosition, 1.0);
|
||||
gl_Position = pos;
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
|
||||
precision highp float;
|
||||
|
||||
void main(void){
|
||||
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
|
||||
precision highp float;
|
||||
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec3 aNormal;
|
||||
|
||||
uniform float uNear;
|
||||
uniform float uFar;
|
||||
uniform mat4 uWorld;
|
||||
uniform mat4 uView;
|
||||
uniform mat4 uProj;
|
||||
uniform float uPointSize;
|
||||
uniform float uBlendDepth;
|
||||
|
||||
// calculate point size depending on the distance from viewport
|
||||
// or rather: take a point in view space, translate it by {trans} along the x and y axis
|
||||
// and then calculate the translated distance in projected space.
|
||||
// this distance, multiplied by a user defined factor, gives the desired point size.
|
||||
float pointSize(vec4 pos){
|
||||
float trans = 0.5 + max(length(pos)-10.0, 0.0) / 30.0;
|
||||
vec4 p1 = uProj * pos;
|
||||
vec4 p2 = uProj * (pos + vec4(trans,trans,0.0,0.0));
|
||||
p1.xyz = p1.xyz / p1.w;
|
||||
p2.xyz = p2.xyz / p1.w;
|
||||
vec2 dist = p1.xy - p2.xy;
|
||||
float ps = length(dist) * 30.0;
|
||||
ps = max(3.0, ps);
|
||||
// ps = ps * uPointSize;
|
||||
|
||||
return ps;
|
||||
}
|
||||
|
||||
void main(void){
|
||||
vec4 worldPos = uWorld * vec4(aVertexPosition, 1.0);
|
||||
// vPos = (uWorld * vec4(aVertexPosition, 1.0)).xyz;
|
||||
vec4 pos = uView * worldPos;
|
||||
|
||||
gl_PointSize = pointSize(pos);
|
||||
pos = uProj * pos;
|
||||
float w = pos.w;
|
||||
float depth = pos.z;
|
||||
pos = pos / w;
|
||||
pos.z = 2.0*((w+uBlendDepth-uNear) / uFar)-1.0;
|
||||
gl_Position = pos;
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
uniform sampler2D uColor;
|
||||
|
||||
varying vec2 vTextureCoord;
|
||||
|
||||
void main(void){
|
||||
vec4 color = texture2D(uColor, vTextureCoord);
|
||||
color = color / color.a;
|
||||
gl_FragColor = color;
|
||||
// gl_FragColor = vec4(0.0, color.a, 0.0, 1.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
|
||||
precision highp float;
|
||||
|
||||
varying vec3 vVertexColour;
|
||||
|
||||
void main(void){
|
||||
/*float a = pow(2.0*(gl_PointCoord.x - 0.5), 2.0);
|
||||
float b = pow(2.0*(gl_PointCoord.y - 0.5), 2.0);
|
||||
float c = 1.0 - (a + b);
|
||||
|
||||
if(c < 0.0){
|
||||
discard;
|
||||
}*/
|
||||
|
||||
gl_FragColor = vec4(vVertexColour, 1.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
|
||||
precision highp float;
|
||||
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec4 aVertexColour;
|
||||
|
||||
uniform mat4 uWorld;
|
||||
uniform mat4 uView;
|
||||
uniform mat4 uProj;
|
||||
uniform float uNear;
|
||||
uniform float uFar;
|
||||
uniform float uPointSize;
|
||||
|
||||
varying vec3 vVertexColour;
|
||||
|
||||
float pointSize(vec4 pos){
|
||||
float trans = 0.5 + max(length(pos)-10.0, 0.0) / 30.0;
|
||||
vec4 p1 = uProj * pos;
|
||||
vec4 p2 = uProj * (pos + vec4(trans,trans,0.0,0.0));
|
||||
p1.xyz = p1.xyz / p1.w;
|
||||
p2.xyz = p2.xyz / p1.w;
|
||||
vec2 dist = p1.xy - p2.xy;
|
||||
float ps = length(dist) * 30.0;
|
||||
ps = max(3.0, ps);
|
||||
ps = ps * 0.3;
|
||||
|
||||
return ps;
|
||||
}
|
||||
|
||||
void main(void){
|
||||
vec4 pos = uView * uWorld * vec4(aVertexPosition, 1.0);
|
||||
vVertexColour = aVertexColour.xyz / 256.0;
|
||||
//float ps = pointSize(pos);
|
||||
|
||||
pos = uProj * pos;
|
||||
float w = pos.w;
|
||||
float depth = pos.z;
|
||||
pos = pos / w;
|
||||
pos.z = 2.0*((w-uNear) / uFar)-1.0;
|
||||
|
||||
gl_PointSize = 1.0;
|
||||
//gl_PointSize = ps;
|
||||
gl_Position = pos;
|
||||
|
||||
}
|
||||
|
||||
@ -1,37 +0,0 @@
|
||||
|
||||
// gauss kernel, r = 3: 0.034793, 0.102006, 0.216137, 0.294128, 0.216137, 0.102006, 0.034793
|
||||
// gauss kernel, r = 5: 0.0216149, 0.0439554, 0.0778778, 0.118718, 0.153857, 0.167953, 0.153857, 0.118718, 0.0778778, 0.0439554, 0.0216149
|
||||
|
||||
precision highp float;
|
||||
|
||||
uniform sampler2D uColor;
|
||||
uniform vec2 uWindowSize;
|
||||
uniform float uKernel[11];
|
||||
|
||||
varying vec2 vTextureCoord;
|
||||
|
||||
void main(void){
|
||||
|
||||
vec4 color = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for(int i = 0; i < 11; i++){
|
||||
float j = float(i)-5.0;
|
||||
|
||||
vec2 offset = vec2(j/uWindowSize.x, 0.0);
|
||||
color = color + uKernel[i] * texture2D(uColor, vTextureCoord + offset);
|
||||
}
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
|
||||
precision highp float;
|
||||
|
||||
uniform sampler2D uColor;
|
||||
uniform vec2 uWindowSize;
|
||||
uniform float uKernel[11];
|
||||
|
||||
varying vec2 vTextureCoord;
|
||||
|
||||
void main(void){
|
||||
vec4 color = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for(int i = 0; i < 11; i++){
|
||||
float j = float(i)-5.0;
|
||||
|
||||
vec2 offset = vec2(0.0, j/uWindowSize.y);
|
||||
color = color + uKernel[i] * texture2D(uColor, vTextureCoord + offset);
|
||||
}
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
|
||||
precision highp float;
|
||||
|
||||
varying vec3 normal;
|
||||
|
||||
uniform vec4 uColor;
|
||||
|
||||
void main(void){
|
||||
gl_FragColor = uColor;
|
||||
gl_FragColor = vec4(normal, 1.0);
|
||||
// gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec3 aVertexNormal;
|
||||
|
||||
varying vec3 normal;
|
||||
|
||||
uniform mat4 uWorld;
|
||||
uniform mat4 uView;
|
||||
uniform mat4 uProj;
|
||||
|
||||
void main(void){
|
||||
vec4 pos = uProj * uView * uWorld * vec4(aVertexPosition, 1.0);
|
||||
normal = (uWorld * vec4(aVertexNormal, 0.0)).xyz;
|
||||
gl_Position = pos;
|
||||
gl_PointSize = 10.0;
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
attribute vec3 aVertexPosition;
|
||||
attribute vec4 aVertexColour;
|
||||
attribute vec3 aNormal;
|
||||
|
||||
uniform mat4 uWorld;
|
||||
uniform mat4 uView;
|
||||
uniform mat4 uProj;
|
||||
uniform float uPointSizeMultiplicator;
|
||||
|
||||
varying vec3 vVertexColour;
|
||||
|
||||
void main(void){
|
||||
vec4 worldPos = uWorld * vec4(aVertexPosition, 1.0);
|
||||
vec4 pos = uView * worldPos;
|
||||
|
||||
// calculate point size depending on the distance from viewport
|
||||
// or rather: take a point in view space, translate it by {trans} along the x and y axis
|
||||
// and then calculate the translated distance in projected space.
|
||||
// this distance, multiplied by a user defined factor, gives the desired point size.
|
||||
float trans = 0.5 + max(length(pos)-10.0, 0.0) / 30.0;
|
||||
vec4 p1 = uProj * pos;
|
||||
vec4 p2 = uProj * (pos + vec4(trans,trans,0.0,0.0));
|
||||
p1.xyz = p1.xyz / p1.w;
|
||||
p2.xyz = p2.xyz / p1.w;
|
||||
vec2 dist = p1.xy - p2.xy;
|
||||
float ps = length(dist) * 30.0;
|
||||
ps = max(3.0, ps);
|
||||
ps = ps * uPointSizeMultiplicator;
|
||||
|
||||
gl_PointSize = ps;
|
||||
gl_Position = uProj * pos;
|
||||
vVertexColour = aVertexColour.xyz / 256.0;
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
|
||||
precision highp float;
|
||||
|
||||
varying float vDepth;
|
||||
|
||||
/**
|
||||
* from http://stackoverflow.com/questions/9882716/packing-float-into-vec4-how-does-this-code-work
|
||||
*/
|
||||
vec4 pack_depth(const in float depth)
|
||||
{
|
||||
const vec4 bit_shift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);
|
||||
const vec4 bit_mask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);
|
||||
vec4 res = fract(depth * bit_shift);
|
||||
res -= res.xxyz * bit_mask;
|
||||
return res;
|
||||
}
|
||||
|
||||
void main(void){
|
||||
float a = pow(2.0*(gl_PointCoord.x - 0.5), 2.0);
|
||||
float b = pow(2.0*(gl_PointCoord.y - 0.5), 2.0);
|
||||
float c = 1.0 - (a + b);
|
||||
|
||||
if(c < 0.0){
|
||||
discard;
|
||||
}
|
||||
|
||||
gl_FragColor = pack_depth(vDepth);
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
attribute vec3 aVertexPosition;
|
||||
|
||||
uniform mat4 uWorld;
|
||||
uniform mat4 uView;
|
||||
uniform mat4 uProj;
|
||||
uniform float uPointSizeMultiplicator;
|
||||
|
||||
varying float vDepth;
|
||||
|
||||
void main(void){
|
||||
vec4 worldPos = uWorld * vec4(aVertexPosition, 1.0);
|
||||
vec4 pos = uView * worldPos;
|
||||
|
||||
// calculate point size depending on the distance from viewport
|
||||
// or rather: take a point in view space, translate it by {trans} along the x and y axis
|
||||
// and then calculate the translated distance in projected space.
|
||||
// this distance, multiplied by a user defined factor, gives the desired point size.
|
||||
float trans = 0.5 + max(length(pos)-10.0, 0.0) / 30.0;
|
||||
vec4 p1 = uProj * pos;
|
||||
vec4 p2 = uProj * (pos + vec4(trans,trans,0.0,0.0));
|
||||
p1.xyz = p1.xyz / p1.w;
|
||||
p2.xyz = p2.xyz / p1.w;
|
||||
vec2 dist = p1.xy - p2.xy;
|
||||
float ps = length(dist) * 30.0;
|
||||
ps = max(3.0, ps);
|
||||
ps = ps * uPointSizeMultiplicator;
|
||||
|
||||
gl_PointSize = ps;
|
||||
gl_Position = uProj * pos;
|
||||
|
||||
vDepth = gl_Position.z / gl_Position.w;
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
varying vec3 vPos;
|
||||
|
||||
void main(void){
|
||||
float a = pow(2.0*(gl_PointCoord.x - 0.5), 2.0);
|
||||
float b = pow(2.0*(gl_PointCoord.y - 0.5), 2.0);
|
||||
float c = 1.0 - (a + b);
|
||||
|
||||
if(c < 0.0){
|
||||
discard;
|
||||
}
|
||||
|
||||
gl_FragColor = vec4( vPos, 1.0 );
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
|
||||
|
||||
precision highp float;
|
||||
|
||||
attribute vec3 aVertexPosition;
|
||||
|
||||
uniform mat4 uWorld;
|
||||
uniform mat4 uView;
|
||||
uniform mat4 uProj;
|
||||
uniform float uPointSizeMultiplicator;
|
||||
|
||||
varying vec3 vPos;
|
||||
|
||||
void main(void){
|
||||
vec4 worldPos = uWorld * vec4(aVertexPosition, 1.0);
|
||||
vec4 pos = uView * worldPos;
|
||||
|
||||
// calculate point size depending on the distance from viewport
|
||||
// or rather: take a point in view space, translate it by {trans} along the x and y axis
|
||||
// and then calculate the translated distance in projected space.
|
||||
// this distance, multiplied by a user defined factor, gives the desired point size.
|
||||
float trans = 0.5 + max(length(pos)-10.0, 0.0) / 30.0;
|
||||
vec4 p1 = uProj * pos;
|
||||
vec4 p2 = uProj * (pos + vec4(trans,trans,0.0,0.0));
|
||||
p1.xyz = p1.xyz / p1.w;
|
||||
p2.xyz = p2.xyz / p1.w;
|
||||
vec2 dist = p1.xy - p2.xy;
|
||||
float ps = length(dist) * 30.0;
|
||||
ps = max(3.0, ps);
|
||||
ps = ps * uPointSizeMultiplicator;
|
||||
|
||||
gl_PointSize = ps;
|
||||
gl_Position = uProj * pos;
|
||||
vPos = worldPos.xyz;
|
||||
}
|
||||
BIN
resources/textures/skybox/nx.jpg
Normal file
|
After Width: | Height: | Size: 37 KiB |
BIN
resources/textures/skybox/ny.jpg
Normal file
|
After Width: | Height: | Size: 6.3 KiB |
BIN
resources/textures/skybox/nz.jpg
Normal file
|
After Width: | Height: | Size: 41 KiB |
BIN
resources/textures/skybox/px.jpg
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
resources/textures/skybox/py.jpg
Normal file
|
After Width: | Height: | Size: 75 KiB |
BIN
resources/textures/skybox/pz.jpg
Normal file
|
After Width: | Height: | Size: 47 KiB |
1
resources/textures/skybox/skyboxsun25degtest.txt
Normal file
@ -0,0 +1 @@
|
||||
http://reije081.home.xs4all.nl/skyboxes/
|
||||
BIN
resources/textures/skyboxsun25degtest.png
Normal file
|
After Width: | Height: | Size: 1.8 MiB |
1
resources/textures/skyboxsun25degtest.txt
Normal file
@ -0,0 +1 @@
|
||||
http://reije081.home.xs4all.nl/skyboxes/
|
||||
@ -1,315 +0,0 @@
|
||||
|
||||
/**
|
||||
* You can call the constructor with either, width and height, or "system". When
|
||||
* invoking the constructor with "system", the framebuffer will refer to the
|
||||
* system/default framebuffer.
|
||||
*
|
||||
* @param {int}
|
||||
* width
|
||||
* @param {int}
|
||||
* height
|
||||
* @class create and handle FramebufferObjects
|
||||
* @see <a href="http://learningwebgl.com/blog/?p=1786">WebGL Lesson 16</a>
|
||||
*/
|
||||
function Framebuffer(width, height) {
|
||||
if (arguments[0] === inheriting)
|
||||
return;
|
||||
if (arguments[0] === "system") {
|
||||
this.framebuffer = null;
|
||||
this.initOtherStuff();
|
||||
} else {
|
||||
this.initBufferStuff(width, height);
|
||||
this.initOtherStuff();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns the system framebuffer
|
||||
*/
|
||||
Framebuffer.getSystemBuffer = function() {
|
||||
if (Framebuffer.systemBuffer == null) {
|
||||
Framebuffer.systemBuffer = new Framebuffer("system");
|
||||
}
|
||||
|
||||
return Framebuffer.systemBuffer;
|
||||
};
|
||||
|
||||
Framebuffer.getActiveBuffer = function() {
|
||||
if (Framebuffer.activeBuffer == null) {
|
||||
Framebuffer.activeBuffer = Framebuffer.getSystemBuffer();
|
||||
}
|
||||
|
||||
return Framebuffer.activeBuffer;
|
||||
};
|
||||
|
||||
Framebuffer.setActiveBuffer = function(buffer) {
|
||||
Framebuffer.activeBuffer = buffer;
|
||||
};
|
||||
|
||||
/**
|
||||
* change size of the framebuffer.
|
||||
*
|
||||
* @param {int}
|
||||
* width
|
||||
* @param {int}
|
||||
* height
|
||||
*/
|
||||
Framebuffer.prototype.setSize = function(width, height) {
|
||||
this.initBufferStuff(width, height);
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize stuff like a vbo for screen quads.
|
||||
*/
|
||||
Framebuffer.prototype.initOtherStuff = function() {
|
||||
|
||||
this.vbo = gl.createBuffer();
|
||||
this.texcoordvbo = gl.createBuffer();
|
||||
|
||||
// create rectangle mesh buffer
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.vbo);
|
||||
var vertices = new Float32Array([ 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0 ]);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
|
||||
|
||||
// create uv coords buffer
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordvbo);
|
||||
vertices = new Float32Array([ 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1 ]);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* change size of screenQuad.
|
||||
*
|
||||
* @param {[x,y]}
|
||||
* start x and y must be values between 0 and 1
|
||||
* @param {[x,y]}
|
||||
* end x and y must be values between 0 and 1
|
||||
*/
|
||||
Framebuffer.prototype.updateScreenQuad = function(start, end) {
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.vbo);
|
||||
var vertices = new Float32Array([ start[0], start[1], 0, end[0], start[1],
|
||||
0, end[0], end[1], 0, start[0], start[1], 0, end[0], end[1], 0,
|
||||
start[0], end[1], 0 ]);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
|
||||
};
|
||||
|
||||
/**
|
||||
* removes existing webgl color/render/frame-buffers and creates new ones
|
||||
*
|
||||
* @param {int}
|
||||
* width
|
||||
* @param {int}
|
||||
* height
|
||||
*/
|
||||
Framebuffer.prototype.initBufferStuff = function(width, height) {
|
||||
if (this.width === width && this.height === height) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
// remove exiting buffers
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
if (this.texture != null) {
|
||||
gl.deleteTexture(this.texture.glid);
|
||||
this.texture = null;
|
||||
}
|
||||
if (this.renderbuffer != null) {
|
||||
gl.deleteRenderbuffer(this.renderbuffer);
|
||||
this.renderbuffer = null;
|
||||
}
|
||||
if (this.framebuffer != null) {
|
||||
gl.deleteFramebuffer(this.framebuffer);
|
||||
this.framebuffer = null;
|
||||
}
|
||||
|
||||
// create new buffers
|
||||
this.framebuffer = gl.createFramebuffer();
|
||||
this.texture = new Texture();
|
||||
this.renderbuffer = gl.createRenderbuffer();
|
||||
|
||||
// WEBGL_depth_texture not supported in firefox/ANGLE
|
||||
// this.depthTexture = new Texture();
|
||||
// this.depthTexture.glid = gl.createTexture();
|
||||
|
||||
// framebuffer
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
|
||||
this.framebuffer.width = width;
|
||||
this.framebuffer.height = height;
|
||||
|
||||
// colorbuffer
|
||||
this.initColorbuffer();
|
||||
|
||||
// depthbuffer
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, this.renderbuffer);
|
||||
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16,
|
||||
this.framebuffer.width, this.framebuffer.height);
|
||||
|
||||
// WEBGL_depth_texture not supported in firefox/ANGLE
|
||||
// gl.bindTexture(gl.TEXTURE_2D, this.depthTexture.glid);
|
||||
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
// gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT, this.framebuffer.width, this.framebuffer.height, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_BYTE, null);
|
||||
|
||||
|
||||
// assemble buffers
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
|
||||
gl.TEXTURE_2D, this.texture.glid, 0);
|
||||
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT,
|
||||
gl.RENDERBUFFER, this.renderbuffer);
|
||||
|
||||
// WEBGL_depth_texture not supported in firefox/ANGLE
|
||||
// gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, this.depthTexture.glid, 0);
|
||||
|
||||
this.checkBuffer();
|
||||
|
||||
gl.bindTexture(gl.TEXTURE_2D, null);
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
};
|
||||
|
||||
/**
|
||||
* initializes the colourbuffer that'll be used as COLOR_ATTACHMENT0
|
||||
*/
|
||||
Framebuffer.prototype.initColorbuffer = function() {
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.texture.glid);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.framebuffer.width,
|
||||
this.framebuffer.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
||||
};
|
||||
|
||||
/**
|
||||
* check if framebuffer was successfully created. Throws an exception if the
|
||||
* buffer is invalid.
|
||||
*/
|
||||
Framebuffer.prototype.checkBuffer = function checkBuffer() {
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
|
||||
|
||||
var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
|
||||
switch (status) {
|
||||
case gl.FRAMEBUFFER_COMPLETE:
|
||||
break;
|
||||
case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
||||
console.log("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
|
||||
throw "";
|
||||
case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
||||
console.log("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
|
||||
throw "";
|
||||
case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
|
||||
console.log("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");
|
||||
throw "";
|
||||
case gl.FRAMEBUFFER_UNSUPPORTED:
|
||||
console.log("Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED");
|
||||
throw "";
|
||||
default:
|
||||
console.log("Incomplete framebuffer: " + status);
|
||||
throw "";
|
||||
}
|
||||
};
|
||||
|
||||
Framebuffer.bindDefault = function() {
|
||||
Framebuffer.activeBuffer = Framebuffer.getSystemBuffer();
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
};
|
||||
|
||||
/**
|
||||
* binds this framebuffer which makes it the target for all drawCalls and
|
||||
* framebuffer related calls.
|
||||
*/
|
||||
Framebuffer.prototype.bind = function() {
|
||||
Framebuffer.activeBuffer = this;
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Texture}
|
||||
* texture
|
||||
* @param {[x,y]}
|
||||
* start
|
||||
* @param {[x,y]}
|
||||
* end
|
||||
*
|
||||
* @example drawTexture(abc, [-1,-1], [1,1])
|
||||
*/
|
||||
Framebuffer.prototype.drawTexture = function(texture, start, end) {
|
||||
this.bind();
|
||||
|
||||
var mat = ShaderManager.getShader("drawTexture");
|
||||
gl.useProgram(mat.program);
|
||||
|
||||
this.updateScreenQuad(start, end);
|
||||
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// uniforms
|
||||
if (this.framebuffer == null) {
|
||||
var canvas = document.getElementById("canvas");
|
||||
gl.uniform1f(mat.uniforms.uWidth, canvas.width);
|
||||
gl.uniform1f(mat.uniforms.uHeight, canvas.height);
|
||||
} else {
|
||||
gl.uniform1f(mat.uniforms.uWidth, this.width);
|
||||
gl.uniform1f(mat.uniforms.uHeight, this.height);
|
||||
}
|
||||
// texture
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, texture.glid);
|
||||
gl.uniform1i(mat.uniforms.uTexture, 0);
|
||||
// depth
|
||||
gl.activeTexture(gl.TEXTURE1);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.renderbuffer);
|
||||
gl.uniform1i(mat.uniforms.uDepth, 0);
|
||||
|
||||
// vertex attributes
|
||||
gl.enableVertexAttribArray(mat.attributes.aVertexPosition);
|
||||
gl.enableVertexAttribArray(mat.attributes.aTexcoords);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.vbo);
|
||||
gl.vertexAttribPointer(mat.attributes.aVertexPosition, 3, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordvbo);
|
||||
gl.vertexAttribPointer(mat.attributes.aTexcoords, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.disable(gl.DEPTH_TEST);
|
||||
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
||||
|
||||
gl.disableVertexAttribArray(mat.attributes.aVertexPosition);
|
||||
gl.disableVertexAttribArray(mat.attributes.aTexcoords);
|
||||
};
|
||||
|
||||
/**
|
||||
* draws a quad over the whole framebuffer using the provided material.
|
||||
*
|
||||
* @param {Material}
|
||||
* mat
|
||||
*/
|
||||
Framebuffer.prototype.drawFullscreenQuad = function(mat) {
|
||||
|
||||
gl.useProgram(mat.program);
|
||||
|
||||
this.updateScreenQuad([ -1, -1 ], [ 1, 1 ]);
|
||||
|
||||
// vertex attributes
|
||||
gl.enableVertexAttribArray(mat.attributes.aVertexPosition);
|
||||
gl.enableVertexAttribArray(mat.attributes.aTexcoord);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.vbo);
|
||||
gl.vertexAttribPointer(mat.attributes.aVertexPosition, 3, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordvbo);
|
||||
gl.vertexAttribPointer(mat.attributes.aTexcoord, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
||||
|
||||
gl.disableVertexAttribArray(mat.attributes.aVertexPosition);
|
||||
gl.disableVertexAttribArray(mat.attributes.aTexcoord);
|
||||
};
|
||||
@ -1,39 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {int} width
|
||||
* @param {int} height
|
||||
*
|
||||
* @class Framebuffer with rgba format and floating point precision for each component.
|
||||
* requires OES_texture_float extension.
|
||||
*
|
||||
* @augments Framebuffer
|
||||
*/
|
||||
function FramebufferFloat32(width, height){
|
||||
Framebuffer.call(this, width, height);
|
||||
}
|
||||
|
||||
FramebufferFloat32.prototype = new Framebuffer(inheriting);
|
||||
FramebufferFloat32.base = Framebuffer.prototype;
|
||||
|
||||
/**
|
||||
* creates a colourbuffer with gl.FLOAT precision
|
||||
*/
|
||||
FramebufferFloat32.prototype.initColorbuffer = function(){
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.texture.glid);
|
||||
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.framebuffer.width, this.framebuffer.height, 0, gl.RGBA, gl.FLOAT, null);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
|
||||
function KeyCodes(){}
|
||||
|
||||
KeyCodes.SPACE = 32;
|
||||
KeyCodes.M = 77;
|
||||
KeyCodes.NUMBER_1 = 49;
|
||||
KeyCodes.NUMBER_2 = 50;
|
||||
KeyCodes.NUMBER_3 = 51;
|
||||
KeyCodes.f = 102;
|
||||
KeyCodes.c = 99;
|
||||
|
||||
KeyCodes.A = 65;
|
||||
KeyCodes.S = 83;
|
||||
KeyCodes.D = 68;
|
||||
KeyCodes.W = 87;
|
||||
KeyCodes.M = 77;
|
||||
|
||||
KeyCodes.LEFT_ARROW = 37;
|
||||
KeyCodes.UP_ARROW = 38;
|
||||
KeyCodes.RIGHT_ARROW = 39;
|
||||
KeyCodes.DOWN_ARROW = 40;
|
||||
@ -1,46 +0,0 @@
|
||||
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
function KeyListener(){
|
||||
|
||||
}
|
||||
|
||||
KeyListener.pressedKeys = new Array();
|
||||
|
||||
KeyListener.listener = new Array();
|
||||
|
||||
KeyListener.addListener = function(listener){
|
||||
if(!KeyListener.listener.contains(listener)){
|
||||
KeyListener.listener.push(listener);
|
||||
}
|
||||
};
|
||||
|
||||
KeyListener.removeListener = function(listener){
|
||||
KeyListener.listener.remove(listener);
|
||||
};
|
||||
|
||||
KeyListener.keyDown = function(event){
|
||||
if(!KeyListener.pressedKeys.contains(event.which)){
|
||||
KeyListener.pressedKeys.push(event.which);
|
||||
}
|
||||
|
||||
for(var i = 0; i < KeyListener.listener.length; i++){
|
||||
KeyListener.listener[i].invokeKeyDown(event);
|
||||
}
|
||||
|
||||
event.stopPropagation();
|
||||
};
|
||||
|
||||
KeyListener.keyUp = function(event){
|
||||
KeyListener.pressedKeys.remove(event.which);
|
||||
for(var i = 0; i < KeyListener.listener.length; i++){
|
||||
KeyListener.listener[i].invokeKeyUp(event);
|
||||
}
|
||||
};
|
||||
|
||||
KeyListener.keyPress = function(event){
|
||||
for(var i = 0; i < KeyListener.listener.length; i++){
|
||||
KeyListener.listener[i].invokeKeyPress(event);
|
||||
}
|
||||
};
|
||||
@ -23,7 +23,7 @@ function LRU(){
|
||||
// a list of all items in the lru list
|
||||
this.items = {};
|
||||
this.elements = 0;
|
||||
this.byteSize = 0;
|
||||
this.numPoints = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,7 +61,7 @@ LRU.prototype.touch = function(node){
|
||||
if(this.first === null){
|
||||
this.first = item;
|
||||
}
|
||||
this.byteSize += node.sizeInBytes();
|
||||
this.numPoints += node.numPoints;
|
||||
}else{
|
||||
// update in list
|
||||
item = this.items[node.id];
|
||||
@ -95,7 +95,7 @@ LRU.prototype.touch = function(node){
|
||||
* removes the least recently used item from the list and returns it.
|
||||
* if the list was empty, null will be returned.
|
||||
*/
|
||||
LRU.prototype.removeLRUItem = function removeLRUItem(){
|
||||
LRU.prototype.remove = function remove(){
|
||||
if(this.first === null){
|
||||
return null;
|
||||
}
|
||||
@ -112,7 +112,7 @@ LRU.prototype.removeLRUItem = function removeLRUItem(){
|
||||
|
||||
delete this.items[lru.node.id];
|
||||
this.elements--;
|
||||
this.byteSize -= lru.node.sizeInBytes();
|
||||
this.numPoints -= lru.node.numPoints;
|
||||
|
||||
// Logger.info("removed node: " + lru.node.id);
|
||||
return lru.node;
|
||||
@ -1,25 +0,0 @@
|
||||
/*
|
||||
* @license
|
||||
* Copyright (c) 2011-2014, Markus Schuetz
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
11
src/Mouse.js
@ -1,11 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
function Mouse(){
|
||||
|
||||
}
|
||||
|
||||
Mouse.left = 0;
|
||||
Mouse.middle = 1;
|
||||
Mouse.right = 2;
|
||||
@ -1,80 +0,0 @@
|
||||
|
||||
/**
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
function MouseListener(){
|
||||
}
|
||||
|
||||
MouseListener.x = null;
|
||||
MouseListener.y = null;
|
||||
MouseListener.pressedKeys = new Array();
|
||||
|
||||
MouseListener.listener = new Array();
|
||||
|
||||
MouseListener.addListener = function(listener){
|
||||
if(!MouseListener.listener.contains(listener)){
|
||||
MouseListener.listener.push(listener);
|
||||
}
|
||||
};
|
||||
|
||||
MouseListener.removeListener = function(listener){
|
||||
MouseListener.listener.remove(listener);
|
||||
};
|
||||
|
||||
MouseListener.mouseDown = function(event){
|
||||
MouseListener.pressedKeys.push(event.button);
|
||||
|
||||
for(var i = 0; i < MouseListener.listener.length; i++){
|
||||
MouseListener.listener[i].invokeMouseDown(event);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
MouseListener.mouseUp = function(event){
|
||||
MouseListener.pressedKeys.remove(event.button);
|
||||
for(var i = 0; i < MouseListener.listener.length; i++){
|
||||
MouseListener.listener[i].invokeMouseUp(event);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
MouseListener.mouseWheel = function(event){
|
||||
var evt=window.event || event; //equalize event object
|
||||
var delta=evt.detail? evt.detail*(-120) : evt.wheelDelta; //check for detail first so Opera uses that instead of wheelDelta
|
||||
|
||||
var ret = true;
|
||||
for(var i = 0; i < MouseListener.listener.length; i++){
|
||||
ret = ret && MouseListener.listener[i].invokeMouseWheel(delta, event);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
MouseListener.mouseMove = function(event){
|
||||
if(MouseListener.x == null){
|
||||
MouseListener.x = event.screenX;
|
||||
MouseListener.y = event.screenY;
|
||||
}
|
||||
|
||||
var diffX = event.screenX - MouseListener.x;
|
||||
var diffY = event.screenY - MouseListener.y;
|
||||
MouseListener.x = event.screenX;
|
||||
MouseListener.y = event.screenY;
|
||||
|
||||
|
||||
|
||||
if(MouseListener.pressedKeys.length > 0){
|
||||
for(var i = 0; i < MouseListener.listener.length; i++){
|
||||
MouseListener.listener[i].invokeMouseDrag(event, MouseListener.pressedKeys, diffX, diffY);
|
||||
}
|
||||
}else{
|
||||
for(var i = 0; i < MouseListener.listener.length; i++){
|
||||
MouseListener.listener[i].invokeMouseMove(event, diffX, diffY);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
};
|
||||
227
src/PointCloudOctree.js
Normal file
@ -0,0 +1,227 @@
|
||||
|
||||
|
||||
/**
|
||||
* Stands in place for invisible or unloaded octree nodes.
|
||||
* If a proxy node becomes visible and its geometry has not been loaded,
|
||||
* loading will begin.
|
||||
* If it is visible and the geometry has been loaded, the proxy node will
|
||||
* be replaced with a point cloud node (THREE.PointCloud as of now)
|
||||
*/
|
||||
Potree.PointCloudOctreeProxyNode = function(geometryNode){
|
||||
THREE.Object3D.call( this );
|
||||
|
||||
this.geometryNode = geometryNode;
|
||||
this.boundingBox = geometryNode.boundingBox;
|
||||
this.name = geometryNode.name;
|
||||
this.level = geometryNode.level;
|
||||
this.numPoints = geometryNode.numPoints;
|
||||
}
|
||||
|
||||
Potree.PointCloudOctreeProxyNode.prototype = Object.create(THREE.Object3D.prototype);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Potree.PointCloudOctree = function(geometry, material){
|
||||
THREE.Object3D.call( this );
|
||||
|
||||
Potree.PointCloudOctree.lru = Potree.PointCloudOctree.lru || new LRU();
|
||||
|
||||
this.pcoGeometry = geometry;
|
||||
this.boundingBox = this.pcoGeometry.boundingBox;
|
||||
this.material = material;
|
||||
this.maxVisibleNodes = 2000;
|
||||
this.maxVisiblePoints = 20*1000*1000;
|
||||
this.level = 0;
|
||||
|
||||
this.LODDistance = 20;
|
||||
this.LODFalloff = 1.3;
|
||||
this.LOD = 4;
|
||||
|
||||
|
||||
var rootProxy = new Potree.PointCloudOctreeProxyNode(this.pcoGeometry.root);
|
||||
this.add(rootProxy);
|
||||
}
|
||||
|
||||
Potree.PointCloudOctree.prototype = Object.create(THREE.Object3D.prototype);
|
||||
|
||||
Potree.PointCloudOctree.prototype.update = function(camera){
|
||||
this.numVisibleNodes = 0;
|
||||
this.numVisiblePoints = 0;
|
||||
var frustum = new THREE.Frustum();
|
||||
frustum.setFromMatrix( new THREE.Matrix4().multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse ) );
|
||||
|
||||
// check visibility
|
||||
var stack = [];
|
||||
stack.push(this);
|
||||
while(stack.length > 0){
|
||||
var object = stack.shift();
|
||||
|
||||
var boxWorld = Potree.utils.computeTransformedBoundingBox(object.boundingBox, object.matrixWorld);
|
||||
var camWorldPos = new THREE.Vector3().setFromMatrixPosition( camera.matrixWorld );
|
||||
var distance = boxWorld.center().distanceTo(camWorldPos);
|
||||
var radius = boxWorld.size().length() * 0.5;
|
||||
|
||||
var visible = true;
|
||||
visible = visible && frustum.intersectsBox(boxWorld);
|
||||
if(object.level > 1){
|
||||
visible = visible && radius / distance > (1 / this.LOD);
|
||||
visible = visible && (this.numVisiblePoints + object.numPoints < Potree.pointLoadLimit);
|
||||
visible = visible && (this.numVisibleNodes <= this.maxVisibleNodes);
|
||||
visible = visible && (this.numVisiblePoints <= this.maxVisiblePoints);
|
||||
}else{
|
||||
visible = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
object.visible = visible;
|
||||
|
||||
if(!visible){
|
||||
this.hideDescendants(object);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(object instanceof THREE.PointCloud){
|
||||
this.numVisibleNodes++;
|
||||
this.numVisiblePoints += object.numPoints;
|
||||
Potree.PointCloudOctree.lru.touch(object);
|
||||
}else if (object instanceof Potree.PointCloudOctreeProxyNode) {
|
||||
this.replaceProxy(object);
|
||||
}
|
||||
|
||||
for(var i = 0; i < object.children.length; i++){
|
||||
stack.push(object.children[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Potree.PointCloudOctree.prototype.replaceProxy = function(proxy){
|
||||
|
||||
var geometryNode = proxy.geometryNode;
|
||||
if(geometryNode.loaded === true){
|
||||
var geometry = geometryNode.geometry;
|
||||
var node = new THREE.PointCloud(geometry, this.material);
|
||||
node.name = proxy.name;
|
||||
node.level = proxy.level;
|
||||
node.numPoints = proxy.numPoints;
|
||||
node.boundingBox = geometry.boundingBox;
|
||||
node.pcoGeometry = geometryNode;
|
||||
var parent = proxy.parent;
|
||||
parent.remove(proxy);
|
||||
parent.add(node);
|
||||
|
||||
for(var i = 0; i < 8; i++){
|
||||
if(geometryNode.children[i] !== undefined){
|
||||
var child = geometryNode.children[i];
|
||||
var childProxy = new Potree.PointCloudOctreeProxyNode(child);
|
||||
node.add(childProxy);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
geometryNode.load();
|
||||
}
|
||||
}
|
||||
|
||||
Potree.PointCloudOctree.prototype.hideDescendants = function(object){
|
||||
var stack = [];
|
||||
for(var i = 0; i < object.children.length; i++){
|
||||
var child = object.children[i];
|
||||
if(child.visible){
|
||||
stack.push(child);
|
||||
}
|
||||
}
|
||||
|
||||
while(stack.length > 0){
|
||||
var object = stack.shift();
|
||||
|
||||
object.visible = false;
|
||||
|
||||
for(var i = 0; i < object.children.length; i++){
|
||||
var child = object.children[i];
|
||||
if(child.visible){
|
||||
stack.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Potree.PointCloudOctree.prototype.moveToOrigin = function(){
|
||||
this.position.set(0,0,0);
|
||||
this.updateMatrixWorld();
|
||||
var box = this.boundingBox;
|
||||
var transform = this.matrixWorld;
|
||||
var tBox = Potree.utils.computeTransformedBoundingBox(box, transform);
|
||||
this.position.set(0,0,0).sub(tBox.center());
|
||||
}
|
||||
|
||||
Potree.PointCloudOctree.prototype.moveToGroundPlane = function(){
|
||||
this.updateMatrixWorld();
|
||||
var box = this.boundingBox;
|
||||
var transform = this.matrixWorld;
|
||||
var tBox = Potree.utils.computeTransformedBoundingBox(box, transform);
|
||||
this.position.y += -tBox.min.y;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* amount: minimum number of points to remove
|
||||
*/
|
||||
Potree.PointCloudOctree.disposeLeastRecentlyUsed = function(amount){
|
||||
|
||||
|
||||
var freed = 0;
|
||||
do{
|
||||
var node = this.lru.first.node;
|
||||
var parent = node.parent;
|
||||
var geometry = node.geometry;
|
||||
var pcoGeometry = node.pcoGeometry;
|
||||
var proxy = new Potree.PointCloudOctreeProxyNode(pcoGeometry);
|
||||
|
||||
var result = Potree.PointCloudOctree.disposeNode(node);
|
||||
freed += result.freed;
|
||||
|
||||
parent.add(proxy);
|
||||
|
||||
if(result.numDeletedNodes == 0){
|
||||
break;
|
||||
}
|
||||
}while(freed < amount);
|
||||
}
|
||||
|
||||
Potree.PointCloudOctree.disposeNode = function(node){
|
||||
|
||||
var freed = 0;
|
||||
var numDeletedNodes = 0;
|
||||
var descendants = [];
|
||||
|
||||
node.traverse(function(object){
|
||||
descendants.push(object);
|
||||
});
|
||||
|
||||
for(var i = 0; i < descendants.length; i++){
|
||||
var descendant = descendants[i];
|
||||
if(descendant instanceof THREE.PointCloud){
|
||||
freed += descendant.pcoGeometry.numPoints;
|
||||
descendant.pcoGeometry.dispose();
|
||||
descendant.geometry.dispose();
|
||||
Potree.PointCloudOctree.lru.remove(descendant);
|
||||
numDeletedNodes++;
|
||||
}
|
||||
}
|
||||
|
||||
Potree.PointCloudOctree.lru.remove(node);
|
||||
node.parent.remove(node);
|
||||
|
||||
return {
|
||||
"freed": freed,
|
||||
"numDeletedNodes": numDeletedNodes
|
||||
};
|
||||
}
|
||||
99
src/PointCloudOctreeGeometry.js
Normal file
@ -0,0 +1,99 @@
|
||||
|
||||
|
||||
|
||||
Potree.PointCloudOctreeGeometry = function(){
|
||||
Potree.PointCloudOctree.lru = Potree.PointCloudOctree.lru || new LRU();
|
||||
|
||||
this.numNodesLoading = 0;
|
||||
}
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode = function(name, pcoGeometry, boundingBox){
|
||||
this.name = name;
|
||||
this.index = parseInt(name.charAt(name.length-1));
|
||||
this.pcoGeometry = pcoGeometry;
|
||||
this.boundingBox = boundingBox;
|
||||
this.children = {};
|
||||
this.numPoints = 0;
|
||||
this.level = null;
|
||||
|
||||
}
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.addChild = function(child){
|
||||
this.children[child.index] = child;
|
||||
child.parent = this;
|
||||
}
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.load = function(){
|
||||
if(this.loading === true || this.pcoGeometry.numNodesLoading > 3){
|
||||
return;
|
||||
}
|
||||
|
||||
if(Potree.PointCloudOctree.lru.numPoints + this.numPoints >= Potree.pointLoadLimit){
|
||||
Potree.PointCloudOctree.disposeLeastRecentlyUsed(this.numPoints);
|
||||
}
|
||||
|
||||
|
||||
this.pcoGeometry.numNodesLoading++;
|
||||
this.loading = true;
|
||||
var url = this.pcoGeometry.octreeDir + "/" + this.name;
|
||||
var node = this;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200 || xhr.status === 0) {
|
||||
var buffer = xhr.response;
|
||||
node.bufferLoaded(buffer);
|
||||
} else {
|
||||
console.log('Failed to load file! HTTP status: ' + xhr.status + ", file: " + url);
|
||||
}
|
||||
}
|
||||
};
|
||||
try{
|
||||
xhr.send(null);
|
||||
}catch(e){
|
||||
console.log("fehler beim laden der punktwolke: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.bufferLoaded = function(buffer){
|
||||
//console.log("loaded: " + this.name);
|
||||
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
var numPoints = buffer.byteLength / 16;
|
||||
|
||||
var positions = new Float32Array(numPoints*3);
|
||||
var colors = new Float32Array(numPoints*3);
|
||||
var color = new THREE.Color();
|
||||
|
||||
var fView = new Float32Array(buffer);
|
||||
var uiView = new Uint8Array(buffer);
|
||||
|
||||
for(var i = 0; i < numPoints; i++){
|
||||
positions[3*i] = fView[4*i];
|
||||
positions[3*i+1] = fView[4*i+1];
|
||||
positions[3*i+2] = fView[4*i+2];
|
||||
|
||||
color.setRGB(uiView[16*i+12], uiView[16*i+13], uiView[16*i+14]);
|
||||
colors[3*i] = color.r /255;
|
||||
colors[3*i+1] = color.g / 255;
|
||||
colors[3*i+2] = color.b / 255;
|
||||
}
|
||||
|
||||
geometry.addAttribute('position', new THREE.Float32Attribute(positions, 3));
|
||||
geometry.addAttribute('color', new THREE.Float32Attribute(colors, 3));
|
||||
geometry.boundingBox = this.boundingBox;
|
||||
this.geometry = geometry;
|
||||
this.loaded = true;
|
||||
this.loading = false;
|
||||
this.pcoGeometry.numNodesLoading--;
|
||||
}
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.dispose = function(){
|
||||
delete this.geometry;
|
||||
this.loaded = false;
|
||||
|
||||
//console.log("dispose: " + this.name);
|
||||
}
|
||||
331
src/Potree.js
@ -1,337 +1,10 @@
|
||||
|
||||
|
||||
/**
|
||||
* holds the WebGL context
|
||||
*/
|
||||
var gl = null;
|
||||
//Config.shaderDir="resources/shader";
|
||||
|
||||
/**
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
function Potree(){
|
||||
this.camHandler = null;
|
||||
|
||||
}
|
||||
|
||||
Potree.shaderDir="resources/shader";
|
||||
|
||||
/**
|
||||
* a list of all js files that must be included by Potree
|
||||
*/
|
||||
Potree.includes = [
|
||||
"libs/mjs/mjs.js",
|
||||
"src/extensions/Array.js",
|
||||
"src/extensions/mjs.js",
|
||||
"src/extensions/String.js",
|
||||
"src/extensions/ArrayBuffer.js",
|
||||
"src/extensions/Float32Array.js",
|
||||
"src/utils/utils.js",
|
||||
"src/KeyListener.js",
|
||||
"src/KeyCodes.js",
|
||||
"src/MouseListener.js",
|
||||
"src/Mouse.js",
|
||||
"src/ResourceManager/TextureManager.js",
|
||||
"src/ResourceManager/MaterialManager.js",
|
||||
"src/shader/Shader.js",
|
||||
"src/utils/Plane.js",
|
||||
"src/utils/Frustum.js",
|
||||
"src/rendering/Renderer.js",
|
||||
"src/scenegraph/AABB.js",
|
||||
"src/scenegraph/SceneNode.js",
|
||||
"src/scenegraph/Camera.js",
|
||||
"src/scenegraph/Scene.js",
|
||||
"src/scenegraph/MeshNode.js",
|
||||
"src/scenegraph/Light.js",
|
||||
"src/scenegraph/Sphere.js",
|
||||
"src/objects/Mesh.js",
|
||||
"src/navigation/CamHandler.js",
|
||||
"src/navigation/FreeFlightCamHandler.js",
|
||||
"src/navigation/OrbitCamHandler.js",
|
||||
"src/Framebuffer.js",
|
||||
"src/FramebufferFloat32.js",
|
||||
"src/ResourceManager/ShaderManager.js",
|
||||
"src/utils/MeshUtils.js",
|
||||
"src/scenegraph/PointcloudOctreeSceneNode.js",
|
||||
"src/scenegraph/PointCloudSceneNode.js",
|
||||
"src/objects/PointCloud.js",
|
||||
"src/objects/PointcloudOctreeNode.js",
|
||||
"src/objects/PointcloudOctree.js",
|
||||
"src/materials/Material.js",
|
||||
"src/materials/WeightedPointSizeMaterial.js",
|
||||
"src/materials/FixedPointSizeMaterial.js",
|
||||
"src/materials/PointCloudMaterial.js",
|
||||
"src/materials/FlatMaterial.js",
|
||||
"src/materials/PhongMaterial.js",
|
||||
"src/materials/FilteredSplatsMaterial.js",
|
||||
"src/materials/GaussFillMaterial.js",
|
||||
"src/loader/POCLoader.js",
|
||||
"src/loader/PointAttributes.js",
|
||||
"src/loader/PlyLoader.js",
|
||||
"src/utils/LRU.js",
|
||||
];
|
||||
|
||||
Potree.Settings = {};
|
||||
|
||||
//settings
|
||||
Potree.Settings.showBoundingBoxes = false;
|
||||
Potree.Settings.LOD = true;
|
||||
Potree.Settings.LODMultiplicator = 10.0;
|
||||
Potree.Settings.pointSize = 1;
|
||||
Potree.Settings.backgroundColor = [0,0,0,1];//[ 0.3, 0.3, 0.4, 1 ];
|
||||
Potree.Settings.showGrid = false;
|
||||
Potree.Settings.frustumCulling = true;
|
||||
|
||||
//other
|
||||
Potree.gridSceneNode = null;
|
||||
Potree.canvas = null;
|
||||
Potree.initialized = false;
|
||||
Potree.updateHandlers = [];
|
||||
Potree.drawHandlers = [];
|
||||
var renderer = null;
|
||||
Potree.fpsHistory = [];
|
||||
Potree.fps = 0;
|
||||
|
||||
|
||||
/**
|
||||
* includes the javascript file at {path} by adding a script tag to the document.
|
||||
*
|
||||
* @param path Potree library path
|
||||
* @returns
|
||||
*/
|
||||
Potree.importScripts = function(path){
|
||||
var importText = "";
|
||||
for(var i = 0; i < Potree.includes.length; i++){
|
||||
var include = Potree.includes[i];
|
||||
//document.write("<scri" + "pt type=\"text/javascript\" src=\"" + path + "/" +include+"\"></scri" + "pt>");
|
||||
importText += "<scri" + "pt type=\"text/javascript\" src=\"" + path + "/" +include+"\"></scri" + "pt>\n";
|
||||
}
|
||||
document.write(importText);
|
||||
};
|
||||
|
||||
|
||||
Potree.isWebGLEnabled = function(canvas){
|
||||
var names = [ "webgl", "experimental-webgl", "moz-webgl", "webkit-3d" ];
|
||||
for ( var i = 0; names.length > i; i++) {
|
||||
try {
|
||||
gl = canvas.getContext(names[i], {
|
||||
antialias : false
|
||||
});
|
||||
if (gl) {
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
if (!gl) {
|
||||
console.log("No known OpenGL context detected! Is it enabled?");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param canvas the canvas element for rendering.
|
||||
* Potree can only be intialized once.
|
||||
* @returns
|
||||
*/
|
||||
Potree.init = function(canvas) {
|
||||
if(Potree.initialized){
|
||||
console.log("Potree has already been initialized");
|
||||
return true;
|
||||
}
|
||||
|
||||
Potree.canvas = canvas;
|
||||
Potree.currentScene = new Scene("default");
|
||||
|
||||
if(!Potree.initGL()){
|
||||
// init failed -> display error message
|
||||
var soSorry = document.createElement("div");
|
||||
var msg = "<br>Could not create a WebGL context. ";
|
||||
msg += "<br><br>Try using <a href='http://www.mozilla.org' style='color: red'>Firefox</a> ";
|
||||
msg += "or <a href='www.google.com/chrome/' style='color: red'>Chrome</a>.";
|
||||
msg += "<br>Other WebGL enabled browsers are not supported but they might work as well.";
|
||||
soSorry.innerHTML = msg;
|
||||
soSorry.style.fontSize = "large";
|
||||
soSorry.style.fontWeight = "bold";
|
||||
soSorry.style.color = "#FFF";
|
||||
soSorry.style.textShadow = "black 0 0 4px, black 0 0 4px, black 0 0 4px, black 0 0 4px, black 0 0 4px, black 0 0 4px";
|
||||
soSorry.style.textAlign = "center";
|
||||
soSorry.style.verticalAlign = "bottom";
|
||||
soSorry.style.height = "100%";
|
||||
canvas.parentNode.replaceChild(soSorry, canvas);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
{// register mouse and key listener
|
||||
var mousewheelevt=(/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel"; //FF doesn't recognize mousewheel as of FF3.x
|
||||
if (document.attachEvent){ //if IE (and Opera depending on user setting)
|
||||
document.attachEvent("on"+mousewheelevt,MouseListener.mouseWheel);
|
||||
} else if (document.addEventListener){ //WC3 browsers
|
||||
document.addEventListener(mousewheelevt, MouseListener.mouseWheel, false);
|
||||
}
|
||||
document.onkeydown = KeyListener.keyDown;
|
||||
document.onkeyup = KeyListener.keyUp;
|
||||
document.onkeypress = KeyListener.keyPress;
|
||||
document.onmousedown = MouseListener.mouseDown;
|
||||
document.onmouseup = MouseListener.mouseUp;
|
||||
document.onmousemove = MouseListener.mouseMove;
|
||||
}
|
||||
|
||||
|
||||
{// install cam handler
|
||||
Potree.camHandler = new FreeFlightCamHandler(Potree.currentScene.activeCamera);
|
||||
MouseListener.addListener(Potree.camHandler);
|
||||
canvas.onfocus = function(){
|
||||
KeyListener.addListener(Potree.camHandler);
|
||||
MouseListener.addListener(Potree.camHandler);
|
||||
};
|
||||
|
||||
canvas.onblur= function(){
|
||||
KeyListener.removeListener(Potree.camHandler);
|
||||
MouseListener.removeListener(Potree.camHandler);
|
||||
};
|
||||
}
|
||||
|
||||
Potree.initialized = true;
|
||||
|
||||
// shaders
|
||||
var drawTextureShader = new Shader("drawTexture", "drawTexture.vs", "drawTexture.fs");
|
||||
|
||||
// materials
|
||||
var pointCloudMaterial = new PointCloudMaterial("pointCloud");
|
||||
var defaultMaterial = new FlatMaterial("default");
|
||||
|
||||
// Potree.mainLoop();
|
||||
setInterval(Potree.mainLoop, 33);
|
||||
|
||||
return Potree.initialized;
|
||||
};
|
||||
|
||||
Object.defineProperty(Potree, "camHandler", {
|
||||
get: function(){
|
||||
return Potree._camHandler;
|
||||
},
|
||||
set: function(camHandler){
|
||||
KeyListener.removeListener(Potree._camHandler);
|
||||
MouseListener.removeListener(Potree._camHandler);
|
||||
Potree._camHandler = camHandler;
|
||||
KeyListener.addListener(Potree._camHandler);
|
||||
MouseListener.addListener(Potree._camHandler);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* creates the WebGL context
|
||||
*
|
||||
*/
|
||||
Potree.initGL = function() {
|
||||
viewportWidth = Potree.canvas.width;
|
||||
viewportHeight = Potree.canvas.height;
|
||||
|
||||
var names = [ "webgl", "experimental-webgl", "moz-webgl", "webkit-3d" ];
|
||||
for ( var i = 0; names.length > i; i++) {
|
||||
try {
|
||||
gl = Potree.canvas.getContext(names[i], {
|
||||
antialias : false
|
||||
});
|
||||
if (gl) {
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
if (!gl) {
|
||||
console.log("No known OpenGL context detected! Is it enabled?");
|
||||
return false;
|
||||
}
|
||||
|
||||
// basic settings
|
||||
var cColor = Potree.Settings.backgroundColor;
|
||||
gl.clearColor(cColor.r, cColor.g, cColor.b, cColor.a);
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* draws a frame to the canvas
|
||||
*/
|
||||
Potree.draw = function() {
|
||||
if(renderer == null){
|
||||
renderer = new Renderer(Potree.currentScene, Framebuffer.getSystemBuffer());
|
||||
}
|
||||
|
||||
Potree.canvas.width = Potree.canvas.clientWidth;
|
||||
Potree.canvas.height = Potree.canvas.clientHeight;
|
||||
|
||||
var cam = renderer.scene.activeCamera;
|
||||
cam.aspectRatio = Potree.canvas.clientWidth / Potree.canvas.clientHeight;
|
||||
renderer.viewport(0, 0, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
renderer.render();
|
||||
|
||||
for(var i = 0; i < Potree.drawHandlers.length; i++) {
|
||||
var drawHandler = Potree.drawHandlers[i];
|
||||
drawHandler();
|
||||
}
|
||||
};
|
||||
|
||||
Potree.mainLoop = function mainLoop(){
|
||||
Potree.calculateTimeSinceLastFrame();
|
||||
|
||||
Potree.update(timeSinceLastFrame);
|
||||
Potree.draw();
|
||||
|
||||
// with 0ms, interaction becomes a lot slower in firefox.
|
||||
// setTimeout(mainLoop, 10);
|
||||
};
|
||||
|
||||
var lastLoopTime = null;
|
||||
var timeSinceLastFrame = null;
|
||||
Potree.calculateTimeSinceLastFrame = function calculateTimeSinceLastFrame(){
|
||||
var newDrawTime = new Date().getTime();
|
||||
if (lastLoopTime != null) {
|
||||
timeSinceLastFrame = (newDrawTime - lastLoopTime) / 1000.0;
|
||||
}else{
|
||||
timeSinceLastFrame = 0;
|
||||
}
|
||||
lastLoopTime = new Date().getTime();
|
||||
|
||||
};
|
||||
|
||||
|
||||
Potree.update = function update(time){
|
||||
|
||||
var i;
|
||||
var fps = 1 / time;
|
||||
|
||||
Potree.fpsHistory.push(fps);
|
||||
if(Potree.fpsHistory.length > 10){
|
||||
Potree.fpsHistory.splice(0, 1);
|
||||
}
|
||||
var mean = 0;
|
||||
for(i = 0; i < Potree.fpsHistory.length; i++){
|
||||
mean += Potree.fpsHistory[i];
|
||||
}
|
||||
mean = mean / Potree.fpsHistory.length;
|
||||
Potree.fps = mean.toFixed(2);
|
||||
|
||||
Potree.currentScene.rootNode.addTime(time);
|
||||
PointcloudOctreeNode.nodesLoadedThisFrame = 0;
|
||||
|
||||
Potree.camHandler.addTime(time);
|
||||
|
||||
for(i = 0; i < Potree.updateHandlers.length; i++) {
|
||||
var updateHandler = Potree.updateHandlers[i];
|
||||
updateHandler(time);
|
||||
}
|
||||
};
|
||||
Potree.pointLoadLimit = 50*1000*1000;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,34 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* keeps track of all material instances.
|
||||
* materials register themselves upon creation.
|
||||
*/
|
||||
function MaterialManager(){
|
||||
|
||||
}
|
||||
|
||||
MaterialManager.materials = new Array();
|
||||
|
||||
MaterialManager.addMaterial = function(material){
|
||||
if(MaterialManager.getMaterial(material.name) != null){
|
||||
var message= "material has already been created: " + material.name;
|
||||
Logger.error(message);
|
||||
throw message;
|
||||
}
|
||||
|
||||
this.materials.push(material);
|
||||
};
|
||||
|
||||
MaterialManager.getMaterial = function(name){
|
||||
for(var i = 0; i < this.materials.length; i++){
|
||||
var material = this.materials[i];
|
||||
if(material.name === name){
|
||||
return material;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
@ -1,18 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
function MeshManager(){
|
||||
|
||||
}
|
||||
|
||||
MeshManager.getMesh = function(name){
|
||||
|
||||
}
|
||||
|
||||
MeshManager.getMeshFileContent = function(name){
|
||||
var url = Config.meshDir + "/" + name;
|
||||
|
||||
return load_binary_resource(url);
|
||||
}
|
||||
@ -1,78 +0,0 @@
|
||||
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
function ShaderManager() {
|
||||
|
||||
}
|
||||
|
||||
ShaderManager.vertexShader = new Object();
|
||||
ShaderManager.fragmentShader = new Object();
|
||||
ShaderManager.shader = new Array();
|
||||
|
||||
ShaderManager.loadVertexShader = function(name, source) {
|
||||
var vertexShader = ShaderManager.loadShader(name, gl.VERTEX_SHADER, source);
|
||||
ShaderManager.vertexShader[name] = vertexShader;
|
||||
};
|
||||
|
||||
ShaderManager.loadFragmentShader = function(name, source) {
|
||||
var fragmentShader = ShaderManager.loadShader(name, gl.FRAGMENT_SHADER, source);
|
||||
ShaderManager.fragmentShader[name] = fragmentShader;
|
||||
};
|
||||
|
||||
ShaderManager.getVertexShader = function(name) {
|
||||
if(ShaderManager.vertexShader[name] == null){
|
||||
ShaderManager.loadVertexShader(name, ShaderManager.getShaderSource(name));
|
||||
}
|
||||
return ShaderManager.vertexShader[name];
|
||||
};
|
||||
|
||||
ShaderManager.getFragmentShader = function(name) {
|
||||
if(ShaderManager.fragmentShader[name] == null){
|
||||
ShaderManager.loadFragmentShader(name, ShaderManager.getShaderSource(name));
|
||||
}
|
||||
return ShaderManager.fragmentShader[name];
|
||||
};
|
||||
|
||||
ShaderManager.loadShader = function(name, shaderType, shaderSource) {
|
||||
var shader = gl.createShader(shaderType);
|
||||
if (!shader) {
|
||||
return null;
|
||||
}
|
||||
gl.shaderSource(shader, shaderSource);
|
||||
gl.compileShader(shader);
|
||||
|
||||
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
||||
var message = "compiling shader '" + name + "' failed: " + gl.getShaderInfoLog(shader);
|
||||
alert(message);
|
||||
return null;
|
||||
}
|
||||
|
||||
return shader;
|
||||
};
|
||||
|
||||
ShaderManager.getShaderSource = function(name){
|
||||
var url = Potree.shaderDir + "/" + name;
|
||||
|
||||
return load_binary_resource(url);
|
||||
};
|
||||
|
||||
ShaderManager.addShader = function(shader){
|
||||
if(ShaderManager.getShader(shader.name) !== null){
|
||||
var message= "shader has already been created: " + shader.name;
|
||||
throw message;
|
||||
}
|
||||
|
||||
ShaderManager.shader.push(shader);
|
||||
};
|
||||
|
||||
ShaderManager.getShader = function(name){
|
||||
for(var i = 0; i < this.shader.length; i++){
|
||||
var shader = this.shader[i];
|
||||
if(shader.name === name){
|
||||
return shader;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
@ -1,80 +0,0 @@
|
||||
|
||||
/**
|
||||
* Textures have to be loaded first by invoking loadTexture(). Once its loaded, it can be accessed with getTexture()
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
function TextureManager(){
|
||||
|
||||
}
|
||||
|
||||
TextureManager.textures = new Array();
|
||||
|
||||
|
||||
TextureManager.getTexture = function(name){
|
||||
for(var i = 0; i < this.textures.length; i++){
|
||||
var texture = this.textures[i];
|
||||
if(texture.name === name){
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
* @param name each texture is stored with this unique name. this name can be used to retrieve the texture with getTexture
|
||||
* @returns
|
||||
*/
|
||||
TextureManager.loadTexture = function(source, name){
|
||||
var image = new Image();
|
||||
image.onload = function() {
|
||||
var texture = new Texture();
|
||||
texture.source = source;
|
||||
texture.name = name;
|
||||
texture.image = image;
|
||||
|
||||
gl.bindTexture(gl.TEXTURE_2D, texture.glid);
|
||||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.image);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
gl.bindTexture(gl.TEXTURE_2D, null);
|
||||
|
||||
TextureManager.textures.push(texture);
|
||||
};
|
||||
image.src = source;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
function Texture(){
|
||||
this.glid = gl.createTexture();
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.glid);
|
||||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
||||
gl.bindTexture(gl.TEXTURE_2D, null);
|
||||
}
|
||||
|
||||
|
||||
Texture.prototype.setData = function(data, width, height){
|
||||
var border = 0;
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.glid);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||
gl.texParameteri ( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT ) ;
|
||||
gl.texParameteri ( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT ) ;
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, border, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
||||
gl.bindTexture(gl.TEXTURE_2D, null);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,65 +0,0 @@
|
||||
|
||||
/**
|
||||
* @class extensions for Arrays
|
||||
*
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
Array = Array;
|
||||
|
||||
/**
|
||||
* remove all occurences of element in the array
|
||||
*/
|
||||
Array.prototype.remove=function(element){
|
||||
var index = null;
|
||||
while((index = this.indexOf(element)) !== -1){
|
||||
this.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
||||
Array.prototype.contains = function(element){
|
||||
var index = this.indexOf(element);
|
||||
return index !== -1;
|
||||
};
|
||||
|
||||
Object.defineProperties(Array.prototype, {
|
||||
'x': {
|
||||
get: function(){
|
||||
return this[0];
|
||||
}
|
||||
},
|
||||
'y': {
|
||||
get: function(){
|
||||
return this[1];
|
||||
}
|
||||
},
|
||||
'z': {
|
||||
get: function(){
|
||||
return this[2];
|
||||
}
|
||||
},
|
||||
'w': {
|
||||
get: function(){
|
||||
return this[3];
|
||||
}
|
||||
},
|
||||
'r': {
|
||||
get: function(){
|
||||
return this[0];
|
||||
}
|
||||
},
|
||||
'g': {
|
||||
get: function(){
|
||||
return this[1];
|
||||
}
|
||||
},
|
||||
'b': {
|
||||
get: function(){
|
||||
return this[2];
|
||||
}
|
||||
},
|
||||
'a': {
|
||||
get: function(){
|
||||
return this[3];
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -1,26 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
* extensions for ArrayBuffers
|
||||
*
|
||||
* @author Markus Schuetz
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
ArrayBuffer = ArrayBuffer;
|
||||
|
||||
ArrayBuffer.prototype.subarray = function(offset, length){
|
||||
if(length == null){
|
||||
length = this.byteLength - offset;
|
||||
}
|
||||
|
||||
var sub = new ArrayBuffer(length);
|
||||
var subView = new Int8Array(sub);
|
||||
var thisView = new Int8Array(this);
|
||||
|
||||
for(var i = 0; i < length; i++ ){
|
||||
subView[i] = thisView[offset+i];
|
||||
}
|
||||
|
||||
return sub;
|
||||
};
|
||||
@ -1,79 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
* @class extensions for Float32Arrays
|
||||
*
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
Float32Array = Float32Array;
|
||||
|
||||
/**
|
||||
* @memberOf Float32Array
|
||||
*/
|
||||
Float32Array.prototype.toString = function() {
|
||||
var msg = "";
|
||||
for ( var i = 0; i < this.length; i++) {
|
||||
msg += this[i] + ", ";
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
|
||||
/**
|
||||
* Stellt die Werte des Arrays als NxN Matrix dar wobei N = Sqrt(length)
|
||||
*
|
||||
*/
|
||||
Float32Array.prototype.toMatrixFormString = function() {
|
||||
var msg = "";
|
||||
for ( var i = 0; i < this.length; i++) {
|
||||
if (i !== 0 && (i) % 4 === 0) {
|
||||
msg += "\n";
|
||||
}
|
||||
msg += this[i].toFixed(3) + "\t";
|
||||
// msg += this[i].toPrecision(2) + ", ";
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
|
||||
|
||||
Object.defineProperties(Float32Array.prototype, {
|
||||
'x': {
|
||||
get: function(){
|
||||
return this[0];
|
||||
}
|
||||
},
|
||||
'y': {
|
||||
get: function(){
|
||||
return this[1];
|
||||
}
|
||||
},
|
||||
'z': {
|
||||
get: function(){
|
||||
return this[2];
|
||||
}
|
||||
},
|
||||
'w': {
|
||||
get: function(){
|
||||
return this[3];
|
||||
}
|
||||
},
|
||||
'r': {
|
||||
get: function(){
|
||||
return this[0];
|
||||
}
|
||||
},
|
||||
'g': {
|
||||
get: function(){
|
||||
return this[1];
|
||||
}
|
||||
},
|
||||
'b': {
|
||||
get: function(){
|
||||
return this[2];
|
||||
}
|
||||
},
|
||||
'a': {
|
||||
get: function(){
|
||||
return this[3];
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -1,82 +0,0 @@
|
||||
|
||||
/**
|
||||
* extensions for strings
|
||||
*
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
|
||||
String.prototype.repeat = function(count) {
|
||||
var msg = "";
|
||||
for ( var i = 0; i < count; i++) {
|
||||
msg += this;
|
||||
}
|
||||
|
||||
return msg;
|
||||
};
|
||||
|
||||
/**
|
||||
* fills the string with character to the left, until it reaches the desired length. <br>
|
||||
* if string.length is already >= length, the unmodified string will be returned.
|
||||
*
|
||||
* @param length
|
||||
* @param character
|
||||
* @returns {String}
|
||||
*/
|
||||
String.prototype.leftPad = function(length, character){
|
||||
if(character == null){
|
||||
character = ' ';
|
||||
}
|
||||
|
||||
var padded = "";
|
||||
var diff = length - this.length;
|
||||
if(diff > 0){
|
||||
padded = character.repeat(diff) + this;
|
||||
}
|
||||
|
||||
return padded;
|
||||
};
|
||||
|
||||
/**
|
||||
* fills the string with character to the right, until it reaches the desired length. <br>
|
||||
* if string.length is already >= length, the unmodified string will be returned.
|
||||
*
|
||||
* @param length
|
||||
* @param character
|
||||
* @returns {String}
|
||||
*/
|
||||
String.prototype.rightPad = function(length, character){
|
||||
if(character == null){
|
||||
character = ' ';
|
||||
}
|
||||
|
||||
var padded = "";
|
||||
var diff = length - this.length;
|
||||
if(diff > 0){
|
||||
padded = this + character.repeat(diff);
|
||||
}
|
||||
|
||||
return padded;
|
||||
};
|
||||
|
||||
/**
|
||||
* turns a buffer object into a string.
|
||||
*
|
||||
* @param buffer
|
||||
* @returns {String}
|
||||
*/
|
||||
String.fromBuffer = function(buffer){
|
||||
var string = "";
|
||||
|
||||
var ibuff = new Uint8Array(buffer);
|
||||
for(var i = 0; i < ibuff.length; i++){
|
||||
string += String.fromCharCode(ibuff[i]);
|
||||
}
|
||||
|
||||
return string;
|
||||
};
|
||||
|
||||
Object.defineProperty(String.prototype, 'first', {
|
||||
get: function(){
|
||||
return "lala";
|
||||
}
|
||||
});
|
||||
@ -1,202 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
* extensions for the mjs.js library
|
||||
*
|
||||
* @author Markus Schuetz
|
||||
*
|
||||
* @class extends the mjs V3 class
|
||||
*/
|
||||
V3 = V3;
|
||||
|
||||
/**
|
||||
* @class extends the mjs M4x4 class
|
||||
*/
|
||||
M4x4 = M4x4;
|
||||
|
||||
|
||||
/**
|
||||
* Function: V3.transform
|
||||
*
|
||||
*
|
||||
* Parameters:
|
||||
*
|
||||
* a - the first vector operand
|
||||
* b - the transformation matrix
|
||||
*
|
||||
* Returns:
|
||||
*
|
||||
* transformed vector
|
||||
*/
|
||||
V3.transform = function V3_transform(a, b, r){
|
||||
if(r === undefined){
|
||||
r = new MJS_FLOAT_ARRAY_TYPE(3);
|
||||
}
|
||||
// var r = new MJS_FLOAT_ARRAY_TYPE(3);
|
||||
|
||||
r[0] = a[0] * b[0] + a[1] * b[4] + a[2] * b[8] + b[12];
|
||||
r[1] = a[0] * b[1] + a[1] * b[5] + a[2] * b[9] + b[13];
|
||||
r[2] = a[0] * b[2] + a[1] * b[6] + a[2] * b[10] + b[14];
|
||||
var h = a[0] * b[3] + a[1] * b[7] + a[2] * b[11] + b[15];
|
||||
r[0] = r[0] / h;
|
||||
r[1] = r[1] / h;
|
||||
r[2] = r[2] / h;
|
||||
|
||||
return r;
|
||||
};
|
||||
|
||||
/**
|
||||
* Function: V3.rTransform
|
||||
*
|
||||
*
|
||||
* Parameters:
|
||||
*
|
||||
* a - the first vector operand
|
||||
* b - the transformation matrix
|
||||
*
|
||||
* Returns:
|
||||
*
|
||||
* vector rotated by the matrix. translation is not applied.
|
||||
*/
|
||||
V3.rTransform = function(a, b, r){
|
||||
if(r === undefined){
|
||||
r = new MJS_FLOAT_ARRAY_TYPE(3);
|
||||
}
|
||||
|
||||
r[0] = a[0] * b[0] + a[1] * b[4] + a[2] * b[8];
|
||||
r[1] = a[0] * b[1] + a[1] * b[5] + a[2] * b[9];
|
||||
r[2] = a[0] * b[2] + a[1] * b[6] + a[2] * b[10];
|
||||
|
||||
var h = a[0] * b[3] + a[1] * b[7] + a[2] * b[11] + b[15];
|
||||
r[0] = r[0] / h;
|
||||
r[1] = r[1] / h;
|
||||
r[2] = r[2] / h;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The original inverseOrthonormal function does not work because it uses Vec3 instead of V3.
|
||||
*/
|
||||
M4x4.inverseOrthonormal = function M4x4_inverseOrthonormal(m, r) {
|
||||
|
||||
if (r === undefined)
|
||||
r = new MJS_FLOAT_ARRAY_TYPE(16);
|
||||
M4x4.transpose(m, r);
|
||||
var t = [m[12], m[13], m[14]];
|
||||
r[3] = r[7] = r[11] = 0;
|
||||
r[12] = -V3.dot([r[0], r[4], r[8]], t);
|
||||
r[13] = -V3.dot([r[1], r[5], r[9]], t);
|
||||
r[14] = -V3.dot([r[2], r[6], r[10]], t);
|
||||
return r;
|
||||
};
|
||||
|
||||
/**
|
||||
* the original direction function returned the direction from b to a, instead of a to b as stated in the comment.
|
||||
*
|
||||
* Function: V3.direction
|
||||
*
|
||||
* Perform
|
||||
* r = (a - b) / |a - b|. The result is the normalized
|
||||
* direction from a to b.
|
||||
*
|
||||
* Parameters:
|
||||
*
|
||||
* a - the first vector operand
|
||||
* b - the second vector operand
|
||||
* r - optional vector to store the result in
|
||||
*
|
||||
* Returns:
|
||||
*
|
||||
* If r is specified, returns r after performing the operation.
|
||||
* Otherwise, returns a new 3-element vector with the result.
|
||||
*/
|
||||
V3.direction = function V3_direction(a, b, r) {
|
||||
if (r === undefined)
|
||||
r = new MJS_FLOAT_ARRAY_TYPE(3);
|
||||
return V3.normalize(V3.sub(b, a, r), r);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* from http://stackoverflow.com/questions/4915462/how-should-i-do-floating-point-comparison
|
||||
*
|
||||
* @param a
|
||||
* @param b
|
||||
* @param epsilon
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
V3.equalScalar = function V3_equalScalar(a,b,epsilon){
|
||||
var absA = Math.abs(a);
|
||||
var absB = Math.abs(b);
|
||||
var diff = Math.abs(a - b);
|
||||
|
||||
if (a === b) { // shortcut, handles infinities
|
||||
return true;
|
||||
} else if (a * b === 0) { // a or b or both are zero
|
||||
// relative error is not meaningful here
|
||||
return diff < (epsilon * epsilon);
|
||||
} else { // use relative error
|
||||
return diff / (absA + absB) < epsilon;
|
||||
}
|
||||
};
|
||||
|
||||
V3.equal = function V3_equal(a,b,epsilon){
|
||||
if(epsilon === undefined){
|
||||
epsilon = 0.000001;
|
||||
}
|
||||
// return
|
||||
// V3.equalScalar(a[0], b[0], 0.000001) &&
|
||||
// V3.equalScalar(a[1], b[1], 0.000001) &&
|
||||
// V3.equalScalar(a[2], b[2], 0.000001);
|
||||
var equals = V3.equalScalar(a[0], b[0], epsilon);
|
||||
equals = equals && V3.equalScalar(a[1], b[1], epsilon);
|
||||
equals = equals && V3.equalScalar(a[2], b[2], epsilon);
|
||||
return equals;
|
||||
};
|
||||
|
||||
|
||||
M4x4.makeInversePerspective = function M4x4_makeInversePerspective (fovy, aspect, znear, zfar, r) {
|
||||
var ymax = znear * Math.tan(fovy * Math.PI / 360.0);
|
||||
var ymin = -ymax;
|
||||
var xmin = ymin * aspect;
|
||||
var xmax = ymax * aspect;
|
||||
|
||||
return M4x4.makeInverseFrustum(xmin, xmax, ymin, ymax, znear, zfar, r);
|
||||
};
|
||||
|
||||
M4x4.makeInverseFrustum = function M4x4_makeInverseFrustum(left, right, bottom, top, near, far, r) {
|
||||
|
||||
if (r === undefined)
|
||||
r = new MJS_FLOAT_ARRAY_TYPE(16);
|
||||
|
||||
r[0] = (-left+right)/(2*near);
|
||||
r[1] = 0;
|
||||
r[2] = 0;
|
||||
r[3] = 0;
|
||||
r[4] = 0;
|
||||
r[5] = (-bottom+top)/(2*near);
|
||||
r[6] = 0;
|
||||
r[7] = 0;
|
||||
r[8] = 0;
|
||||
r[9] = 0;
|
||||
r[10] = 0;
|
||||
r[11] = -(far-near)/(2*far*near);
|
||||
r[12] = (left+right)/(2*near);
|
||||
r[13] = (bottom+top)/(2*near);
|
||||
r[14] = -1;
|
||||
r[15] = (far+near)/(2*far*near);
|
||||
|
||||
return r;
|
||||
};
|
||||
|
||||
/**
|
||||
* copy values from matrix a into matrix b
|
||||
*/
|
||||
M4x4.copy = function(a, b){
|
||||
for(var i = 0; i < 16; i++){
|
||||
b[i] = a[i];
|
||||
}
|
||||
};
|
||||
@ -14,53 +14,66 @@ function POCLoader(){
|
||||
* @return a point cloud octree with the root node data loaded.
|
||||
* loading of descendants happens asynchronously when they're needed
|
||||
*
|
||||
* @param file the xml mno file
|
||||
* @param url
|
||||
* @param loadingFinishedListener executed after loading the binary has been finished
|
||||
*/
|
||||
POCLoader.load = function load(file) {
|
||||
POCLoader.load = function load(url) {
|
||||
try{
|
||||
var pco = new PointcloudOctree();
|
||||
var pco = new Potree.PointCloudOctreeGeometry();
|
||||
pco.url = url;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', file, false);
|
||||
xhr.open('GET', url, false);
|
||||
xhr.send(null);
|
||||
if(xhr.status === 200 || xhr.status === 0){
|
||||
var fMno = JSON.parse(xhr.responseText);
|
||||
if(Potree.utils.pathExists(fMno.octreeDir + "/r")){
|
||||
pco.octreeDir = fMno.octreeDir;
|
||||
}else{
|
||||
pco.octreeDir = url + "/../" + fMno.octreeDir;
|
||||
}
|
||||
|
||||
pco.octreeDir = file + "/../data";
|
||||
var pointAttributes = POCLoader.loadPointAttributes(fMno);
|
||||
pco.setPointAttributes(pointAttributes);
|
||||
var nodes = {};
|
||||
|
||||
{ // load Root
|
||||
var mRoot = new PointcloudOctreeNode("r", pco);
|
||||
var aabb = new AABB();
|
||||
aabb.setDimensionByMinMax(
|
||||
[ fMno.boundingBox.lx, fMno.boundingBox.ly, fMno.boundingBox.lz ],
|
||||
[ fMno.boundingBox.ux, fMno.boundingBox.uy, fMno.boundingBox.uz ]);
|
||||
mRoot.setAABB(aabb);
|
||||
mRoot.points = fMno.hierarchy[0][1];
|
||||
pco.rootNode = mRoot;
|
||||
{ // load root
|
||||
var name = "r";
|
||||
var min = new THREE.Vector3(fMno.boundingBox.lx, fMno.boundingBox.ly, fMno.boundingBox.lz);
|
||||
var max = new THREE.Vector3(fMno.boundingBox.ux, fMno.boundingBox.uy, fMno.boundingBox.uz);
|
||||
var boundingBox = new THREE.Box3(min, max);
|
||||
pco.boundingBox = boundingBox;
|
||||
|
||||
var root = new Potree.PointCloudOctreeGeometryNode(name, pco, boundingBox);
|
||||
root.level = 0;
|
||||
root.numPoints = fMno.hierarchy[0][1];
|
||||
pco.root = root;
|
||||
pco.root.load();
|
||||
nodes[name] = root;
|
||||
}
|
||||
|
||||
// load remaining hierarchy
|
||||
for( var i = 1; i < fMno.hierarchy.length; i++){
|
||||
var nodeName = fMno.hierarchy[i][0];
|
||||
var name = fMno.hierarchy[i][0];
|
||||
var numPoints = fMno.hierarchy[i][1];
|
||||
var index = parseInt(name.charAt(name.length-1));
|
||||
var parentName = name.substring(0, name.length-1);
|
||||
var parentNode = nodes[parentName];
|
||||
var points = fMno.hierarchy[i][1];
|
||||
var mNode = new PointcloudOctreeNode(nodeName, pco);
|
||||
mNode.points = points;
|
||||
pco.rootNode.addChild(mNode);
|
||||
var childIndex = parseInt(mNode.name.charAt(mNode.name.length-1));
|
||||
var childAABB = POCLoader.createChildAABB(mNode.parent.aabb, childIndex);
|
||||
mNode.setAABB(childAABB);
|
||||
var level = name.length-1;
|
||||
var boundingBox = POCLoader.createChildAABB(parentNode.boundingBox, index);
|
||||
|
||||
var node = new Potree.PointCloudOctreeGeometryNode(name, pco, boundingBox);
|
||||
node.level = level;
|
||||
node.numPoints = numPoints;
|
||||
parentNode.addChild(node);
|
||||
nodes[name] = node;
|
||||
}
|
||||
|
||||
pco.nodes = nodes;
|
||||
|
||||
}
|
||||
|
||||
var pcoNode = new PointcloudOctreeSceneNode(pco);
|
||||
return pcoNode;
|
||||
return pco;
|
||||
}catch(e){
|
||||
// Logger.error("loading failed: '" + file + "'");
|
||||
// Logger.error(e);
|
||||
console.log("loading failed: '" + file + "'");
|
||||
console.log("loading failed: '" + url + "'");
|
||||
console.log(e);
|
||||
}
|
||||
};
|
||||
@ -76,89 +89,49 @@ POCLoader.loadPointAttributes = function(mno){
|
||||
}
|
||||
|
||||
return pa;
|
||||
// var fpa = mno.pointAttributes;
|
||||
// var pa = {
|
||||
// 'numAttributes' : fpa.length,
|
||||
// 'bytesPerPoint' : 0,
|
||||
// 'attributes' : {}
|
||||
// };
|
||||
//
|
||||
// for(var i = 0; i < fpa.length; i++){
|
||||
// var pointAttribute = PointAttributes[fpa[i]];
|
||||
// pa.attributes[i] = pointAttribute;
|
||||
// var bytes = pointAttribute.type.size * pointAttribute.numElements;
|
||||
// pa.bytesPerPoint += bytes;
|
||||
// }
|
||||
//
|
||||
// return pa;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* creates an aabb that covers the area of the childnode at childIndex
|
||||
*
|
||||
* @param aabb aabb of the parent
|
||||
* @param childIndex index of the childs region
|
||||
* @returns {AABB}
|
||||
*/
|
||||
POCLoader.createChildAABB = function(aabb, childIndex){
|
||||
var min = aabb.objectSpaceMin;
|
||||
var max = aabb.objectSpaceMax;
|
||||
var caabb = new AABB();
|
||||
// (aabb.max - aabb.minPos) * 0.5
|
||||
var dHalfLength = V3.scale(V3.sub(max,min), 0.5);
|
||||
var xHalfLength = [ dHalfLength[0], 0, 0 ];
|
||||
var yHalfLength = [ 0, dHalfLength[1], 0 ];
|
||||
var zHalfLength = [ 0, 0, dHalfLength[2] ];
|
||||
var V3 = THREE.Vector3;
|
||||
var min = aabb.min;
|
||||
var max = aabb.max;
|
||||
var dHalfLength = new THREE.Vector3().copy(max).sub(min).multiplyScalar(0.5);
|
||||
var xHalfLength = new THREE.Vector3(dHalfLength.x, 0, 0);
|
||||
var yHalfLength = new THREE.Vector3(0, dHalfLength.y, 0);
|
||||
var zHalfLength = new THREE.Vector3(0, 0, dHalfLength.z);
|
||||
|
||||
{
|
||||
var cmin = min;
|
||||
// max = min + (aabb.max - aabb.min) * 0.5;
|
||||
var cmax = V3.add(min, dHalfLength);
|
||||
var caabb = new AABB();
|
||||
caabb.setDimensionByMinMax(cmin, cmax);
|
||||
}
|
||||
var cmin = min;
|
||||
var cmax = new THREE.Vector3().add(min).add(dHalfLength);
|
||||
|
||||
var min, max;
|
||||
if (childIndex === 1) {
|
||||
var min = V3.add(caabb.min, zHalfLength);
|
||||
var max = V3.add(caabb.max, zHalfLength);
|
||||
caabb.setDimensionByMinMax(min, max);
|
||||
caabb.setColor([0.0, 0.0, 1.0, 1.0]);
|
||||
min = new THREE.Vector3().copy(cmin).add(zHalfLength);
|
||||
max = new THREE.Vector3().copy(cmax).add(zHalfLength);
|
||||
}else if (childIndex === 3) {
|
||||
var min = V3.add(V3.add(caabb.min, zHalfLength), yHalfLength);
|
||||
var max = V3.add(V3.add(caabb.max, zHalfLength), yHalfLength);
|
||||
caabb.setDimensionByMinMax(min, max);
|
||||
caabb.setColor([1.0, 1.0, 0.0, 1.0]);
|
||||
min = new THREE.Vector3().copy(cmin).add(zHalfLength).add(yHalfLength);
|
||||
max = new THREE.Vector3().copy(cmax).add(zHalfLength).add(yHalfLength);
|
||||
}else if (childIndex === 0) {
|
||||
caabb.setColor([1.0, 0.0, 0.0, 1.0]);
|
||||
min = cmin;
|
||||
max = cmax;
|
||||
}else if (childIndex === 2) {
|
||||
var min = V3.add(caabb.min, yHalfLength);
|
||||
var max = V3.add(caabb.max, yHalfLength);
|
||||
caabb.setDimensionByMinMax(min, max);
|
||||
caabb.setColor([0.0, 1.0, 0.0, 1.0]);
|
||||
min = new THREE.Vector3().copy(cmin).add(yHalfLength);
|
||||
max = new THREE.Vector3().copy(cmax).add(yHalfLength);
|
||||
}else if (childIndex === 5) {
|
||||
var min = V3.add(V3.add(caabb.min, zHalfLength), xHalfLength);
|
||||
var max = V3.add(V3.add(caabb.max, zHalfLength), xHalfLength);
|
||||
caabb.setDimensionByMinMax(min, max);
|
||||
caabb.setColor([1.0, 1.0, 1.0, 1.0]);
|
||||
min = new THREE.Vector3().copy(cmin).add(zHalfLength).add(xHalfLength);
|
||||
max = new THREE.Vector3().copy(cmax).add(zHalfLength).add(xHalfLength);
|
||||
}else if (childIndex === 7) {
|
||||
var min = V3.add(caabb.min, dHalfLength);
|
||||
var max = V3.add(caabb.max, dHalfLength);
|
||||
caabb.setDimensionByMinMax(min, max);
|
||||
caabb.setColor([0.0, 0.0, 0.0, 1.0]);
|
||||
min = new THREE.Vector3().copy(cmin).add(dHalfLength);
|
||||
max = new THREE.Vector3().copy(cmax).add(dHalfLength);
|
||||
}else if (childIndex === 4) {
|
||||
var min = V3.add(caabb.min, xHalfLength);
|
||||
var max = V3.add(caabb.max, xHalfLength);
|
||||
caabb.setDimensionByMinMax(min, max);
|
||||
caabb.setColor([1.0, 0.0, 1.0, 1.0]);
|
||||
min = new THREE.Vector3().copy(cmin).add(xHalfLength);
|
||||
max = new THREE.Vector3().copy(cmax).add(xHalfLength);
|
||||
}else if (childIndex === 6) {
|
||||
var min = V3.add(V3.add(caabb.min, xHalfLength), yHalfLength);
|
||||
var max = V3.add(V3.add(caabb.max, xHalfLength), yHalfLength);
|
||||
caabb.setDimensionByMinMax(min, max);
|
||||
caabb.setColor([0.0, 1.0, 1.0, 1.0]);
|
||||
min = new THREE.Vector3().copy(cmin).add(xHalfLength).add(yHalfLength);
|
||||
max = new THREE.Vector3().copy(cmax).add(xHalfLength).add(yHalfLength);
|
||||
}
|
||||
|
||||
return caabb;
|
||||
return new THREE.Box3(min, max);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1,278 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
* List of possible ply file types
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
function PlyFileType(){}
|
||||
PlyFileType.ASCII = "ascii";
|
||||
PlyFileType.BINARY_LITTLE_ENDIAN = "binary_little_endian";
|
||||
PlyFileType.BINARY_BIG_ENDIAN = "binary_big_endian";
|
||||
|
||||
/**
|
||||
* represents a property definition in a ply file
|
||||
*
|
||||
* @class
|
||||
*
|
||||
*/
|
||||
function PlyProperty(name, type){
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
function PlyPropertyDataType(name, size){
|
||||
this.name = name;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
/**
|
||||
* represent an element in a ply file. (such as vertex/face/...)
|
||||
*
|
||||
* @class
|
||||
*
|
||||
*/
|
||||
function PlyElement(name){
|
||||
this.name = name;
|
||||
this.properties = new Array();
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
PlyPropertyDataType.char = new PlyPropertyDataType("char", 1);
|
||||
PlyPropertyDataType.uchar = new PlyPropertyDataType("uchar", 1);
|
||||
PlyPropertyDataType.short = new PlyPropertyDataType("short", 2);
|
||||
PlyPropertyDataType.ushort = new PlyPropertyDataType("ushort", 2);
|
||||
PlyPropertyDataType.int = new PlyPropertyDataType("int", 4);
|
||||
PlyPropertyDataType.uint = new PlyPropertyDataType("uint", 4);
|
||||
PlyPropertyDataType.float = new PlyPropertyDataType("float", 4);
|
||||
PlyPropertyDataType.double = new PlyPropertyDataType("double", 8);
|
||||
|
||||
/**
|
||||
* holds ply header data
|
||||
*
|
||||
* @class
|
||||
*
|
||||
*/
|
||||
function PlyHeader(){
|
||||
this.type = null;
|
||||
this.byteSize = 0;
|
||||
this.elements = new Array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains ply header and a buffer with byte-data
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
function PlyFile(buffer){
|
||||
this.buffer = buffer;
|
||||
this.header = new PlyHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* This listener is called while a ply file is beeing loaded
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
function PlyLoaderListener(){
|
||||
|
||||
}
|
||||
|
||||
PlyLoaderListener.prototype.finishedLoading = function(pointcloud){
|
||||
|
||||
};
|
||||
|
||||
PlyLoaderListener.prototype.pointsLoaded = function(numLoadedPoints, numPoints){
|
||||
|
||||
};
|
||||
|
||||
PlyLoaderListener.prototype.onProgress = function(progress){
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
function PlyLoader(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads source in a background task.
|
||||
* Once loading is finished, listener.finishedLoading(pointCloud) is called.
|
||||
*/
|
||||
PlyLoader.load = function(source, listener){
|
||||
var plyFile = new PlyFile();
|
||||
var worker = new Worker("src/loader/PlyLoaderWorker.js");
|
||||
worker.onmessage = function(event){
|
||||
if(event.data.type === "header"){
|
||||
plyFile.header = PlyLoader.parseHeader(event.data.header);
|
||||
}else if(event.data.type === "progress"){
|
||||
listener.pointsLoaded(event.data.pointsLoaded, plyFile.header.elements[0].size);
|
||||
}else if(event.data.type === "result"){
|
||||
var pointBuffer = event.data.buffer;
|
||||
var aabb = event.data.aabb;
|
||||
var vertexElement = plyFile.header.elements[0];
|
||||
var pointAttributes = PlyLoader.pointAttributesFromProperties(vertexElement.properties, true);
|
||||
var numPoints = pointBuffer.byteLength / pointAttributes.byteSize;
|
||||
var pointCloud = new PointCloud("test", pointAttributes);
|
||||
pointCloud.setVertexBufferData(pointBuffer);
|
||||
pointCloud.size = numPoints;
|
||||
pointCloud.aabb = new AABB();
|
||||
var min = V3.$(aabb.lx, aabb.ly, aabb.lz);
|
||||
var max = V3.$(aabb.ux, aabb.uy, aabb.uz);
|
||||
pointCloud.aabb.setDimensionByMinMax(min, max);
|
||||
|
||||
listener.finishedLoading(pointCloud);
|
||||
}else if(event.data.type === "log"){
|
||||
console.log(event.data.message);
|
||||
}else if(event.data.type === "fileLoadProgress"){
|
||||
listener.fileLoadProgress(event.data.percentage);
|
||||
}else{
|
||||
alert(event.data);
|
||||
}
|
||||
};
|
||||
worker.postMessage(source);
|
||||
};
|
||||
|
||||
PlyLoader.parseHeader = function PlyLoader_parseHeader(header){
|
||||
var lines = header.split('\n');
|
||||
var plyHeader = new PlyHeader();
|
||||
plyHeader.byteSize = header.length;
|
||||
var vertexElement = new PlyElement("vertex");
|
||||
plyHeader.elements.push(vertexElement);
|
||||
|
||||
var formatPattern = /^format (ascii|binary_little_endian).*/;
|
||||
var elementPattern = /element (\w*) (\d*)/;
|
||||
var propertyPattern = /property (char|uchar|short|ushort|int|uint|float|double) (\w*)/;
|
||||
|
||||
while(lines.length > 0){
|
||||
//for(var i = 0; i < lines.length; i++){
|
||||
var line = lines.shift();
|
||||
|
||||
if(line === "ply"){
|
||||
}else if(line.search(formatPattern) >= 0){
|
||||
var result = line.match(formatPattern);
|
||||
plyHeader.type = PlyFileType[result[1].toUpperCase()];
|
||||
}else if(line.search(elementPattern) >= 0){
|
||||
var result = line.match(elementPattern);
|
||||
var name = result[1];
|
||||
var count = parseInt(result[2]);
|
||||
|
||||
if(name !== "vertex"){
|
||||
throw "As of now, only ply files with 'vertex' as the first element are supported.";
|
||||
}
|
||||
|
||||
vertexElement.size = count;
|
||||
// handle properties
|
||||
while(lines[0].search(propertyPattern) >= 0){
|
||||
var result = lines.shift().match(propertyPattern);
|
||||
var name = result[2];
|
||||
var type = PlyPropertyDataType[result[1]];
|
||||
var property = new PlyProperty(name, type);
|
||||
vertexElement.properties.push(property);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return plyHeader;
|
||||
};
|
||||
|
||||
PlyLoader.pointAttributesFromProperties = function PlyLoader_pointAttributesFromProperties(properties, forTargetBuffer){
|
||||
if(forTargetBuffer === undefined){
|
||||
forTargetBuffer = false;
|
||||
}
|
||||
var pointAttributes = new PointAttributes();
|
||||
var i = 0;
|
||||
while(i < properties.length){
|
||||
var property = properties[i];
|
||||
|
||||
if(property.name === "x"){
|
||||
var p0 = property;
|
||||
var p1 = properties[i+1];
|
||||
var p2 = properties[i+2];
|
||||
|
||||
if(p1.name !== "y" || p2.name !== "z"){
|
||||
throw "unsupported ply format";
|
||||
}
|
||||
|
||||
if((p0.type.name + p1.type.name + p2.type.name) !== "floatfloatfloat"){
|
||||
throw "unsupported ply format";
|
||||
}
|
||||
|
||||
pointAttributes.add(PointAttribute.POSITION_CARTESIAN);
|
||||
i+=3;
|
||||
}else if(property.name === "nx"){
|
||||
var p0 = property;
|
||||
var p1 = properties[i+1];
|
||||
var p2 = properties[i+2];
|
||||
|
||||
if(p1.name !== "ny" || p2.name !== "nz"){
|
||||
throw "unsupported ply format";
|
||||
}
|
||||
|
||||
if((p0.type.name + p1.type.name + p2.type.name) !== "floatfloatfloat"){
|
||||
throw "unsupported ply format";
|
||||
}
|
||||
|
||||
pointAttributes.add(PointAttribute.NORMAL_FLOATS);
|
||||
i+=3;
|
||||
}else if(property.name === "red"){
|
||||
if(properties[i+3] != null && properties[i+3].name === "alpha"){
|
||||
var c0 = property;
|
||||
var c1 = properties[i+1];
|
||||
var c2 = properties[i+2];
|
||||
var c3 = properties[i+3];
|
||||
|
||||
if(c1.name !== "green" || c2.name !== "blue" || c3.name !== "alpha"){
|
||||
throw "unsupported ply format";
|
||||
}
|
||||
|
||||
if((c0.type.name + c1.type.name + c2.type.name + c3.type.name) !== "ucharucharucharuchar"){
|
||||
throw "unsupported ply format";
|
||||
}
|
||||
|
||||
pointAttributes.add(PointAttribute.RGBA_PACKED);
|
||||
i += 4;
|
||||
}else{
|
||||
var c0 = property;
|
||||
var c1 = properties[i+1];
|
||||
var c2 = properties[i+2];
|
||||
|
||||
if(c1.name !== "green" || c2.name !== "blue"){
|
||||
throw "unsupported ply format";
|
||||
}
|
||||
|
||||
if((c0.type.name + c1.type.name + c2.type.name) !== "ucharucharuchar"){
|
||||
throw "unsupported ply format";
|
||||
}
|
||||
|
||||
if(forTargetBuffer){
|
||||
pointAttributes.add(PointAttribute.RGBA_PACKED);
|
||||
}else{
|
||||
pointAttributes.add(PointAttribute.RGB_PACKED);
|
||||
}
|
||||
i+=3;
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
if(!forTargetBuffer){
|
||||
var attribute = new PointAttribute(PointAttributeNames.FILLER,
|
||||
PointAttributeTypes.DATA_TYPE_INT8, property.size);
|
||||
pointAttributes.add(attribute);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return pointAttributes;
|
||||
};
|
||||
|
||||
@ -1,312 +0,0 @@
|
||||
|
||||
|
||||
importScripts("PointAttributes.js");
|
||||
importScripts("PlyLoader.js");
|
||||
|
||||
self.onmessage = function(message){
|
||||
// postMessage("onmessage");
|
||||
var plyFile = message.data;
|
||||
PlyBinaryWorker.load(plyFile);
|
||||
};
|
||||
|
||||
/**
|
||||
* A worker thread class that loads data from ply files in the background.
|
||||
*
|
||||
* @class
|
||||
*
|
||||
*/
|
||||
function PlyBinaryWorker(){
|
||||
|
||||
}
|
||||
|
||||
PlyBinaryWorker.load = function PlyLoader_load(source){
|
||||
// postMessage("load");
|
||||
if(source instanceof Blob){
|
||||
PlyBinaryWorker.loadFromFile(source);
|
||||
}else if(source instanceof ArrayBuffer){
|
||||
PlyBinaryWorker.loadFromBuffer(source);
|
||||
}else if(typeof source === 'string'){
|
||||
PlyBinaryWorker.loadFromUrl(source);
|
||||
}
|
||||
// postMessage("sis: " + (source instanceof String));
|
||||
};
|
||||
|
||||
PlyBinaryWorker.loadFromFile = function(source){
|
||||
var reader = new FileReaderSync();
|
||||
var buffer = reader.readAsArrayBuffer(source);
|
||||
PlyBinaryWorker.loadFromBuffer(buffer);
|
||||
};
|
||||
|
||||
PlyBinaryWorker.loadFromUrl = function(source){
|
||||
// postMessage("fromUrl");
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', source, true);
|
||||
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.onprogress = function(evt){
|
||||
var pFinished = 100 * (evt.loaded / evt.total);
|
||||
postMessage({"type": "fileLoadProgress", "percentage": pFinished});
|
||||
}
|
||||
|
||||
xhr.onreadystatechange = function(){
|
||||
if(xhr.readyState === 4){
|
||||
if (xhr.status === 200 || xhr.status === 0) {
|
||||
var buffer = xhr.response;
|
||||
PlyBinaryWorker.loadFromBuffer(buffer);
|
||||
} else {
|
||||
// post message failed
|
||||
}
|
||||
}else if(xhr.readyState === 3){
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
try{
|
||||
xhr.send(null);
|
||||
}catch(e){
|
||||
// post message failed
|
||||
}
|
||||
};
|
||||
|
||||
PlyBinaryWorker.loadFromAscii = function loadFromAscii(plyFile){
|
||||
var vertexElement = plyFile.header.elements[0];
|
||||
var plyPointAttributes = PlyLoader.pointAttributesFromProperties(vertexElement.properties);
|
||||
var pointAttributes = PlyLoader.pointAttributesFromProperties(vertexElement.properties, true);
|
||||
var pointBuffer = new ArrayBuffer(pointAttributes.byteSize * vertexElement.size);
|
||||
var pointDataView = new DataView(pointBuffer);
|
||||
var plyBuffer = plyFile.buffer;
|
||||
var plyBufferUint8 = new Uint8Array(plyBuffer, plyFile.header.byteSize);
|
||||
|
||||
var currentLineStart = 0;
|
||||
var nextLineStart = 0;
|
||||
var getNextLineStart = function(){
|
||||
for(var i = currentLineStart+1; i < plyBufferUint8.byteLength; i++){
|
||||
if(plyBufferUint8[i] === "\n".charCodeAt(0)){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
var linesRead = 0;
|
||||
var targetOffset = 0;
|
||||
var aabb = {
|
||||
lx: Infinity,
|
||||
ly: Infinity,
|
||||
lz: Infinity,
|
||||
ux: -Infinity,
|
||||
uy: -Infinity,
|
||||
uz: -Infinity
|
||||
};
|
||||
|
||||
while(nextLineStart < plyBuffer.byteLength && nextLineStart != null && targetOffset < pointDataView.byteLength ){
|
||||
nextLineStart = getNextLineStart();
|
||||
var line = String.fromCharCode.apply(this, plyBufferUint8.subarray(currentLineStart, nextLineStart));
|
||||
var tokens = line.trim().split(" ");
|
||||
// if(tokens.length !== plyPointAttributes.attributes.length){
|
||||
// continue;
|
||||
// }
|
||||
|
||||
for(var j = 0; j < plyPointAttributes.attributes.length; j++){
|
||||
var pointAttribute = plyPointAttributes.attributes[j];
|
||||
|
||||
if(pointAttribute === PointAttribute.POSITION_CARTESIAN){
|
||||
var x = parseFloat(tokens.shift());
|
||||
var y = parseFloat(tokens.shift());
|
||||
var z = parseFloat(tokens.shift());
|
||||
pointDataView.setFloat32(targetOffset, x, true);
|
||||
pointDataView.setFloat32(targetOffset+4, y, true);
|
||||
pointDataView.setFloat32(targetOffset+8, z, true);
|
||||
|
||||
if(!isNaN(x) && !isNaN(y) && !isNaN(z)){
|
||||
aabb.lx = Math.min(aabb.lx, x);
|
||||
aabb.ly = Math.min(aabb.ly, y);
|
||||
aabb.lz = Math.min(aabb.lz, z);
|
||||
aabb.ux = Math.max(aabb.ux, x);
|
||||
aabb.uy = Math.max(aabb.uy, y);
|
||||
aabb.uz = Math.max(aabb.uz, z);
|
||||
}
|
||||
|
||||
targetOffset += 12;
|
||||
}else if(pointAttribute === PointAttribute.NORMAL_FLOATS){
|
||||
var nx = parseFloat(tokens.shift());
|
||||
var ny = parseFloat(tokens.shift());
|
||||
var nz = parseFloat(tokens.shift());
|
||||
pointDataView.setFloat32(targetOffset, nx, true);
|
||||
pointDataView.setFloat32(targetOffset+4, ny, true);
|
||||
pointDataView.setFloat32(targetOffset+8, nz, true);
|
||||
|
||||
targetOffset += 12;
|
||||
}else if(pointAttribute === PointAttribute.RGB_PACKED){
|
||||
var r = parseInt(tokens.shift());
|
||||
var g = parseInt(tokens.shift());
|
||||
var b = parseInt(tokens.shift());
|
||||
pointDataView.setUint8(targetOffset, r);
|
||||
pointDataView.setUint8(targetOffset+1, g);
|
||||
pointDataView.setUint8(targetOffset+2, b);
|
||||
pointDataView.setUint8(targetOffset+3, 255);
|
||||
|
||||
targetOffset += 4;
|
||||
}else if(pointAttribute === PointAttribute.RGBA_PACKED){
|
||||
var r = parseInt(tokens.shift());
|
||||
var g = parseInt(tokens.shift());
|
||||
var b = parseInt(tokens.shift());
|
||||
var a = parseInt(tokens.shift());
|
||||
pointDataView.setUint8(targetOffset, r);
|
||||
pointDataView.setUint8(targetOffset+1, g);
|
||||
pointDataView.setUint8(targetOffset+2, b);
|
||||
pointDataView.setUint8(targetOffset+3, a);
|
||||
targetOffset += 4;
|
||||
}
|
||||
}
|
||||
|
||||
linesRead++;
|
||||
if((linesRead % (1000)) === 0){
|
||||
var message = {
|
||||
"type": "progress",
|
||||
"pointsLoaded": linesRead
|
||||
};
|
||||
postMessage(message);
|
||||
}
|
||||
|
||||
currentLineStart = nextLineStart;
|
||||
|
||||
// if(linesRead >= 10000){
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
var result = {
|
||||
"type": "result",
|
||||
"buffer": pointBuffer,
|
||||
"pointAttributes": pointAttributes,
|
||||
"aabb": aabb
|
||||
};
|
||||
postMessage(result);
|
||||
|
||||
};
|
||||
|
||||
PlyBinaryWorker.loadFromBinary = function loadFromBinary(plyFile){
|
||||
var littleEndian = true;
|
||||
if(plyFile.header.type === PlyFileType.BINARY_LITTLE_ENDIAN){
|
||||
littleEndian = true;
|
||||
}else{
|
||||
littleEndian = false;
|
||||
}
|
||||
|
||||
// postMessage({"type": "log", "message": ("binary:" + littleEndian)});
|
||||
|
||||
var vertexElement = plyFile.header.elements[0];
|
||||
// vertexElement.size = 10000;
|
||||
var plyPointAttributes = PlyLoader.pointAttributesFromProperties(vertexElement.properties);
|
||||
var pointAttributes = PlyLoader.pointAttributesFromProperties(vertexElement.properties, true);
|
||||
var pointBuffer = new ArrayBuffer(pointAttributes.byteSize * vertexElement.size);
|
||||
var pointDataView = new DataView(pointBuffer);
|
||||
var plyDataView = new DataView(plyFile.buffer, plyFile.header.byteSize);
|
||||
var aabb = {
|
||||
lx: Infinity,
|
||||
ly: Infinity,
|
||||
lz: Infinity,
|
||||
ux: -Infinity,
|
||||
uy: -Infinity,
|
||||
uz: -Infinity
|
||||
};
|
||||
|
||||
for(var i = 0; i < vertexElement.size; i++){
|
||||
var targetOffset = i * pointAttributes.byteSize;
|
||||
var plyOffset = i * plyPointAttributes.byteSize;
|
||||
for(var j = 0; j < plyPointAttributes.attributes.length; j++){
|
||||
var pointAttribute = plyPointAttributes.attributes[j];
|
||||
|
||||
if(pointAttribute === PointAttribute.POSITION_CARTESIAN){
|
||||
var x = plyDataView.getFloat32(plyOffset, littleEndian);
|
||||
var y = plyDataView.getFloat32(plyOffset+4, littleEndian);
|
||||
var z = plyDataView.getFloat32(plyOffset+8, littleEndian);
|
||||
pointDataView.setFloat32(targetOffset, x, true);
|
||||
pointDataView.setFloat32(targetOffset+4, y, true);
|
||||
pointDataView.setFloat32(targetOffset+8, z, true);
|
||||
|
||||
// if(i <= 100){
|
||||
// var message = "plyOffset: " + plyOffset;
|
||||
// postMessage({"type": "log", "message": message});
|
||||
// message = ("x: " + x + ", y: " + y + ", z: " + z);
|
||||
// postMessage({"type": "log", "message": message});
|
||||
// }
|
||||
|
||||
if(!isNaN(x) && !isNaN(y) && !isNaN(z)){
|
||||
aabb.lx = Math.min(aabb.lx, x);
|
||||
aabb.ly = Math.min(aabb.ly, y);
|
||||
aabb.lz = Math.min(aabb.lz, z);
|
||||
aabb.ux = Math.max(aabb.ux, x);
|
||||
aabb.uy = Math.max(aabb.uy, y);
|
||||
aabb.uz = Math.max(aabb.uz, z);
|
||||
}
|
||||
|
||||
targetOffset += 12;
|
||||
plyOffset += 12;
|
||||
}else if(pointAttribute === PointAttribute.NORMAL_FLOATS){
|
||||
pointDataView.setFloat32(targetOffset, plyDataView.getFloat32(plyOffset, littleEndian), true);
|
||||
pointDataView.setFloat32(targetOffset+4, plyDataView.getFloat32(plyOffset+4, littleEndian), true);
|
||||
pointDataView.setFloat32(targetOffset+8, plyDataView.getFloat32(plyOffset+8, littleEndian), true);
|
||||
targetOffset += 12;
|
||||
plyOffset += 12;
|
||||
}else if(pointAttribute === PointAttribute.RGB_PACKED){
|
||||
pointDataView.setUint8(targetOffset, plyDataView.getUint8(plyOffset));
|
||||
pointDataView.setUint8(targetOffset+1, plyDataView.getUint8(plyOffset+1));
|
||||
pointDataView.setUint8(targetOffset+2, plyDataView.getUint8(plyOffset+2));
|
||||
pointDataView.setUint8(targetOffset+3, 255);
|
||||
targetOffset += 4;
|
||||
plyOffset += 3;
|
||||
}else if(pointAttribute === PointAttribute.RGBA_PACKED){
|
||||
pointDataView.setUint8(targetOffset, plyDataView.getUint8(plyOffset));
|
||||
pointDataView.setUint8(targetOffset+1, plyDataView.getUint8(plyOffset+1));
|
||||
pointDataView.setUint8(targetOffset+2, plyDataView.getUint8(plyOffset+2));
|
||||
pointDataView.setUint8(targetOffset+3, plyDataView.getUint8(plyOffset+3));
|
||||
targetOffset += 4;
|
||||
plyOffset += 4;
|
||||
}else{
|
||||
plyOffset += pointAttribute.byteSize;
|
||||
}
|
||||
}
|
||||
if(i % (10*1000) === 0){
|
||||
var message = {
|
||||
"type": "progress",
|
||||
"pointsLoaded": i
|
||||
};
|
||||
postMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
var result = {
|
||||
"type": "result",
|
||||
"buffer": pointBuffer,
|
||||
"pointAttributes": pointAttributes,
|
||||
"aabb": aabb
|
||||
};
|
||||
postMessage(result);
|
||||
};
|
||||
|
||||
PlyBinaryWorker.loadFromBuffer = function PlyLoader_loadFromBuffer(buffer){
|
||||
var plyFile = new PlyFile(buffer);
|
||||
var possibleHeader = String.fromCharCode.apply(null, new Uint8Array(buffer, 0, 5000));
|
||||
var headerLength = possibleHeader.indexOf("end_header") + 11;
|
||||
if(headerLength === 0){
|
||||
throw "unable to read ply header";
|
||||
}
|
||||
|
||||
var strHeader = possibleHeader.substr(0, headerLength);
|
||||
var plyHeader = PlyLoader.parseHeader(strHeader);
|
||||
plyFile.header = plyHeader;
|
||||
postMessage({
|
||||
"type": "header",
|
||||
"header": strHeader});
|
||||
|
||||
if(plyFile.header.type === PlyFileType.ASCII){
|
||||
PlyBinaryWorker.loadFromAscii(plyFile);
|
||||
}else{
|
||||
PlyBinaryWorker.loadFromBinary(plyFile);
|
||||
}
|
||||
};
|
||||
@ -1,25 +1,35 @@
|
||||
|
||||
|
||||
/**
|
||||
* Some types of possible point attributes
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
var PointAttributeNames = {
|
||||
POSITION_CARTESIAN : 0, // float x, y, z;
|
||||
COLOR_PACKED : 1, // byte r, g, b, a; I = [0,1]
|
||||
COLOR_FLOATS_1 : 2, // float r, g, b; I = [0,1]
|
||||
COLOR_FLOATS_255 : 3, // float r, g, b; I = [0,255]
|
||||
NORMAL_FLOATS : 4, // float x, y, z;
|
||||
FILLER : 5
|
||||
};
|
||||
///**
|
||||
// * Some types of possible point attributes
|
||||
// *
|
||||
// * @class
|
||||
// */
|
||||
//var PointAttributeNames = {
|
||||
// POSITION_CARTESIAN : 0, // float x, y, z;
|
||||
// COLOR_PACKED : 1, // byte r, g, b, a; I = [0,1]
|
||||
// COLOR_FLOATS_1 : 2, // float r, g, b; I = [0,1]
|
||||
// COLOR_FLOATS_255 : 3, // float r, g, b; I = [0,255]
|
||||
// NORMAL_FLOATS : 4, // float x, y, z;
|
||||
// FILLER : 5
|
||||
//};
|
||||
//
|
||||
//var i = 0;
|
||||
//for(var obj in PointAttributeNames){
|
||||
// PointAttributeNames[i] = PointAttributeNames[obj];
|
||||
// i++;
|
||||
//}
|
||||
|
||||
var i = 0;
|
||||
for(var obj in PointAttributeNames){
|
||||
PointAttributeNames[i] = PointAttributeNames[obj];
|
||||
i++;
|
||||
function PointAttributeNames(){
|
||||
|
||||
}
|
||||
|
||||
PointAttributeNames.POSITION_CARTESIAN = 0; // float x, y, z;
|
||||
PointAttributeNames.COLOR_PACKED = 1; // byte r, g, b, a; I = [0,1]
|
||||
PointAttributeNames.COLOR_FLOATS_1 = 2; // float r, g, b; I = [0,1]
|
||||
PointAttributeNames.COLOR_FLOATS_255 = 3; // float r, g, b; I = [0,255]
|
||||
PointAttributeNames.NORMAL_FLOATS = 4; // float x, y, z;
|
||||
PointAttributeNames.FILLER = 5;
|
||||
/**
|
||||
* Some types of possible point attribute data formats
|
||||
*
|
||||
|
||||
@ -1,343 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the "High-Quality Splatting on Today's GPUs" paper.
|
||||
*
|
||||
* @class
|
||||
* @see http://graphics.ucsd.edu/~matthias/Papers/HighQualitySplattingOnGPUs.pdf
|
||||
*
|
||||
*/
|
||||
function FilteredSplatsMaterial(name){
|
||||
if(!FilteredSplatsMaterial.isSupported()){
|
||||
throw new Error("FilteredSplatsMaterial is not supported on your system. OES_texture_float extension is not available.");
|
||||
}
|
||||
|
||||
Material.call(this, name);
|
||||
this.depthShader = new Shader(name + "_depth", "filteredSplats/filteredSplatsDepthPass.vs", "filteredSplats/filteredSplatsDepthPass.fs");
|
||||
this.normalShader = new Shader(name + "_filtered_normal", "filteredSplats/filteredSplatsAttributePass.vs", "filteredSplats/filteredSplatsNormalAttributePass.fs");
|
||||
this.colorShader = new Shader(name + "_filtered_color", "filteredSplats/filteredSplatsAttributePass.vs", "filteredSplats/filteredSplatsColorAttributePass.fs");
|
||||
this.normalizationShader = new Shader(name + "normalization", "drawTexture.vs", "filteredSplats/filteredSplatsShadingPass.fs");
|
||||
this.depthFBO = new FramebufferFloat32(Potree.canvas.width, Potree.canvas.height);
|
||||
this.normalFBO = new FramebufferFloat32(Potree.canvas.width, Potree.canvas.height);
|
||||
this.colorFBO = new FramebufferFloat32(Potree.canvas.width, Potree.canvas.height);
|
||||
|
||||
this.illuminationMode = IlluminationMode.PHONG;
|
||||
this.pointSize = 1.0;
|
||||
this.blendDepth = 0.1;
|
||||
}
|
||||
|
||||
FilteredSplatsMaterial.prototype = new Material(inheriting);
|
||||
|
||||
FilteredSplatsMaterial.isSupported = function(){
|
||||
if (gl.getExtension("OES_texture_float") == null) {
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
FilteredSplatsMaterial.prototype.render = function(sceneNode, renderer){
|
||||
var transform = sceneNode.globalTransformation;
|
||||
var pointClouds = new Array();
|
||||
|
||||
if(sceneNode instanceof PointCloudSceneNode){
|
||||
pointClouds.push(sceneNode.pointCloud);
|
||||
}else if(sceneNode instanceof PointcloudOctreeSceneNode){
|
||||
var renderQueue = sceneNode.mno.renderQueue;
|
||||
for(var i = 0; i < renderQueue.length; i++){
|
||||
var node = renderQueue.get(i);
|
||||
pointClouds.push(node.pointCloud);
|
||||
}
|
||||
}
|
||||
this.renderPointClouds(transform, pointClouds, renderer);
|
||||
};
|
||||
|
||||
FilteredSplatsMaterial.prototype.renderPointClouds = function(transform, pointClouds, renderer){
|
||||
var oldBuffer = Framebuffer.getActiveBuffer();
|
||||
|
||||
// depth and position
|
||||
this.depthPass(transform, pointClouds, renderer);
|
||||
|
||||
// attributes
|
||||
this.colorPass(transform, pointClouds, renderer);
|
||||
if(this.illuminationMode === IlluminationMode.PHONG || this.illuminationMode === IlluminationMode.NORMALS){
|
||||
this.normalPass(transform, pointClouds, renderer);
|
||||
}
|
||||
|
||||
// normalization and shading
|
||||
this.shadingPass(oldBuffer, renderer);
|
||||
|
||||
// oldBuffer.drawTexture(this.colorFBO.texture, [0,0], [1,1]);
|
||||
// oldBuffer.drawTexture(this.normalFBO.texture, [-1,0], [0,1]);
|
||||
// oldBuffer.drawTexture(this.depthFBO.texture, [-1,0], [0,1]);
|
||||
// oldBuffer.drawTexture(this.depthFBO.texture, [-1,-1], [1,1]);
|
||||
};
|
||||
|
||||
/**
|
||||
* create depth map.
|
||||
* this pass renders into the depthFBO which is defined as a floating point texture.
|
||||
* linear depth is stored in the first value of each pixel.
|
||||
*
|
||||
*/
|
||||
FilteredSplatsMaterial.prototype.depthPass = function(transform, pointClouds, renderer){
|
||||
var camera = renderer.camera;
|
||||
var lights = renderer.lights;
|
||||
|
||||
this.depthFBO.bind();
|
||||
this.depthFBO.setSize(Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.viewport(0, 0, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.clearColor(0,0,0,0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||
|
||||
gl.disable(gl.BLEND);
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.depthMask(true);
|
||||
|
||||
{// uniforms
|
||||
gl.useProgram(this.depthShader.program);
|
||||
gl.uniformMatrix4fv(this.depthShader.uniforms.uWorld, false, transform);
|
||||
gl.uniformMatrix4fv(this.depthShader.uniforms.uView, false, camera.viewMatrix);
|
||||
gl.uniformMatrix4fv(this.depthShader.uniforms.uProj, false, camera.projectionMatrix);
|
||||
gl.uniform1f(this.depthShader.uniforms.uPointSize, this.pointSize);
|
||||
gl.uniform1f(this.depthShader.uniforms.uNear, camera.nearClipPlane);
|
||||
gl.uniform1f(this.depthShader.uniforms.uFar, camera.farClipPlane);
|
||||
gl.uniform1f(this.depthShader.uniforms.uBlendDepth, this.blendDepth);
|
||||
gl.uniform2f(this.depthShader.uniforms.uWindowSize, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
|
||||
var nearHeight = 2*camera.nearClipPlane*Math.tan(camera.fieldOfView*Math.PI/360);
|
||||
var nearWidth = nearHeight*camera.aspectRatio;
|
||||
gl.uniform2f(this.depthShader.uniforms.uNearWindowSize, nearWidth, nearHeight);
|
||||
|
||||
}
|
||||
|
||||
for(var i = 0; i < pointClouds.length; i++){
|
||||
var pointCloud = pointClouds[i];
|
||||
var pointAttributes = pointCloud.pointAttributes;
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, pointCloud.vbo);
|
||||
var offset = 0;
|
||||
for(var j = 0; j < pointAttributes.size; j++){
|
||||
var attribute = pointAttributes.attributes[j];
|
||||
|
||||
if(attribute === PointAttribute.POSITION_CARTESIAN){
|
||||
gl.enableVertexAttribArray(this.depthShader.attributes.aVertexPosition);
|
||||
gl.vertexAttribPointer(this.depthShader.attributes.aVertexPosition, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}else if(attribute === PointAttribute.RGBA_PACKED){
|
||||
if(this.depthShader.attributes.aVertexColour != null){
|
||||
gl.enableVertexAttribArray(this.depthShader.attributes.aVertexColour);
|
||||
gl.vertexAttribPointer(this.depthShader.attributes.aVertexColour, 3, gl.UNSIGNED_BYTE, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}else if(attribute === PointAttribute.NORMAL_FLOATS){
|
||||
if(this.depthShader.attributes.aNormal != null){
|
||||
gl.enableVertexAttribArray(this.depthShader.attributes.aNormal);
|
||||
gl.vertexAttribPointer(this.depthShader.attributes.aNormal, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}
|
||||
offset += attribute.byteSize;
|
||||
}
|
||||
|
||||
gl.drawArrays(gl.POINTS, 0, pointCloud.size);
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aVertexPosition);
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aVertexColour);
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aNormal);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
FilteredSplatsMaterial.prototype.colorPass = function(transform, pointClouds, renderer){
|
||||
var camera = renderer.camera;
|
||||
|
||||
// color fbo
|
||||
this.colorFBO.bind();
|
||||
this.colorFBO.setSize(Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, this.depthFBO.renderbuffer);
|
||||
this.colorFBO.checkBuffer();
|
||||
gl.viewport(0, 0, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.clearColor(0,0,0,0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(gl.ONE, gl.ONE);
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.depthFunc(gl.LESS);
|
||||
gl.depthMask(false);
|
||||
|
||||
{ // color uniforms
|
||||
gl.useProgram(this.colorShader.program);
|
||||
gl.uniformMatrix4fv(this.colorShader.uniforms.uWorld, false, transform);
|
||||
gl.uniformMatrix4fv(this.colorShader.uniforms.uView, false, camera.viewMatrix);
|
||||
gl.uniformMatrix4fv(this.colorShader.uniforms.uProj, false, camera.projectionMatrix);
|
||||
gl.uniform1f(this.colorShader.uniforms.uPointSize, this.pointSize);
|
||||
gl.uniform1f(this.colorShader.uniforms.uNear, camera.nearClipPlane);
|
||||
gl.uniform1f(this.colorShader.uniforms.uFar, camera.farClipPlane);
|
||||
gl.uniform2f(this.depthShader.uniforms.uWindowSize, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
|
||||
var nearHeight = 2*camera.nearClipPlane*Math.tan(camera.fieldOfView*Math.PI/360);
|
||||
var nearWidth = nearHeight*camera.aspectRatio;
|
||||
gl.uniform2f(this.depthShader.uniforms.uNearWindowSize, nearWidth, nearHeight);
|
||||
}
|
||||
|
||||
for(var i = 0; i < pointClouds.length; i++){
|
||||
var pointCloud = pointClouds[i];
|
||||
var pointAttributes = pointCloud.pointAttributes;
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, pointCloud.vbo);
|
||||
var offset = 0;
|
||||
for(var j = 0; j < pointAttributes.size; j++){
|
||||
var attribute = pointAttributes.attributes[j];
|
||||
|
||||
if(attribute === PointAttribute.POSITION_CARTESIAN){
|
||||
gl.enableVertexAttribArray(this.colorShader.attributes.aVertexPosition);
|
||||
gl.vertexAttribPointer(this.colorShader.attributes.aVertexPosition, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}else if(attribute === PointAttribute.RGBA_PACKED){
|
||||
if(this.colorShader.attributes.aVertexColour != null){
|
||||
gl.enableVertexAttribArray(this.colorShader.attributes.aVertexColour);
|
||||
gl.vertexAttribPointer(this.colorShader.attributes.aVertexColour, 3, gl.UNSIGNED_BYTE, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}else if(attribute === PointAttribute.NORMAL_FLOATS){
|
||||
if(this.colorShader.attributes.aNormal != null){
|
||||
gl.enableVertexAttribArray(this.colorShader.attributes.aNormal);
|
||||
gl.vertexAttribPointer(this.colorShader.attributes.aNormal, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}
|
||||
offset += attribute.byteSize;
|
||||
}
|
||||
|
||||
gl.drawArrays(gl.POINTS, 0, pointCloud.size);
|
||||
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aVertexPosition);
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aVertexColour);
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aNormal);
|
||||
}
|
||||
gl.depthFunc(gl.LESS);
|
||||
gl.depthMask(true);
|
||||
};
|
||||
|
||||
FilteredSplatsMaterial.prototype.normalPass = function(transform, pointClouds, renderer){
|
||||
var camera = renderer.camera;
|
||||
|
||||
// normal fbo
|
||||
this.normalFBO.bind();
|
||||
this.normalFBO.setSize(Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, this.depthFBO.renderbuffer);
|
||||
this.normalFBO.checkBuffer();
|
||||
gl.viewport(0, 0, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.clearColor(0,0,0,0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(gl.ONE, gl.ONE);
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.depthFunc(gl.LESS);
|
||||
gl.depthMask(false);
|
||||
|
||||
{ // normal uniforms
|
||||
gl.useProgram(this.normalShader.program);
|
||||
gl.uniformMatrix4fv(this.normalShader.uniforms.uWorld, false, transform);
|
||||
gl.uniformMatrix4fv(this.normalShader.uniforms.uView, false, camera.viewMatrix);
|
||||
gl.uniformMatrix4fv(this.normalShader.uniforms.uProj, false, camera.projectionMatrix);
|
||||
gl.uniform1f(this.normalShader.uniforms.uPointSize, this.pointSize);
|
||||
gl.uniform1f(this.normalShader.uniforms.uNear, camera.nearClipPlane);
|
||||
gl.uniform1f(this.normalShader.uniforms.uFar, camera.farClipPlane);
|
||||
|
||||
gl.uniform2f(this.depthShader.uniforms.uWindowSize, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
|
||||
var nearHeight = 2*camera.nearClipPlane*Math.tan(camera.fieldOfView*Math.PI/360);
|
||||
var nearWidth = nearHeight*camera.aspectRatio;
|
||||
gl.uniform2f(this.depthShader.uniforms.uNearWindowSize, nearWidth, nearHeight);
|
||||
}
|
||||
|
||||
for(var i = 0; i < pointClouds.length; i++){
|
||||
var pointCloud = pointClouds[i];
|
||||
var pointAttributes = pointCloud.pointAttributes;
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, pointCloud.vbo);
|
||||
var offset = 0;
|
||||
for(var j = 0; j < pointAttributes.size; j++){
|
||||
var attribute = pointAttributes.attributes[j];
|
||||
|
||||
if(attribute === PointAttribute.POSITION_CARTESIAN){
|
||||
gl.enableVertexAttribArray(this.normalShader.attributes.aVertexPosition);
|
||||
gl.vertexAttribPointer(this.normalShader.attributes.aVertexPosition, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}else if(attribute === PointAttribute.RGBA_PACKED){
|
||||
if(this.normalShader.attributes.aVertexColour != null){
|
||||
gl.enableVertexAttribArray(this.normalShader.attributes.aVertexColour);
|
||||
gl.vertexAttribPointer(this.normalShader.attributes.aVertexColour, 3, gl.UNSIGNED_BYTE, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}else if(attribute === PointAttribute.NORMAL_FLOATS){
|
||||
if(this.normalShader.attributes.aNormal != null){
|
||||
gl.enableVertexAttribArray(this.normalShader.attributes.aNormal);
|
||||
gl.vertexAttribPointer(this.normalShader.attributes.aNormal, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}
|
||||
offset += attribute.byteSize;
|
||||
}
|
||||
|
||||
gl.drawArrays(gl.POINTS, 0, pointCloud.size);
|
||||
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aVertexPosition);
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aVertexColour);
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aNormal);
|
||||
}
|
||||
gl.depthFunc(gl.LESS);
|
||||
gl.depthMask(true);
|
||||
};
|
||||
|
||||
var startTime = new Date().getTime();
|
||||
|
||||
/**
|
||||
* normalize output from second pass.
|
||||
* rgb values are divided by the weight(stored in the alpha component) and alpha is set to 1.
|
||||
* renders into the buffer which was active before this material was used.
|
||||
*
|
||||
*/
|
||||
FilteredSplatsMaterial.prototype.shadingPass = function(oldBuffer, renderer){
|
||||
var camera = renderer.camera;
|
||||
var lights = renderer.lights;
|
||||
|
||||
oldBuffer.bind();
|
||||
|
||||
// var cColor = Potree.Settings.backgroundColor;
|
||||
// gl.clearColor(cColor[0], cColor[1], cColor[2], cColor[3]);
|
||||
gl.clearColor(0,0,0,1.0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||
|
||||
gl.useProgram(this.normalizationShader.program);
|
||||
gl.disable(gl.DEPTH_TEST);
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(gl.ONE, gl.ONE);
|
||||
|
||||
// normal
|
||||
// if(this.illuminationMode === IlluminationMode.PHONG || this.illuminationMode === IlluminationMode.NORMALS){
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.normalFBO.texture.glid);
|
||||
gl.uniform1i(this.normalizationShader.uniforms.uNormal, 0);
|
||||
// }
|
||||
|
||||
// color
|
||||
// if(this.illuminationMode === IlluminationMode.FLAT || this.illuminationMode === IlluminationMode.PHONG){
|
||||
gl.activeTexture(gl.TEXTURE0 + 1);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.colorFBO.texture.glid);
|
||||
gl.uniform1i(this.normalizationShader.uniforms.uColor, 1);
|
||||
// }
|
||||
|
||||
// position
|
||||
// if(this.illuminationMode === IlluminationMode.PHONG || this.illuminationMode === IlluminationMode.POSITIONS){
|
||||
gl.activeTexture(gl.TEXTURE0 + 2);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.depthFBO.texture.glid);
|
||||
gl.uniform1i(this.normalizationShader.uniforms.uPosition, 2);
|
||||
// }
|
||||
|
||||
gl.uniform1i(this.normalizationShader.uniforms.uIlluminationMode, this.illuminationMode.value);
|
||||
|
||||
if(this.illuminationMode === IlluminationMode.PHONG){
|
||||
for(var i = 0; i < lights.length; i++){
|
||||
var light = lights[i];
|
||||
var pos = light.globalPosition;
|
||||
|
||||
gl.uniform3f(this.normalizationShader.uniforms.uLightPos, pos.x, pos.y, pos.z);
|
||||
gl.uniform3f(this.normalizationShader.uniforms.uLightColor, light.red, light.green, light.blue);
|
||||
oldBuffer.drawFullscreenQuad(this.normalizationShader);
|
||||
}
|
||||
}else{
|
||||
oldBuffer.drawFullscreenQuad(this.normalizationShader);
|
||||
}
|
||||
};
|
||||
@ -1,86 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
* @class renders points with a fixed pixel size.
|
||||
* @augments Material
|
||||
* @author Markus Schütz
|
||||
*/
|
||||
function FixedPointSizeMaterial(name){
|
||||
Material.call(this, name);
|
||||
this.shader = new Shader(name, "fixedPointSize.vs", "colouredPoint.fs");
|
||||
|
||||
this.pointSize = 1.0;
|
||||
}
|
||||
|
||||
FixedPointSizeMaterial.prototype = new Material(inheriting);
|
||||
|
||||
FixedPointSizeMaterial.prototype.render = function(sceneNode, renderer){
|
||||
var transform = sceneNode.globalTransformation;
|
||||
var pointClouds = new Array();
|
||||
|
||||
if(sceneNode instanceof PointCloudSceneNode){
|
||||
pointClouds.push(sceneNode.pointCloud);
|
||||
}else if(sceneNode instanceof PointcloudOctreeSceneNode){
|
||||
var renderQueue = sceneNode.mno.renderQueue;
|
||||
for(var i = 0; i < renderQueue.length; i++){
|
||||
var node = renderQueue.get(i);
|
||||
pointClouds.push(node.pointCloud);
|
||||
}
|
||||
}
|
||||
|
||||
if(renderer.fboColor != null){
|
||||
this.renderPointClouds(transform, pointClouds, renderer);
|
||||
}
|
||||
};
|
||||
|
||||
FixedPointSizeMaterial.prototype.renderPointClouds = function(transform, pointClouds, renderer){
|
||||
var camera = renderer.camera;
|
||||
var lights = renderer.lights;
|
||||
|
||||
renderer.fboColor.bind();
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.disable(gl.BLEND);
|
||||
|
||||
gl.useProgram(this.shader.program);
|
||||
|
||||
{ // uniforms
|
||||
gl.uniformMatrix4fv(this.shader.uniforms.uWorld, false, transform);
|
||||
gl.uniformMatrix4fv(this.shader.uniforms.uView, false, camera.viewMatrix);
|
||||
gl.uniformMatrix4fv(this.shader.uniforms.uProj, false, camera.projectionMatrix);
|
||||
gl.uniform1f(this.shader.uniforms.uPointSize, this.pointSize);
|
||||
gl.uniform2f(this.shader.uniforms.uViewportSize, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
}
|
||||
|
||||
for(var i = 0; i < pointClouds.length; i++){
|
||||
var pointCloud = pointClouds[i];
|
||||
var pointAttributes = pointCloud.pointAttributes;
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, pointCloud.vbo);
|
||||
var offset = 0;
|
||||
for(var j = 0; j < pointAttributes.size; j++){
|
||||
var attribute = pointAttributes.attributes[j];
|
||||
|
||||
if(attribute == PointAttribute.POSITION_CARTESIAN){
|
||||
gl.enableVertexAttribArray(this.shader.attributes.aVertexPosition);
|
||||
gl.vertexAttribPointer(this.shader.attributes.aVertexPosition, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}else if(attribute == PointAttribute.COLOR_PACKED){
|
||||
if(this.shader.attributes.aVertexColour != null){
|
||||
gl.enableVertexAttribArray(this.shader.attributes.aVertexColour);
|
||||
gl.vertexAttribPointer(this.shader.attributes.aVertexColour, 3, gl.UNSIGNED_BYTE, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}else if(attribute == PointAttribute.NORMAL_FLOATS){
|
||||
if(this.shader.attributes.aNormal != null){
|
||||
gl.enableVertexAttribArray(this.shader.attributes.aNormal);
|
||||
gl.vertexAttribPointer(this.shader.attributes.aNormal, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}
|
||||
offset += attribute.byteSize;
|
||||
}
|
||||
|
||||
gl.drawArrays(gl.POINTS, 0, pointCloud.size);
|
||||
|
||||
gl.disableVertexAttribArray(this.shader.attributes.aVertexPosition);
|
||||
gl.disableVertexAttribArray(this.shader.attributes.aVertexColour);
|
||||
gl.disableVertexAttribArray(this.shader.attributes.aNormal);
|
||||
}
|
||||
};
|
||||
@ -1,75 +0,0 @@
|
||||
|
||||
/**
|
||||
* @class render an object without illumination
|
||||
* @augments Material
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
function FlatMaterial(name, color){
|
||||
Material.call(this, name);
|
||||
this.flatShader = new Shader( name, "flatShader.vs", "flatShader.fs");
|
||||
|
||||
if(color != null){
|
||||
this.color = color;
|
||||
}else{
|
||||
this.color = [1.0, 0.0, 0.0, 1.0];
|
||||
}
|
||||
}
|
||||
|
||||
FlatMaterial.prototype = new Material(inheriting);
|
||||
|
||||
FlatMaterial.prototype.setColor = function(color){
|
||||
this.color = color;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param object may be either a SubMesh or a PointcloudOctree
|
||||
* @param sceneNode
|
||||
* @param camera
|
||||
*/
|
||||
FlatMaterial.prototype.render = function(object, sceneNode, renderer){
|
||||
if(object instanceof AABB){
|
||||
this.renderAABB(object, sceneNode, renderer);
|
||||
}else if(object instanceof SubMesh){
|
||||
this.renderSubMesh(object, sceneNode, renderer);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
FlatMaterial.prototype.renderSubMesh = function(subMesh, meshNode, renderer){
|
||||
var camera = renderer.camera;
|
||||
var lights = renderer.lights;
|
||||
var shader = this.flatShader;
|
||||
|
||||
var scene = camera.scene;
|
||||
var mesh = meshNode.mesh;
|
||||
gl.useProgram(shader.program);
|
||||
|
||||
// uniforms
|
||||
gl.uniformMatrix4fv(shader.uniforms.uWorld, false, meshNode.globalTransformation);
|
||||
gl.uniformMatrix4fv(shader.uniforms.uView, false, camera.viewMatrix);
|
||||
gl.uniformMatrix4fv(shader.uniforms.uProj, false, camera.projectionMatrix);
|
||||
var viewPos = camera.globalPosition;
|
||||
gl.uniform3f(shader.uniforms.uViewPos, viewPos[0], viewPos[1], viewPos[2]);
|
||||
gl.uniform4f(shader.uniforms.uColor, this.color[0], this.color[1], this.color[2], this.color[3]);
|
||||
|
||||
// vertex attributes
|
||||
gl.enableVertexAttribArray(shader.attributes.aVertexPosition);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, subMesh.vbos["POSITION"]);
|
||||
gl.vertexAttribPointer(shader.attributes.aVertexPosition, 3, gl.FLOAT, false, 0, 0);
|
||||
|
||||
if(subMesh.vbos["TEXCOORD_0"] != null && shader.attributes.aTextureCoord != null ){
|
||||
gl.enableVertexAttribArray(shader.attributes.aTextureCoord);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, subMesh.vbos["TEXCOORD_0"]);
|
||||
gl.vertexAttribPointer(shader.attributes.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
|
||||
}
|
||||
|
||||
if(subMesh.ibo != null){
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, subMesh.ibo);
|
||||
gl.drawElements(mesh.glType, subMesh.indices.length, gl.UNSIGNED_SHORT, 0);
|
||||
}else if(subMesh.vertexCount != null){
|
||||
gl.lineWidth(10.0);
|
||||
gl.drawArrays(mesh.glType, 0, subMesh.vertexCount);
|
||||
}
|
||||
};
|
||||
@ -1,286 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @class
|
||||
* @see http://graphics.ucsd.edu/~matthias/Papers/HighQualitySplattingOnGPUs.pdf
|
||||
*
|
||||
*/
|
||||
function GaussFillMaterial(name){
|
||||
if(!GaussFillMaterial.isSupported()){
|
||||
throw new Error("GaussFillMaterial is not supported on your system. OES_texture_float extension is not available.");
|
||||
}
|
||||
|
||||
Material.call(this, name);
|
||||
this.depthShader = new Shader(name + "_depth", "gaussFill/gaussFillDepthPass.vs", "gaussFill/gaussFillDepthPass.fs");
|
||||
this.colorShader = new Shader(name + "_filtered_color", "gaussFill/gaussFillPointsPass.vs", "gaussFill/gaussFillPointsPass.fs");
|
||||
this.spreadXShader = new Shader(name + "_spreadX", "drawTexture.vs", "gaussFill/gaussFillSpreadXPass.fs");
|
||||
this.spreadYShader = new Shader(name + "_spreadY", "drawTexture.vs", "gaussFill/gaussFillSpreadYPass.fs");
|
||||
this.normalizationShader = new Shader(name + "normalization", "drawTexture.vs", "gaussFill/gaussFillNormalizationPass.fs");
|
||||
this.depthFBO = new Framebuffer(Potree.canvas.width, Potree.canvas.height);
|
||||
this.colorFBO = new Framebuffer(Potree.canvas.width, Potree.canvas.height);
|
||||
this.spreadXFBO = new FramebufferFloat32(Potree.canvas.width, Potree.canvas.height);
|
||||
this.spreadYFBO = new FramebufferFloat32(Potree.canvas.width, Potree.canvas.height);
|
||||
|
||||
this.illuminationMode = IlluminationMode.PHONG;
|
||||
this.pointSize = 1.0;
|
||||
this.blendDepth = 0.1;
|
||||
|
||||
this.gaussKernel = [0.0216149, 0.0439554, 0.0778778, 0.118718, 0.153857, 0.167953, 0.153857, 0.118718, 0.0778778, 0.0439554, 0.0216149];
|
||||
|
||||
for(var i = 0; i < this.gaussKernel.length; i++){
|
||||
this.gaussKernel[i] = Math.pow(this.gaussKernel[i] + 0.1, 20);
|
||||
}
|
||||
}
|
||||
|
||||
GaussFillMaterial.prototype = new Material(inheriting);
|
||||
|
||||
GaussFillMaterial.isSupported = function(){
|
||||
if (gl.getExtension("OES_texture_float") == null) {
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
GaussFillMaterial.prototype.render = function(sceneNode, renderer){
|
||||
var transform = sceneNode.globalTransformation;
|
||||
var pointClouds = new Array();
|
||||
|
||||
if(sceneNode instanceof PointCloudSceneNode){
|
||||
pointClouds.push(sceneNode.pointCloud);
|
||||
}else if(sceneNode instanceof PointcloudOctreeSceneNode){
|
||||
var renderQueue = sceneNode.mno.renderQueue;
|
||||
for(var i = 0; i < renderQueue.length; i++){
|
||||
var node = renderQueue.get(i);
|
||||
pointClouds.push(node.pointCloud);
|
||||
}
|
||||
}
|
||||
this.renderPointClouds(transform, pointClouds, renderer);
|
||||
};
|
||||
|
||||
GaussFillMaterial.prototype.renderPointClouds = function(transform, pointClouds, renderer){
|
||||
var oldBuffer = Framebuffer.getActiveBuffer();
|
||||
var camera = renderer.camera;
|
||||
var lights = renderer.lights;
|
||||
|
||||
this.depthPass(transform, pointClouds, camera);
|
||||
this.pointsPass(transform, pointClouds, camera);
|
||||
this.spreadXPass(transform, pointClouds, camera);
|
||||
this.spreadYPass(transform, pointClouds, camera);
|
||||
this.normalizationPass(oldBuffer, camera, lights);
|
||||
|
||||
// oldBuffer.drawTexture(this.colorFBO.texture, [0,0], [1,1]);
|
||||
// oldBuffer.drawTexture(this.normalFBO.texture, [-1,0], [0,1]);
|
||||
// oldBuffer.drawTexture(this.depthFBO.texture, [-1,0], [0,1]);
|
||||
// oldBuffer.drawTexture(this.depthFBO.texture, [-1,-1], [1,1]);
|
||||
};
|
||||
|
||||
/**
|
||||
* create depth map.
|
||||
* this pass renders into the depthFBO which is defined as a floating point texture.
|
||||
* linear depth is stored in the first value of each pixel.
|
||||
*
|
||||
*/
|
||||
GaussFillMaterial.prototype.depthPass = function(transform, pointClouds, camera){
|
||||
|
||||
this.depthFBO.bind();
|
||||
this.depthFBO.setSize(Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.viewport(0, 0, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.clearColor(0,0,0,0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||
|
||||
gl.disable(gl.BLEND);
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.depthMask(true);
|
||||
|
||||
{// uniforms
|
||||
gl.useProgram(this.depthShader.program);
|
||||
gl.uniformMatrix4fv(this.depthShader.uniforms.uWorld, false, transform);
|
||||
gl.uniformMatrix4fv(this.depthShader.uniforms.uView, false, camera.viewMatrix);
|
||||
gl.uniformMatrix4fv(this.depthShader.uniforms.uProj, false, camera.projectionMatrix);
|
||||
gl.uniform1f(this.depthShader.uniforms.uPointSize, this.pointSize);
|
||||
gl.uniform1f(this.depthShader.uniforms.uNear, camera.nearClipPlane);
|
||||
gl.uniform1f(this.depthShader.uniforms.uFar, camera.farClipPlane);
|
||||
gl.uniform1f(this.depthShader.uniforms.uBlendDepth, this.blendDepth);
|
||||
gl.uniform2f(this.depthShader.uniforms.uWindowSize, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
|
||||
var nearHeight = 2*camera.nearClipPlane*Math.tan(camera.fieldOfView*Math.PI/360);
|
||||
var nearWidth = nearHeight*camera.aspectRatio;
|
||||
gl.uniform2f(this.depthShader.uniforms.uNearWindowSize, nearWidth, nearHeight);
|
||||
|
||||
}
|
||||
|
||||
for(var i = 0; i < pointClouds.length; i++){
|
||||
var pointCloud = pointClouds[i];
|
||||
var pointAttributes = pointCloud.pointAttributes;
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, pointCloud.vbo);
|
||||
var offset = 0;
|
||||
for(var j = 0; j < pointAttributes.size; j++){
|
||||
var attribute = pointAttributes.attributes[j];
|
||||
|
||||
if(attribute === PointAttribute.POSITION_CARTESIAN){
|
||||
gl.enableVertexAttribArray(this.depthShader.attributes.aVertexPosition);
|
||||
gl.vertexAttribPointer(this.depthShader.attributes.aVertexPosition, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}else if(attribute === PointAttribute.RGBA_PACKED){
|
||||
if(this.depthShader.attributes.aVertexColour != null){
|
||||
gl.enableVertexAttribArray(this.depthShader.attributes.aVertexColour);
|
||||
gl.vertexAttribPointer(this.depthShader.attributes.aVertexColour, 3, gl.UNSIGNED_BYTE, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}else if(attribute === PointAttribute.NORMAL_FLOATS){
|
||||
if(this.depthShader.attributes.aNormal != null){
|
||||
gl.enableVertexAttribArray(this.depthShader.attributes.aNormal);
|
||||
gl.vertexAttribPointer(this.depthShader.attributes.aNormal, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}
|
||||
offset += attribute.byteSize;
|
||||
}
|
||||
|
||||
gl.drawArrays(gl.POINTS, 0, pointCloud.size);
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aVertexPosition);
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aVertexColour);
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aNormal);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
GaussFillMaterial.prototype.pointsPass = function(transform, pointClouds, camera){
|
||||
// color fbo
|
||||
this.colorFBO.bind();
|
||||
this.colorFBO.setSize(Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, this.depthFBO.renderbuffer);
|
||||
this.colorFBO.checkBuffer();
|
||||
gl.viewport(0, 0, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.clearColor(0,0,0,0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
gl.disable(gl.BLEND);
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
// gl.disable(gl.DEPTH_TEST);
|
||||
gl.depthFunc(gl.LEQUAL);
|
||||
gl.depthMask(false);
|
||||
|
||||
{ // color uniforms
|
||||
gl.useProgram(this.colorShader.program);
|
||||
gl.uniformMatrix4fv(this.colorShader.uniforms.uWorld, false, transform);
|
||||
gl.uniformMatrix4fv(this.colorShader.uniforms.uView, false, camera.viewMatrix);
|
||||
gl.uniformMatrix4fv(this.colorShader.uniforms.uProj, false, camera.projectionMatrix);
|
||||
gl.uniform1f(this.colorShader.uniforms.uNear, camera.nearClipPlane);
|
||||
gl.uniform1f(this.colorShader.uniforms.uFar, camera.farClipPlane);
|
||||
gl.uniform1f(this.colorShader.uniforms.uPointSize, this.pointSize);
|
||||
}
|
||||
|
||||
for(var i = 0; i < pointClouds.length; i++){
|
||||
var pointCloud = pointClouds[i];
|
||||
var pointAttributes = pointCloud.pointAttributes;
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, pointCloud.vbo);
|
||||
var offset = 0;
|
||||
for(var j = 0; j < pointAttributes.size; j++){
|
||||
var attribute = pointAttributes.attributes[j];
|
||||
|
||||
if(attribute === PointAttribute.POSITION_CARTESIAN){
|
||||
gl.enableVertexAttribArray(this.colorShader.attributes.aVertexPosition);
|
||||
gl.vertexAttribPointer(this.colorShader.attributes.aVertexPosition, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}else if(attribute === PointAttribute.RGBA_PACKED){
|
||||
if(this.colorShader.attributes.aVertexColour != null){
|
||||
gl.enableVertexAttribArray(this.colorShader.attributes.aVertexColour);
|
||||
gl.vertexAttribPointer(this.colorShader.attributes.aVertexColour, 3, gl.UNSIGNED_BYTE, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}else if(attribute === PointAttribute.NORMAL_FLOATS){
|
||||
if(this.colorShader.attributes.aNormal != null){
|
||||
gl.enableVertexAttribArray(this.colorShader.attributes.aNormal);
|
||||
gl.vertexAttribPointer(this.colorShader.attributes.aNormal, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}
|
||||
offset += attribute.byteSize;
|
||||
}
|
||||
|
||||
gl.drawArrays(gl.POINTS, 0, pointCloud.size);
|
||||
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aVertexPosition);
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aVertexColour);
|
||||
gl.disableVertexAttribArray(this.depthShader.attributes.aNormal);
|
||||
}
|
||||
gl.depthFunc(gl.LESS);
|
||||
gl.depthMask(true);
|
||||
};
|
||||
|
||||
GaussFillMaterial.prototype.spreadXPass = function(oldBuffer, camera, lights){
|
||||
// color fbo
|
||||
this.spreadXFBO.bind();
|
||||
this.spreadXFBO.setSize(Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.viewport(0, 0, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.disable(gl.BLEND);
|
||||
|
||||
gl.clearColor(0,0,0,0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||
|
||||
gl.useProgram(this.spreadXShader.program);
|
||||
gl.disable(gl.DEPTH_TEST);
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(gl.ONE, gl.ONE);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0 + 1);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.colorFBO.texture.glid);
|
||||
gl.uniform1i(this.spreadXShader.uniforms.uColor, 1);
|
||||
gl.uniform2f(this.spreadXShader.uniforms.uWindowSize, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.uniform1fv(this.spreadXShader.uniforms["uKernel[0]"],this.gaussKernel);
|
||||
|
||||
this.spreadXFBO.drawFullscreenQuad(this.spreadXShader);
|
||||
};
|
||||
|
||||
GaussFillMaterial.prototype.spreadYPass = function(oldBuffer, camera, lights){
|
||||
// color fbo
|
||||
this.spreadYFBO.bind();
|
||||
this.spreadYFBO.setSize(Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.viewport(0, 0, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.disable(gl.BLEND);
|
||||
|
||||
gl.clearColor(0,0,0,0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||
|
||||
gl.useProgram(this.spreadYShader.program);
|
||||
gl.disable(gl.DEPTH_TEST);
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(gl.ONE, gl.ONE);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0 + 1);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.spreadXFBO.texture.glid);
|
||||
gl.uniform1i(this.spreadYShader.uniforms.uColor, 1);
|
||||
gl.uniform2f(this.spreadYShader.uniforms.uWindowSize, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
gl.uniform1fv(this.spreadYShader.uniforms["uKernel[0]"],this.gaussKernel);
|
||||
|
||||
this.spreadYFBO.drawFullscreenQuad(this.spreadYShader);
|
||||
};
|
||||
|
||||
|
||||
var startTime = new Date().getTime();
|
||||
|
||||
/**
|
||||
* normalize output from second pass.
|
||||
* rgb values are divided by the weight(stored in the alpha component) and alpha is set to 1.
|
||||
* renders into the buffer which was active before this material was used.
|
||||
*
|
||||
*/
|
||||
GaussFillMaterial.prototype.normalizationPass = function(oldBuffer, camera, lights){
|
||||
oldBuffer.bind();
|
||||
|
||||
// var cColor = Potree.Settings.backgroundColor;
|
||||
// gl.clearColor(cColor[0], cColor[1], cColor[2], cColor[3]);
|
||||
gl.clearColor(0,0,0,1.0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||
|
||||
gl.useProgram(this.normalizationShader.program);
|
||||
gl.disable(gl.DEPTH_TEST);
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(gl.ONE, gl.ONE);
|
||||
|
||||
// color
|
||||
gl.activeTexture(gl.TEXTURE0 + 1);
|
||||
// gl.bindTexture(gl.TEXTURE_2D, this.colorFBO.texture.glid);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.spreadYFBO.texture.glid);
|
||||
gl.uniform1i(this.normalizationShader.uniforms.uColor, 1);
|
||||
|
||||
oldBuffer.drawFullscreenQuad(this.normalizationShader);
|
||||
};
|
||||
@ -1,21 +0,0 @@
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {String} name a unique name for the material or null. If name is null, a unique name will be generated.
|
||||
* @class The base class for all materials.
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
function Material(name){
|
||||
if (arguments[0] === inheriting) return;
|
||||
|
||||
if(name == null){
|
||||
name = "Material_" + Material.count;
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
MaterialManager.addMaterial(this);
|
||||
|
||||
Material.count++;
|
||||
}
|
||||
|
||||
Material.count = 0;
|
||||
@ -1,74 +0,0 @@
|
||||
|
||||
/**
|
||||
* @class render an object without illumination
|
||||
* @augments Material
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
function PhongMaterial(name, color){
|
||||
Material.call(this, name);
|
||||
this.flatShader = new Shader( name, "phong.vs", "phong.fs");
|
||||
|
||||
if(color != null){
|
||||
this.color = color;
|
||||
}else{
|
||||
this.color = [1.0, 0.0, 0.0, 1.0];
|
||||
}
|
||||
}
|
||||
|
||||
PhongMaterial.prototype = new Material(inheriting);
|
||||
|
||||
PhongMaterial.prototype.setColor = function(color){
|
||||
this.color = color;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param object may be either a SubMesh or a PointcloudOctree
|
||||
* @param sceneNode
|
||||
* @param camera
|
||||
*/
|
||||
PhongMaterial.prototype.render = function(object, sceneNode, camera){
|
||||
if(object instanceof AABB){
|
||||
this.renderAABB(object, sceneNode, camera);
|
||||
}else if(object instanceof SubMesh){
|
||||
this.renderSubMesh(object, sceneNode, camera);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
PhongMaterial.prototype.renderSubMesh = function(subMesh, meshNode, camera, lights){
|
||||
var shader = this.flatShader;
|
||||
|
||||
var scene = camera.scene;
|
||||
var mesh = meshNode.mesh;
|
||||
gl.useProgram(shader.program);
|
||||
|
||||
// uniforms
|
||||
gl.uniformMatrix4fv(shader.uniforms.uWorld, false, meshNode.globalTransformation);
|
||||
gl.uniformMatrix4fv(shader.uniforms.uView, false, camera.viewMatrix);
|
||||
gl.uniformMatrix4fv(shader.uniforms.uProj, false, camera.projectionMatrix);
|
||||
var viewPos = camera.globalPosition;
|
||||
gl.uniform3f(shader.uniforms.uViewPos, viewPos[0], viewPos[1], viewPos[2]);
|
||||
gl.uniform4f(shader.uniforms.uColor, this.color[0], this.color[1], this.color[2], this.color[3]);
|
||||
|
||||
{// vertex attributes
|
||||
gl.enableVertexAttribArray(shader.attributes.aVertexPosition);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, subMesh.vbos["POSITION"]);
|
||||
gl.vertexAttribPointer(shader.attributes.aVertexPosition, 3, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.enableVertexAttribArray(shader.attributes.aVertexNormal);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, subMesh.vbos["NORMAL"]);
|
||||
gl.vertexAttribPointer(shader.attributes.aVertexNormal, 3, gl.FLOAT, false, 0, 0);
|
||||
}
|
||||
|
||||
if(subMesh.ibo != null){
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, subMesh.ibo);
|
||||
gl.drawElements(mesh.glType, subMesh.indices.length, gl.UNSIGNED_SHORT, 0);
|
||||
}else if(subMesh.vertexCount != null){
|
||||
gl.lineWidth(10.0);
|
||||
gl.drawArrays(mesh.glType, 0, subMesh.vertexCount);
|
||||
}
|
||||
gl.disableVertexAttribArray(shader.attributes.aVertexNormal);
|
||||
gl.disableVertexAttribArray(shader.attributes.aVertexPosition);
|
||||
};
|
||||
@ -1,140 +0,0 @@
|
||||
|
||||
/**
|
||||
* Specify how points are to be shaded
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
var IlluminationMode = {
|
||||
FLAT : {value:0, name: "Flat"},
|
||||
PHONG : {value:1, name: "Phong"},
|
||||
NORMALS : {value:2, name: "Normals"},
|
||||
POSITION : {value:3, name: "Position"}
|
||||
};
|
||||
|
||||
/**
|
||||
* specify how points are to be rasterized
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
var PointCloudRenderMode = {
|
||||
FIXED_CIRCLE : {value:0, name: "fixed circle"},
|
||||
WEIGHTED_CIRCLE : {value:1, name: "weighted circle"},
|
||||
FILTERED_SPLAT : {value:3, name: "filtered splat"},
|
||||
GAUSS_FILL : {value:4, name: "gauss fill"}
|
||||
};
|
||||
|
||||
/**
|
||||
* Eierlegende wollmilchsau.
|
||||
* combines different materials.
|
||||
*
|
||||
* @param name
|
||||
* @class
|
||||
* @augments Material
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
function PointCloudMaterial(name){
|
||||
Material.call(this, name);
|
||||
|
||||
this.renderMode = PointCloudRenderMode.WEIGHTED_CIRCLE;
|
||||
|
||||
if(FilteredSplatsMaterial.isSupported()){
|
||||
this.filteredMaterial = new FilteredSplatsMaterial(name + "_filtered");
|
||||
}else{
|
||||
this.filteredMaterial = null;
|
||||
}
|
||||
this.weightedMaterial = new WeightedPointSizeMaterial(name + "_weighted");
|
||||
this.fixedMaterial = new FixedPointSizeMaterial(name + "_fixed");
|
||||
|
||||
if(GaussFillMaterial.isSupported()){
|
||||
this.gaussFillMaterial = new GaussFillMaterial(name + "_fill");
|
||||
}else{
|
||||
this.gaussFillMaterial = null;
|
||||
}
|
||||
|
||||
this.activeMaterial = this.weightedMaterial;
|
||||
this.pointSize = 0.2;
|
||||
this.blendDepth = 0.1;
|
||||
this.illuminationMode = IlluminationMode.FLAT;
|
||||
}
|
||||
|
||||
PointCloudMaterial.prototype = new Material(inheriting);
|
||||
|
||||
PointCloudMaterial.prototype.render = function(sceneNode, renderer){
|
||||
if(renderer.fboDepthAsRGBA != null){
|
||||
this.weightedMaterial.render(sceneNode, renderer);
|
||||
}else{
|
||||
this.activeMaterial.render(sceneNode, renderer);
|
||||
}
|
||||
};
|
||||
|
||||
Object.defineProperty(PointCloudMaterial.prototype, 'renderMode', {
|
||||
set: function(renderMode){
|
||||
this._renderMode = renderMode;
|
||||
|
||||
if(this.renderMode === PointCloudRenderMode.FIXED_CIRCLE){
|
||||
this.activeMaterial = this.fixedMaterial;
|
||||
}else if(this.renderMode === PointCloudRenderMode.WEIGHTED_CIRCLE){
|
||||
this.activeMaterial = this.weightedMaterial;
|
||||
}else if(this.renderMode === PointCloudRenderMode.FILTERED_SPLAT){
|
||||
if(FilteredSplatsMaterial.isSupported()){
|
||||
this.activeMaterial = this.filteredMaterial;
|
||||
}else{
|
||||
this.activeMaterial = this.weightedMaterial;
|
||||
console.log("FILTERED_SPLAT material is not supported on your system. ");
|
||||
}
|
||||
}else if(this.renderMode === PointCloudRenderMode.GAUSS_FILL){
|
||||
if(GaussFillMaterial.isSupported()){
|
||||
this.activeMaterial = this.gaussFillMaterial;
|
||||
}else{
|
||||
this.activeMaterial = this.weightedMaterial;
|
||||
console.log("GAUSS_FILL material is not supported on your system. ");
|
||||
}
|
||||
}
|
||||
},
|
||||
get: function(){
|
||||
return this._renderMode;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(PointCloudMaterial.prototype, 'pointSize', {
|
||||
set: function(pointSize){
|
||||
this._pointSize = pointSize;
|
||||
if(this.filteredMaterial !== null){
|
||||
this.filteredMaterial.pointSize = pointSize;
|
||||
}
|
||||
this.weightedMaterial.pointSize = pointSize;
|
||||
this.fixedMaterial.pointSize = pointSize;
|
||||
if(this.gaussFillMaterial !== null){
|
||||
this.gaussFillMaterial.pointSize = pointSize;
|
||||
}
|
||||
},
|
||||
get: function(){
|
||||
return this._pointSize;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(PointCloudMaterial.prototype, 'blendDepth', {
|
||||
set: function(blendDepth){
|
||||
this._blendDepth = blendDepth;
|
||||
if(this.filteredMaterial != null){
|
||||
this.filteredMaterial.blendDepth = blendDepth;
|
||||
}
|
||||
},
|
||||
get: function(){
|
||||
return this._blendDepth;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(PointCloudMaterial.prototype, 'illuminationMode', {
|
||||
set: function(illuminationMode){
|
||||
this._illuminationMode = illuminationMode;
|
||||
if(FilteredSplatsMaterial.isSupported()){
|
||||
this.filteredMaterial.illuminationMode = illuminationMode;
|
||||
}
|
||||
this.weightedMaterial.illuminationMode = illuminationMode;
|
||||
this.fixedMaterial.illuminationMode = illuminationMode;
|
||||
},
|
||||
get: function(){
|
||||
return this._illuminationMode;
|
||||
}
|
||||
});
|
||||
@ -1,188 +0,0 @@
|
||||
|
||||
/**
|
||||
*
|
||||
* @class point size depends on distance from eye.
|
||||
* this may change so that point size depends on more factors like child node visibility, density of a node, etc.
|
||||
*
|
||||
* @augments Material
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
function WeightedPointSizeMaterial(name){
|
||||
Material.call(this, name);
|
||||
this.shader = new Shader(name + "_color", "pointSize.vs", "colouredPoint.fs");
|
||||
this.posShader = new Shader(name + "_position", "weightedPoints/weightedPointsPosition.vs", "weightedPoints/weightedPointsPosition.fs");
|
||||
this.rgbaDepthShader = new Shader(name + "_depthRGBA", "weightedPoints/weightedPointsDepthAsRGBA.vs", "weightedPoints/weightedPointsDepthAsRGBA.fs");
|
||||
|
||||
this.pointSize = 0.3;
|
||||
}
|
||||
|
||||
WeightedPointSizeMaterial.prototype = new Material(inheriting);
|
||||
|
||||
WeightedPointSizeMaterial.prototype.render = function(sceneNode, renderer){
|
||||
var transform = sceneNode.globalTransformation;
|
||||
var pointClouds = new Array();
|
||||
|
||||
if(sceneNode instanceof PointCloudSceneNode){
|
||||
pointClouds.push(sceneNode.pointCloud);
|
||||
}else if(sceneNode instanceof PointcloudOctreeSceneNode){
|
||||
var renderQueue = sceneNode.mno.renderQueue;
|
||||
for(var i = 0; i < renderQueue.length; i++){
|
||||
var node = renderQueue.get(i);
|
||||
// if(node.level > 2){
|
||||
// continue;
|
||||
// }
|
||||
pointClouds.push(node.pointCloud);
|
||||
}
|
||||
}
|
||||
|
||||
if(renderer.fboColor != null){
|
||||
this.renderPointClouds(transform, pointClouds, renderer);
|
||||
}
|
||||
if(renderer.fboPosition != null){
|
||||
this.renderPointCloudsPosition(transform, pointClouds, renderer);
|
||||
}
|
||||
if(renderer.fboDepthAsRGBA != null){
|
||||
this.renderPointCloudsDepthAsRGBA(transform, pointClouds, renderer);
|
||||
}
|
||||
};
|
||||
|
||||
WeightedPointSizeMaterial.prototype.renderPointCloudsDepthAsRGBA = function renderPointCloudsDepthAsRGBA(transform, pointClouds, renderer){
|
||||
var camera = renderer.camera;
|
||||
var lights = renderer.lights;
|
||||
|
||||
renderer.fboDepthAsRGBA.bind();
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.disable(gl.BLEND);
|
||||
|
||||
var shader = this.rgbaDepthShader;
|
||||
var uniforms = shader.uniforms;
|
||||
var attributes = shader.attributes;
|
||||
|
||||
gl.useProgram(shader.program);
|
||||
|
||||
{ // uniforms
|
||||
gl.uniformMatrix4fv(uniforms.uWorld, false, transform);
|
||||
gl.uniformMatrix4fv(uniforms.uView, false, camera.viewMatrix);
|
||||
gl.uniformMatrix4fv(uniforms.uProj, false, camera.projectionMatrix);
|
||||
gl.uniform1f(uniforms.uPointSizeMultiplicator, this.pointSize);
|
||||
gl.uniform2f(uniforms.uViewportSize, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
}
|
||||
|
||||
for(var i = 0; i < pointClouds.length; i++){
|
||||
var pointCloud = pointClouds[i];
|
||||
var pointAttributes = pointCloud.pointAttributes;
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, pointCloud.vbo);
|
||||
var offset = 0;
|
||||
for(var j = 0; j < pointAttributes.size; j++){
|
||||
var attribute = pointAttributes.attributes[j];
|
||||
|
||||
if(attribute === PointAttribute.POSITION_CARTESIAN){
|
||||
gl.enableVertexAttribArray(attributes.aVertexPosition);
|
||||
gl.vertexAttribPointer(attributes.aVertexPosition, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
offset += attribute.byteSize;
|
||||
}
|
||||
|
||||
gl.drawArrays(gl.POINTS, 0, pointCloud.size);
|
||||
|
||||
gl.disableVertexAttribArray(attributes.aNormal);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
WeightedPointSizeMaterial.prototype.renderPointCloudsPosition = function renderPointCloudsPosition(transform, pointClouds, renderer){
|
||||
var camera = renderer.camera;
|
||||
var lights = renderer.lights;
|
||||
|
||||
renderer.fboPosition.bind();
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.disable(gl.BLEND);
|
||||
|
||||
for(var i = 0; i < pointClouds.length; i++){
|
||||
var pointCloud = pointClouds[i];
|
||||
var pointAttributes = pointCloud.pointAttributes;
|
||||
gl.useProgram(this.posShader.program);
|
||||
|
||||
{ // uniforms
|
||||
gl.uniformMatrix4fv(this.posShader.uniforms.uWorld, false, transform);
|
||||
gl.uniformMatrix4fv(this.posShader.uniforms.uView, false, camera.viewMatrix);
|
||||
gl.uniformMatrix4fv(this.posShader.uniforms.uProj, false, camera.projectionMatrix);
|
||||
gl.uniform1f(this.posShader.uniforms.uPointSizeMultiplicator, this.pointSize);
|
||||
gl.uniform2f(this.posShader.uniforms.uViewportSize, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
}
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, pointCloud.vbo);
|
||||
var offset = 0;
|
||||
for(var j = 0; j < pointAttributes.size; j++){
|
||||
var attribute = pointAttributes.attributes[j];
|
||||
|
||||
if(attribute === PointAttribute.POSITION_CARTESIAN){
|
||||
gl.enableVertexAttribArray(this.posShader.attributes.aVertexPosition);
|
||||
gl.vertexAttribPointer(this.posShader.attributes.aVertexPosition, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
offset += attribute.byteSize;
|
||||
}
|
||||
|
||||
gl.drawArrays(gl.POINTS, 0, pointCloud.size);
|
||||
|
||||
gl.disableVertexAttribArray(this.posShader.attributes.aNormal);
|
||||
}
|
||||
};
|
||||
|
||||
WeightedPointSizeMaterial.prototype.renderPointClouds = function renderPointClouds(transform, pointClouds, renderer){
|
||||
var camera = renderer.camera;
|
||||
var lights = renderer.lights;
|
||||
|
||||
renderer.fboColor.bind();
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.disable(gl.BLEND);
|
||||
|
||||
for(var i = 0; i < pointClouds.length; i++){
|
||||
var pointCloud = pointClouds[i];
|
||||
var pointAttributes = pointCloud.pointAttributes;
|
||||
gl.useProgram(this.shader.program);
|
||||
|
||||
{ // uniforms
|
||||
gl.uniformMatrix4fv(this.shader.uniforms.uWorld, false, transform);
|
||||
gl.uniformMatrix4fv(this.shader.uniforms.uView, false, camera.viewMatrix);
|
||||
gl.uniformMatrix4fv(this.shader.uniforms.uProj, false, camera.projectionMatrix);
|
||||
gl.uniform1f(this.shader.uniforms.uPointSizeMultiplicator, this.pointSize);
|
||||
gl.uniform2f(this.shader.uniforms.uViewportSize, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
|
||||
}
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, pointCloud.vbo);
|
||||
var offset = 0;
|
||||
for(var j = 0; j < pointAttributes.size; j++){
|
||||
var attribute = pointAttributes.attributes[j];
|
||||
|
||||
if(attribute === PointAttribute.POSITION_CARTESIAN){
|
||||
gl.enableVertexAttribArray(this.shader.attributes.aVertexPosition);
|
||||
gl.vertexAttribPointer(this.shader.attributes.aVertexPosition, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}else if(attribute === PointAttribute.RGBA_PACKED){
|
||||
if(this.shader.attributes.aVertexColour !== null){
|
||||
gl.enableVertexAttribArray(this.shader.attributes.aVertexColour);
|
||||
gl.vertexAttribPointer(this.shader.attributes.aVertexColour, 3, gl.UNSIGNED_BYTE, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}else if(attribute === PointAttribute.RGB_PACKED){
|
||||
if(this.shader.attributes.aVertexColour !== null){
|
||||
gl.enableVertexAttribArray(this.shader.attributes.aVertexColour);
|
||||
gl.vertexAttribPointer(this.shader.attributes.aVertexColour, 3, gl.UNSIGNED_BYTE, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}else if(attribute === PointAttribute.NORMAL_FLOATS){
|
||||
if(this.shader.attributes.aNormal !== null){
|
||||
gl.enableVertexAttribArray(this.shader.attributes.aNormal);
|
||||
gl.vertexAttribPointer(this.shader.attributes.aNormal, 3, gl.FLOAT, false,pointAttributes.byteSize, offset);
|
||||
}
|
||||
}
|
||||
offset += attribute.byteSize;
|
||||
}
|
||||
|
||||
gl.drawArrays(gl.POINTS, 0, pointCloud.size);
|
||||
|
||||
gl.disableVertexAttribArray(this.shader.attributes.aVertexPosition);
|
||||
gl.disableVertexAttribArray(this.shader.attributes.aVertexColour);
|
||||
gl.disableVertexAttribArray(this.shader.attributes.aNormal);
|
||||
}
|
||||
};
|
||||
@ -1,47 +0,0 @@
|
||||
|
||||
/**
|
||||
*
|
||||
* @class CamHandlers define different types of navigation behaviour. This class is intended to be subclassed.
|
||||
*
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
function CamHandler(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
CamHandler.prototype.addTime = function(time){
|
||||
// override in subclass
|
||||
};
|
||||
|
||||
CamHandler.prototype.invokeKeyDown = function(event){
|
||||
// override in subclass
|
||||
};
|
||||
|
||||
CamHandler.prototype.invokeKeyUp = function(event){
|
||||
// override in subclass
|
||||
};
|
||||
|
||||
CamHandler.prototype.invokeKeyPress = function(event){
|
||||
// override in subclass
|
||||
};
|
||||
|
||||
CamHandler.prototype.invokeMouseDown = function(event){
|
||||
// override in subclass
|
||||
};
|
||||
|
||||
CamHandler.prototype.invokeMouseUp = function(event){
|
||||
// override in subclass
|
||||
};
|
||||
|
||||
CamHandler.prototype.invokeMouseMove = function(event, diffX, diffY){
|
||||
// override in subclass
|
||||
};
|
||||
|
||||
CamHandler.prototype.invokeMouseDrag = function(event, pressedKeys, diffX, diffY){
|
||||
// override in subclass
|
||||
};
|
||||
|
||||
CamHandler.prototype.invokeMouseWheel = function(delta){
|
||||
// override in subclass
|
||||
};
|
||||
@ -1,109 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param camera
|
||||
* @class Navgitation similar to google earth
|
||||
* @augments CamHandler
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
function EarthCamHandler(camera){
|
||||
this.camera = camera;
|
||||
this.velocity = [0,0,0];
|
||||
this.targetVelocity = [0,0,0];
|
||||
this.targetVelocityMultiplicator = 20.0;
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.speedMultiplier = 0.2;
|
||||
this.qualityToggle = 0;
|
||||
}
|
||||
|
||||
EarthCamHandler.prototype = new CamHandler();
|
||||
|
||||
EarthCamHandler.prototype.addTime = function(time){
|
||||
this.update(time);
|
||||
};
|
||||
|
||||
EarthCamHandler.prototype.update = function(time){
|
||||
this.velocity[0] = 0.2 *this.velocity[0] + 0.8 * this.targetVelocity[0] * this.targetVelocityMultiplicator;
|
||||
this.velocity[1] = 0.2 *this.velocity[1] + 0.8 * this.targetVelocity[1] * this.targetVelocityMultiplicator;
|
||||
this.velocity[2] = 0.2 *this.velocity[2] + 0.8 * this.targetVelocity[2] * this.targetVelocityMultiplicator;
|
||||
|
||||
var t = [this.velocity[0]* time, this.velocity[1]* time, this.velocity[2] * time];
|
||||
|
||||
this.camera.transform = M4x4.translate3(t[0], t[1], t[2], this.camera.transform);
|
||||
};
|
||||
|
||||
EarthCamHandler.prototype.invokeKeyDown = function(event){
|
||||
if(event.which === KeyCodes.DOWN_ARROW || event.which == KeyCodes.S ){
|
||||
this.targetVelocity[2] = 1 * this.speedMultiplier;
|
||||
}else if(event.which === KeyCodes.UP_ARROW || event.which == KeyCodes.W){
|
||||
this.targetVelocity[2] = -1 * this.speedMultiplier;
|
||||
}else if(event.which === KeyCodes.RIGHT_ARROW || event.which == KeyCodes.D){
|
||||
this.targetVelocity[0] = 1 * this.speedMultiplier;
|
||||
}else if(event.which === KeyCodes.LEFT_ARROW || event.which == KeyCodes.A){
|
||||
this.targetVelocity[0] = -1 * this.speedMultiplier;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
EarthCamHandler.prototype.invokeKeyUp = function(event){
|
||||
if(event.which === KeyCodes.DOWN_ARROW || event.which == KeyCodes.S){
|
||||
this.targetVelocity[2] = 0;
|
||||
}else if(event.which === KeyCodes.UP_ARROW || event.which == KeyCodes.W){
|
||||
this.targetVelocity[2] = 0;
|
||||
}else if(event.which === KeyCodes.RIGHT_ARROW || event.which == KeyCodes.D){
|
||||
this.targetVelocity[0] = 0;
|
||||
}else if(event.which === KeyCodes.LEFT_ARROW || event.which == KeyCodes.A){
|
||||
this.targetVelocity[0] = 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
EarthCamHandler.prototype.invokeKeyPress = function(event){
|
||||
|
||||
};
|
||||
|
||||
EarthCamHandler.prototype.invokeMouseDown = function(event){
|
||||
|
||||
};
|
||||
|
||||
EarthCamHandler.prototype.invokeMouseUp = function(event){
|
||||
};
|
||||
|
||||
EarthCamHandler.prototype.invokeMouseMove = function(event, diffX, diffY){
|
||||
|
||||
};
|
||||
|
||||
EarthCamHandler.prototype.invokeMouseDrag = function(event, pressedKeys, diffX, diffY){
|
||||
if(pressedKeys.length === 1 && pressedKeys.contains(0)){
|
||||
var pos = this.camera.localPosition;
|
||||
|
||||
var toOrigin = M4x4.translate3(-pos[0], -pos[1], -pos[2], M4x4.I);
|
||||
var rotY = M4x4.rotate(-diffX / 100.0, [0,1,0], M4x4.I);
|
||||
var rotX = M4x4.rotate(-diffY / 100.0, this.camera.getSideVector(), M4x4.I);
|
||||
var backToPos = M4x4.translate3(pos[0], pos[1], pos[2], M4x4.I);
|
||||
|
||||
var transform = M4x4.mul(toOrigin, this.camera.transform);
|
||||
transform = M4x4.mul(rotX, transform);
|
||||
transform = M4x4.mul(backToPos, transform);
|
||||
this.camera.transform = transform;
|
||||
|
||||
|
||||
transform = M4x4.mul(toOrigin, this.camera.transform);
|
||||
transform = M4x4.mul(rotY, transform);
|
||||
transform = M4x4.mul(backToPos, transform);
|
||||
this.camera.transform = transform;
|
||||
this.qualityToggle = 0.1;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
EarthCamHandler.prototype.invokeMouseWheel = function(delta){
|
||||
var amount = delta / 2000.0;
|
||||
this.speedMultiplier += amount;
|
||||
this.speedMultiplier = Math.max(0.01, Math.min(10.0, this.speedMultiplier));
|
||||
};
|
||||
|
||||
@ -1,134 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param camera
|
||||
* @class fly like a bird
|
||||
* @augments CamHandler
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
function FreeFlightCamHandler(camera){
|
||||
this.camera = camera;
|
||||
this.velocity = [0,0,0];
|
||||
this.targetVelocity = [0,0,0];
|
||||
this.targetVelocityMultiplicator = 20.0;
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.speedMultiplier = 0.2;
|
||||
this.qualityToggle = 0;
|
||||
}
|
||||
|
||||
FreeFlightCamHandler.prototype = new CamHandler();
|
||||
|
||||
FreeFlightCamHandler.prototype.addTime = function(time){
|
||||
this.update(time);
|
||||
};
|
||||
|
||||
FreeFlightCamHandler.prototype.update = function(time){
|
||||
this.velocity[0] = 0.2 *this.velocity[0] + 0.8 * this.targetVelocity[0] * this.targetVelocityMultiplicator;
|
||||
this.velocity[1] = 0.2 *this.velocity[1] + 0.8 * this.targetVelocity[1] * this.targetVelocityMultiplicator;
|
||||
this.velocity[2] = 0.2 *this.velocity[2] + 0.8 * this.targetVelocity[2] * this.targetVelocityMultiplicator;
|
||||
|
||||
var t = [this.velocity[0]* time, this.velocity[1]* time, this.velocity[2] * time];
|
||||
|
||||
// this.camera.translate(t[0], t[1], t[2]);
|
||||
this.camera.transform = M4x4.translate3(t[0], t[1], t[2], this.camera.transform);
|
||||
|
||||
//Potree.isLowQualityMode = this.qualityToggle > 0 || V3.length(this.velocity) > 0.1;
|
||||
if(this.qualityToggle > 0){
|
||||
this.qualityToggle -= time;
|
||||
}
|
||||
};
|
||||
|
||||
FreeFlightCamHandler.prototype.invokeKeyDown = function(event){
|
||||
if(event.which === 83 ){
|
||||
//s
|
||||
this.targetVelocity[2] = 1 * this.speedMultiplier;
|
||||
}else if(event.which === 87 ){
|
||||
//w
|
||||
this.targetVelocity[2] = -1 * this.speedMultiplier;
|
||||
}else if(event.which === 68 ){
|
||||
//d
|
||||
this.targetVelocity[0] = 1 * this.speedMultiplier;
|
||||
}else if(event.which === 65 ){
|
||||
//a
|
||||
this.targetVelocity[0] = -1 * this.speedMultiplier;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
FreeFlightCamHandler.prototype.invokeKeyUp = function(event){
|
||||
if(event.which === 83 ){
|
||||
//s
|
||||
this.targetVelocity[2] = 0;
|
||||
}else if(event.which === 87 ){
|
||||
//w
|
||||
this.targetVelocity[2] = 0;
|
||||
}else if(event.which === 68 ){
|
||||
//d
|
||||
this.targetVelocity[0] = 0;
|
||||
}else if(event.which === 65 ){
|
||||
//a
|
||||
this.targetVelocity[0] = 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
FreeFlightCamHandler.prototype.invokeKeyPress = function(event){
|
||||
|
||||
};
|
||||
|
||||
FreeFlightCamHandler.prototype.invokeMouseDown = function(event){
|
||||
|
||||
};
|
||||
|
||||
FreeFlightCamHandler.prototype.invokeMouseUp = function(event){
|
||||
};
|
||||
|
||||
FreeFlightCamHandler.prototype.invokeMouseMove = function(event, diffX, diffY){
|
||||
|
||||
};
|
||||
|
||||
FreeFlightCamHandler.prototype.invokeMouseDrag = function(event, pressedKeys, diffX, diffY){
|
||||
|
||||
if(pressedKeys.length === 1 && pressedKeys.contains(0) && KeyListener.pressedKeys.contains(18)){
|
||||
// this.camera.translate((this.speedMultiplier * -diffX) / 10.0, (this.speedMultiplier * diffY) / 10.0, 0);
|
||||
this.camera.transform = M4x4.translate3((this.speedMultiplier * -diffX) / 10.0, (this.speedMultiplier * diffY) / 10.0, 0, this.camera.transform);
|
||||
this.qualityToggle = 0.1;
|
||||
}else if(pressedKeys.length === 1 && pressedKeys.contains(0)){
|
||||
var pos = this.camera.localPosition;
|
||||
|
||||
var toOrigin = M4x4.translate3(-pos[0], -pos[1], -pos[2], M4x4.I);
|
||||
var rotY = M4x4.rotate(-diffX / 100.0, [0,1,0], M4x4.I);
|
||||
var rotX = M4x4.rotate(-diffY / 100.0, this.camera.getSideVector(), M4x4.I);
|
||||
var backToPos = M4x4.translate3(pos[0], pos[1], pos[2], M4x4.I);
|
||||
|
||||
var transform = M4x4.mul(toOrigin, this.camera.transform);
|
||||
transform = M4x4.mul(rotX, transform);
|
||||
transform = M4x4.mul(backToPos, transform);
|
||||
//this.camera.setTransform(transform);
|
||||
this.camera.transform = transform;
|
||||
|
||||
|
||||
transform = M4x4.mul(toOrigin, this.camera.transform);
|
||||
transform = M4x4.mul(rotY, transform);
|
||||
transform = M4x4.mul(backToPos, transform);
|
||||
this.camera.transform = transform;
|
||||
this.qualityToggle = 0.1;
|
||||
|
||||
// this.camera.transform = M4x4.translate3(t[0], t[1], t[2], this.camera.transform);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
FreeFlightCamHandler.prototype.invokeMouseWheel = function(delta){
|
||||
// var amount = -delta / 100.0;
|
||||
// this.camera.translate(0,0,amount);
|
||||
|
||||
var amount = delta / 2000.0;
|
||||
this.speedMultiplier += amount;
|
||||
this.speedMultiplier = Math.max(0.01, Math.min(10.0, this.speedMultiplier));
|
||||
};
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
|
||||
/**
|
||||
*
|
||||
* @param camera
|
||||
* @augments CamHandler
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
function OrbitCamHandler(camera){
|
||||
this.camera = camera;
|
||||
this.rotateSpeed = 0.2;
|
||||
this.zoomSpeed = 0.2;
|
||||
this.pivot = V3.$(0,0,0);
|
||||
}
|
||||
|
||||
OrbitCamHandler.prototype = new CamHandler();
|
||||
|
||||
OrbitCamHandler.prototype.update = function(time){};
|
||||
|
||||
OrbitCamHandler.prototype.invokeMouseDrag = function(event, pressedKeys, diffX, diffY){
|
||||
// rotate around pivot point
|
||||
var amount = -this.rotateSpeed*timeSinceLastFrame;
|
||||
this.camera.rotateAroundPivot(amount*diffX, amount*diffY, this.pivot);
|
||||
};
|
||||
|
||||
OrbitCamHandler.prototype.invokeMouseWheel = function(delta){
|
||||
// zoom in/out
|
||||
var dir = this.camera.getGlobalDirection();
|
||||
var v = V3.scale(dir, delta*timeSinceLastFrame*this.zoomSpeed);
|
||||
this.camera.transform = M4x4.mul(M4x4.makeTranslate3(v.x, v.y, v.z), this.camera.transform);
|
||||
};
|
||||
@ -1,141 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
* @class
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
MeshType = {
|
||||
TRIANGLES : 0,
|
||||
LINES: 1,
|
||||
POINTS: 2
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @class
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
function Mesh(name){
|
||||
this.name = name;
|
||||
this.subMeshes = new Array();
|
||||
this.setType(MeshType.TRIANGLES);
|
||||
this._material = null;
|
||||
|
||||
// depending on MeshType, this can be either lineWidth or pointSize
|
||||
this.primitiveSize = 1.0;
|
||||
}
|
||||
|
||||
Mesh.prototype.setType = function(type){
|
||||
this.type = type;
|
||||
if(type === MeshType.TRIANGLES){
|
||||
this.glType = gl.TRIANGLES;
|
||||
}else if(type === MeshType.LINES){
|
||||
this.glType = gl.LINES;
|
||||
}else if(type === MeshType.POINTS){
|
||||
this.glType = gl.POINTS;
|
||||
}else{
|
||||
throw "unknown mesh type: " + type + ". use one of the MeshType members.";
|
||||
}
|
||||
};
|
||||
|
||||
Mesh.prototype.render = function(meshNode, renderer){
|
||||
for(var i = 0; i < this.subMeshes.length; i++){
|
||||
var subMesh = this.subMeshes[i];
|
||||
subMesh.render(meshNode, renderer);
|
||||
}
|
||||
};
|
||||
|
||||
Mesh.prototype.addSubMesh = function(subMesh){
|
||||
this.subMeshes.push(subMesh);
|
||||
};
|
||||
|
||||
Mesh.prototype.setMaterial = function(material){
|
||||
this.material = material;
|
||||
};
|
||||
|
||||
Object.defineProperty(Mesh.prototype, "material", {
|
||||
get: function(){
|
||||
return this._material;
|
||||
},
|
||||
set: function(material){
|
||||
this._material = material;
|
||||
for(var i = 0; i < this.subMeshes.length; i++){
|
||||
var subMesh = this.subMeshes[i];
|
||||
subMesh.material = material;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mesh
|
||||
* @class
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
function SubMesh(mesh){
|
||||
this.mesh = mesh;
|
||||
// beinhaltet alle vertex buffer des meshes
|
||||
this.vbos = new Object();
|
||||
// index buffer
|
||||
this.ibo = null;
|
||||
this.vertexCount = 0;
|
||||
// this.material = null;
|
||||
this.indices = null;
|
||||
this._material = null;
|
||||
}
|
||||
|
||||
SubMesh.prototype.setMaterial = function(material){
|
||||
this.material = material;
|
||||
};
|
||||
|
||||
Object.defineProperty(SubMesh.prototype, "material", {
|
||||
get: function(){
|
||||
return this._material;
|
||||
},
|
||||
set: function(material){
|
||||
this._material = material;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
SubMesh.prototype.setVertexBufferData = function(name, data){
|
||||
// wenn vertex buffer noch nicht vorhanden -> neuen erstellen
|
||||
if(this.vbos[name] == null){
|
||||
this.vbos[name] = gl.createBuffer();
|
||||
}
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.vbos[name]);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
|
||||
};
|
||||
|
||||
SubMesh.prototype.setIndexBufferData = function(data){
|
||||
if(this.ibo == null){
|
||||
this.ibo = gl.createBuffer();
|
||||
}
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.ibo);
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, data, gl.STATIC_DRAW);
|
||||
this.indices = data;
|
||||
};
|
||||
|
||||
SubMesh.prototype.render = function(meshNode, renderer){
|
||||
this.material.renderSubMesh(this, meshNode, renderer);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||