-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #282 from Tour-360/video
Добавил возможность отображать видео в ВТ
- Loading branch information
Showing
15 changed files
with
363 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* globals Tools */ | ||
|
||
Tools.meshEditor = function(id, lat) { | ||
this.selectedMesh = false; | ||
this.durationCrop = 0; | ||
|
||
function onMouseMove( event ) { | ||
var mouse = new THREE.Vector2(); | ||
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1; | ||
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1; | ||
var raycaster = new THREE.Raycaster(); | ||
raycaster.setFromCamera( mouse, Tour.camera ); | ||
var intersects = raycaster.intersectObjects( Tour.meshs ); | ||
|
||
Tour.meshs.forEach(function (n) { | ||
n.material.color && n.material.color.set( 0xffffff ); | ||
n.material.opacity = 1; | ||
}) | ||
|
||
Tools.selectedMesh = false; | ||
|
||
for ( var i = 0; i < intersects.length; i++ ) { | ||
if(intersects[ i ].object.material.color){ | ||
intersects[ i ].object.material.color.set( 0xff0000 ); | ||
intersects[ i ].object.material.opacity = 0.6; | ||
Tools.selectedMesh = intersects[ i ].object; | ||
} | ||
} | ||
} | ||
|
||
window.addEventListener('keydown', function(event) { | ||
var alpha = 0.1 | ||
console.log(event) | ||
if(event.altKey) alpha/=10; | ||
if(event.ctrlKey) alpha/=10; | ||
if(event.shiftKey) alpha*=10; | ||
|
||
var sm = Tools.selectedMesh; | ||
|
||
if(sm){ | ||
console.log(event.keyCode); | ||
if(event.keyCode == 74){ //J | ||
sm.position.z -= 1*alpha; | ||
}else if(event.keyCode == 76){ //L | ||
sm.position.z += 1*alpha; | ||
}else if(event.keyCode == 73){ //K | ||
sm.position.x += 1*alpha; | ||
}else if(event.keyCode == 75){ //K | ||
sm.position.x -= 1*alpha; | ||
}else if(event.keyCode == 85){ //K | ||
sm.position.y += 1*alpha; | ||
}else if(event.keyCode == 79){ //K | ||
sm.position.y -= 1*alpha; | ||
}else if(event.keyCode == 219){ //{ | ||
sm.rotation.y += Math.PI/2*alpha; | ||
}else if(event.keyCode == 221){ // } | ||
sm.rotation.y -= Math.PI/2*alpha; | ||
}else if(event.keyCode == 57){ // ( | ||
sm.rotation.z += Math.PI/2*alpha; | ||
}else if(event.keyCode == 48){ // ) | ||
sm.rotation.z -= Math.PI/2*alpha; | ||
}else if(event.keyCode == 188){ // ( | ||
sm.rotation.x += Math.PI/2*alpha; | ||
}else if(event.keyCode == 190){ // ) | ||
sm.rotation.x -= Math.PI/2*alpha; | ||
}else if(event.keyCode == 84){ // ( | ||
sm.scale.x += 1*alpha; | ||
}else if(event.keyCode == 89){ // ) | ||
sm.scale.x -= 1*alpha | ||
}else if(event.keyCode == 71){ // ( | ||
sm.scale.y += 1*alpha; | ||
}else if(event.keyCode == 72){ // ) | ||
sm.scale.y -= 1*alpha | ||
}else if(event.keyCode == 86){ // v | ||
Tools.durationCrop = ++Tools.durationCrop%4; | ||
UI.notification.show('Set duration crop '+['top', 'right', 'bottom', 'left'][Tools.durationCrop]) | ||
}else if(event.keyCode == 66){ // b | ||
if(Tools.durationCrop == 0){ | ||
sm.material.map.repeat.y /= 1.1; | ||
sm.material.map.offset.y /= 1.1; | ||
Tools.selectedVideo.scale.y /= 1.1; | ||
}else if(Tools.durationCrop == 1){ | ||
sm.material.map.repeat.x /= 1.1; | ||
sm.material.map.offset.x /= 1.1; | ||
sm.scale.x /= 1.1; | ||
}else if(Tools.durationCrop == 2){ | ||
sm.material.map.repeat.y -= 0.1; | ||
sm.scale.y = sm.material.map.repeat.y; | ||
}else if(Tools.durationCrop == 3){ | ||
sm.material.map.repeat.x -= 0.1; | ||
sm.scale.x = sm.material.map.repeat.x; | ||
} | ||
|
||
}else if(event.keyCode == 78){ // n | ||
if(Tools.durationCrop == 0){ | ||
sm.material.map.repeat.y *= 1.1; | ||
sm.material.map.offset.y *= 1.1; | ||
sm.scale.y *= 1.1; | ||
}else if(Tools.durationCrop == 1){ | ||
sm.material.map.repeat.x *= 1.1; | ||
sm.material.map.offset.x *= 1.1; | ||
sm.scale.x *= 1.1; | ||
}else if(Tools.durationCrop == 2){ | ||
sm.material.map.repeat.y += 0.1; | ||
sm.scale.y = sm.material.map.repeat.y; | ||
}else if(Tools.durationCrop == 3){ | ||
sm.material.map.repeat.x += 0.1; | ||
sm.scale.x = sm.material.map.repeat.x; | ||
} | ||
} | ||
|
||
|
||
|
||
var fix = function(n){ | ||
return parseFloat(parseFloat(n).toFixed(4)); | ||
} | ||
|
||
if(event.code == 'Digit8' && Tools.selectedMesh){ | ||
var mesh = {} | ||
var sm = Tools.selectedMesh; | ||
mesh.position = {x: fix(sm.position.x), y: fix(sm.position.y), z: fix(sm.position.z)} | ||
mesh.rotation = {x: fix(sm.rotation.x), y: fix(sm.rotation.y), z: fix(sm.rotation.z)} | ||
if(sm._videoId){ | ||
var alpha = Tour.videos[sm._videoId].canvas.height / Tour.videos[sm._videoId].canvas.width; | ||
mesh.scale = { | ||
x: fix(sm.scale.x / Tour.videos[sm._videoId].texture.repeat.x), | ||
y: fix(sm.scale.y / Tour.videos[sm._videoId].texture.repeat.y) / alpha, | ||
z: fix(sm.scale.z) | ||
} | ||
mesh.videoId = sm._videoId; | ||
}else{ | ||
var alpha = Tour.images[sm._imageId].height / Tour.images[sm._imageId].width; | ||
mesh.scale = { | ||
x: fix(sm.scale.x), | ||
y: fix(sm.scale.y / alpha), | ||
z: fix(sm.scale.z) | ||
} | ||
mesh.imageId = sm._imageId; | ||
} | ||
|
||
Tour.controls.copyText(JSON.stringify(mesh)) | ||
} | ||
} | ||
}); | ||
|
||
|
||
document.body.addEventListener('click', onMouseMove, false ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* globals Tour, THREE*/ | ||
|
||
Tour.Image = function(options) { | ||
this.loader = new THREE.TextureLoader(); | ||
this.material = new THREE.MeshBasicMaterial({ | ||
map: this.loader.load(options.src), | ||
transparent: true, | ||
// overdraw: 0.5, | ||
// needsUpdate: true, | ||
depthWrite: false | ||
}); | ||
|
||
this.width = options.width; | ||
this.height = options.height; | ||
|
||
}; | ||
//https://stackoverflow.com/questions/15994944/transparent-objects-in-threejs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* globals Tour, THREE*/ | ||
|
||
Tour.Video = function (options) { | ||
this.videoElement = document.createElement('video'); | ||
this.videoElement.src = options.src; | ||
// this.videoElement.autoplay = options.autoplay || true; | ||
this.videoElement.loop = options.loop || true; | ||
this.videoElement.muted = options.muted || true; | ||
|
||
var that = this | ||
var sync = function(){ | ||
if(that.videoElement.duration && that.needsUpdate){ | ||
that.videoElement.currentTime = (Date.now()/1000)%that.videoElement.duration; | ||
} | ||
} | ||
|
||
if(options.sync){ | ||
clearTimeout(this.syncTimeout) | ||
Tour.on('changeView', function(){ | ||
that.syncTimeout = setTimeout(sync, 2000); | ||
}) | ||
this.syncInterval = setInterval(sync, 10000); | ||
} | ||
|
||
// if(options.autoplay){ | ||
// this.videoElement.play(); | ||
// } | ||
this.videoElement.pause(); | ||
|
||
this.canvas = document.createElement('canvas'); | ||
this.canvas.width = Math.pow(2 ,Math.ceil(Math.log(options.width) / Math.log(2))); | ||
this.canvas.height = Math.pow(2 ,Math.ceil(Math.log(options.height) / Math.log(2))); | ||
|
||
this.ctx = this.canvas.getContext( '2d' ); | ||
|
||
this.texture = new THREE.Texture( this.canvas ); | ||
this.texture.repeat.x = options.width/this.canvas.width; | ||
this.texture.repeat.y = options.height/this.canvas.height; | ||
this.texture.offset.y = 1 - this.texture.repeat.y; | ||
this.texture.needsUpdate = true; | ||
this.needsUpdate = false; | ||
|
||
this.material = new THREE.MeshBasicMaterial( { map: this.texture, overdraw: 0,transparent: true} ); | ||
}; | ||
|
||
Tour.Video.prototype.draw = function(){ | ||
if(this.needsUpdate){ | ||
this.videoElement.play(); | ||
this.ctx.drawImage(this.videoElement, 0, 0); | ||
this.texture.needsUpdate = true; | ||
Tour.needsUpdate = true; | ||
}else{ | ||
this.videoElement.pause(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.