Permalink
Browse files

more work

  • Loading branch information...
jeromeetienne committed Mar 6, 2013
1 parent fd90dc7 commit 732379aa59cd3a3c6921b606455d37d538afed5d
@@ -37644,7 +37644,6 @@ tQuery.convert = {};
* @return {THREE.Color} the resulting color
*/
tQuery.convert.toThreeColor = function(/* arguments */){
-console.log('ddd', arguments)
// honor the plugins with 'preConvert' event
var result = tQuery.convert.toThreeColor.dispatchEvent('preConvert', arguments);
if( result !== undefined ) return result;
@@ -40860,11 +40859,16 @@ requirejs.config({
}
});
(function(){
+ // get the script dom element which included the library
var scripts = document.getElementsByTagName('script');
- var element = scripts[scripts.length-1];
- var baseUrl = element.getAttribute('data-baseURL');
- console.log('baseUrl', baseUrl, element);
- if( baseUrl === null ) return;
+ var scriptEl = scripts[scripts.length-1];
+ var src = scriptEl.src;
+ var suffix = '/build/tquery-bundle-require.js';
+ // if the element src DOES NOT endup with suffix, do nothing
+ if(src.indexOf(suffix, src.length - suffix.length) !== -1) return;
+ // get the baseURL
+ var baseURL = src.substr(0, src.length - suffix.length)
+ // configure require.js using this baseUrl
requirejs.config({
paths : {
"build" : baseUrl+'/build',
@@ -40873,4 +40877,4 @@ requirejs.config({
"three.js" : baseUrl+'/vendor/three.js',
},
});
-})()
+})();
View
@@ -37644,7 +37644,6 @@ tQuery.convert = {};
* @return {THREE.Color} the resulting color
*/
tQuery.convert.toThreeColor = function(/* arguments */){
-console.log('ddd', arguments)
// honor the plugins with 'preConvert' event
var result = tQuery.convert.toThreeColor.dispatchEvent('preConvert', arguments);
if( result !== undefined ) return result;
View
@@ -418,7 +418,6 @@ tQuery.convert = {};
* @return {THREE.Color} the resulting color
*/
tQuery.convert.toThreeColor = function(/* arguments */){
-console.log('ddd', arguments)
// honor the plugins with 'preConvert' event
var result = tQuery.convert.toThreeColor.dispatchEvent('preConvert', arguments);
if( result !== undefined ) return result;
View
@@ -6,7 +6,6 @@ tQuery.convert = {};
* @return {THREE.Color} the resulting color
*/
tQuery.convert.toThreeColor = function(/* arguments */){
-console.log('ddd', arguments)
// honor the plugins with 'preConvert' event
var result = tQuery.convert.toThreeColor.dispatchEvent('preConvert', arguments);
if( result !== undefined ) return result;
@@ -37,7 +37,7 @@
* - aka i init a load of a given asset while it is already loading
*/
- var cache = new MicroCache();
+ var cache = new tQuery.MicroCache();
world.enableWebAudio();
tQuery.Flow()
@@ -10,5 +10,5 @@
envMap : tQuery.createCubeTexture('skybox')
});
- var object = tQuery.createSphere(material).addTo(world).scaleBy(3);
+ var object = tQuery.createSphere().addTo(world).scaleBy(3)
</script></body>
@@ -1,7 +1,10 @@
-s<!doctype html><title>Minimal tQuery Page</title>
+<!doctype html><title>Minimal tQuery Page</title>
<script src="../../../build/tquery-bundle-require.js"></script>
<body><script>
-require(['tquery.skymap', 'tquery.grassground', 'tquery.minecraft'], function(){
+require([ 'tquery.skymap'
+ , 'tquery.grassground'
+ , 'tquery.minecraft'
+], function(){
var world = tQuery.createWorld().boilerplate().start();
tQuery.createSkymap('mars').addTo(world);
@@ -8,7 +8,8 @@ tQuery.registerStatic('createVideoTexture', function(opts){
}
// TODO handle webrtc stream
opts = tQuery.extend(opts, {
- loop : tQuery.world.loop()
+ world : tQuery.world
+
// TODO at the world level
});
console.assert( opts.url, "url MUST be specified" )
@@ -25,7 +26,7 @@ tQuery.registerStatic('createVideoTexture', function(opts){
var texture = new THREE.Texture( video );
// how do i stop that ?
- opts.loop.hook(function(){
+ var callback = opts.world.loop().hook(function(){
if( video.readyState === video.HAVE_ENOUGH_DATA ){
texture.needsUpdate = true;
}
@@ -8,7 +8,8 @@
world.removeCameraControls();
var joystick = new VirtualJoystick({
- container : document.body,
+ //container : document.body,
+ container : world.tRenderer().domElement,
mouseSupport : true
});
@@ -4,22 +4,12 @@
<body><script>
require(['tquery.videos'], function(){
var world = tQuery.createWorld().boilerplate().start();
-
- tQuery.convert.toTexture.addEventListener('preConvert', function(value){
-return;
-console.log('blabalbal', value)
- if( value instanceof LocalMediaStream === false ){
- return undefined;
- }
- // TODO use videotexture plugin instead
- return createTexture(value)
- });
rtc.createStream({"video": true, "audio": true}, function(stream){
-console.log('blabalbal', stream)
+console.dir(stream)
var url = URL.createObjectURL(stream);
var texture = tQuery.createVideoTexture(url);
- tQuery.createPlane().addTo(world)
+ var player = tQuery.createCube().addTo(world)
.setBasicMaterial()
.map(texture)
.back()
@@ -1,56 +1,37 @@
<!doctype html><title>Minimal tQuery Page</title>
<script src="../../../build/tquery-bundle-require.js"></script>
<script src='../vendor/webrtc.io-client/webrtc.io.js'></script>
-<body>
-<script>
-require([], function(){
+<script src='../tquery.webrtc.js'></script>
+<body><script>
+require(['tquery.videos'], function(){
var world = tQuery.createWorld().boilerplate().start();
-
- rtc.createStream({"video": true, "audio": true}, function(stream){
-console.dir(stream)
- var texture = createTexture(stream)
+ rtc.createStream({'video': true, 'audio': false}, function(mediaStream){
tQuery.createPlane().addTo(world)
- .positionX(2 * Math.random()-0.5)
- .positionY(2 * Math.random()-0.5)
.setBasicMaterial()
- .map(texture)
+ .map(mediaStream)
.back()
}, function(){
console.log('createStream failed', arguments)
});
var room = 'public';
- var serverUrl = "ws://localhost:8000/";
+ var serverUrl = "ws://localhost:8080/";
rtc.connect(serverUrl, room);
-
- rtc.on('add remote stream', function(stream, socketId) {
- var texture = createTexture(stream)
+ rtc.on('add remote stream', function(mediaStream, socketId) {
tQuery.createPlane().addTo(world)
+ .addClass('socketId-'+socketId)
.positionX(2 * Math.random()-0.5)
.positionY(2 * Math.random()-0.5)
.setBasicMaterial()
- .map(texture)
+ .map(mediaStream)
.back()
});
-
- function createTexture(stream){
- var videoEl = document.createElement('video');
- videoEl.width = 320;
- videoEl.height = 240;
- videoEl.autoplay= true;
- videoEl.loop = true;
- videoEl.src = URL.createObjectURL(stream);
-
- var texture = new THREE.Texture( videoEl );
-
- world.loop().hook(function(){
- if( videoEl.readyState === videoEl.HAVE_ENOUGH_DATA ){
- texture.needsUpdate = true;
- }
- });
- return texture;
- }
+ rtc.on('disconnect stream', function(socketId) {
+ var nRemote = tQuery('.socketId-'+socketId).length;
+ console.log('remove',socketId,'currently', nRemote);
+ tQuery('.socketId-'+socketId).detach();
+ });
});
</script></body>
@@ -0,0 +1,28 @@
+<!doctype html><title>Minimal tQuery Page</title>
+<script src="../../../build/tquery-bundle-require.js"></script>
+<script src='../vendor/webrtc.io-client/webrtc.io.js'></script>
+<script src='../tquery.webrtc.js'></script>
+<body><script>
+require(['tquery.videos'], function(){
+ var world = tQuery.createWorld().boilerplate().start();
+
+ var room = 'public';
+ var serverUrl = "ws://localhost:8080/";
+ rtc.connect(serverUrl, room);
+ rtc.on('add remote stream', function(mediaStream, socketId) {
+ console.log('add socketId', socketId)
+ tQuery.createPlane().addTo(world)
+ .addClass('socketId-'+socketId)
+ .positionX(2 * Math.random()-0.5)
+ .positionY(2 * Math.random()-0.5)
+ .setBasicMaterial()
+ .map(mediaStream)
+ .back()
+ });
+ rtc.on('disconnect stream', function(socketId) {
+ var nRemote = tQuery('.socketId-'+socketId).length;
+ console.log('remove',socketId,'currently', nRemote);
+ tQuery('.socketId-'+socketId).detach();
+ });
+});
+</script></body>
@@ -0,0 +1,19 @@
+/**
+ * hook tQuery.convert.toTexture() to accept MediaStream
+ */
+tQuery.convert.toTexture.addEventListener('preConvert', function(args){
+ // if first args IS NOT a LocalMediaStream, return now
+ //if( args[0] instanceof LocalMediaStream === false ) return undefined;
+
+ // FIXME window.LocalMediaStream is not defined... so impossible to do instanceof
+ // - working around by testing properties which MUST exist in a MediaLocalStream
+ // - aka a poor version of it
+ if( args[0].audioTracks === undefined ) return;
+ if( args[0].videoTracks === undefined ) return;
+ if( args[0].readyState === undefined ) return;
+ // now convert the stream in a texture using tquery.videos plugin
+ var stream = args[0];
+ var url = URL.createObjectURL(stream);
+ var texture = tQuery.createVideoTexture(url);
+ return texture;
+});
View
@@ -0,0 +1,91 @@
+<!doctype html><title>Minimal tQuery Page</title>
+<script src="../../../build/tquery-bundle-require.js"></script>
+<body><script>
+require([ 'tquery.skymap'
+ , 'tquery.grassground'
+ , 'tquery.minecraft'
+], function(){
+ var world = tQuery.createWorld().boilerplate().start();
+
+ tQuery.createSkymap('mars').addTo(world);
+
+ // tQuery.createGrassGround({
+ // textureRepeatX : 10,
+ // textureRepeatY : 10,
+ // }).addTo(world).scale(30)
+ // .translateY(-0.001)
+
+ var cubeCamera = new THREE.CubeCamera( 0.001, 1000, 1024 );
+ // to avoid flickering on the border of the sphere
+ cubeCamera.renderTarget.minFilter = THREE.LinearMipMapLinearFilter;
+
+ var sphere = tQuery.createSphere().addTo(world)
+ .setBasicMaterial()
+ .envMap(cubeCamera.renderTarget)
+ .color(0xffff00)
+ .back()
+
+ // world.loop().hook(function(delta, now){
+ // sphere.rotateY( 0.1 * delta * Math.PI*2)
+ // })
+
+
+
+
+ tQuery(cubeCamera).addTo(sphere)
+
+ world.loop().hook(function(){
+ sphere.visible(false) // *cough*
+
+ cubeCamera.updateCubeMap( world.tRenderer(), world.tScene() );
+
+ sphere.visible(true) // *cough*
+ })
+
+
+ var container = tQuery.createObject3D().addTo(world)
+ .positionY(-0.5)
+ tQuery.createTorusKnot().addTo(container).position( 0, 0, 1)
+ tQuery.createTorusKnot().addTo(container).position( 0, 0,-1)
+ tQuery.createTorusKnot().addTo(container).position( 1, 0, 0).rotateY( Math.PI/2)
+ tQuery.createTorusKnot().addTo(container).position(-1, 0, 0).rotateY(-Math.PI/2)
+
+ world.loop().hook(function(delta, now){
+ container.rotateY( 0.3 * delta * Math.PI*2)
+ })
+
+
+ var textureW = 512;
+ var textureH = 512;
+ var rtTexture = new THREE.WebGLRenderTarget(textureW, textureH, {
+ minFilter : THREE.LinearFilter,
+ magFilter : THREE.NearestFilter,
+ format : THREE.RGBFormat
+ });
+
+ var tCamera = new THREE.PerspectiveCamera(35, textureW/textureH, 0.01, 10000);
+
+
+ world.loop().hook(function(delta, now){
+ var tRenderer = world.tRenderer();
+ tRenderer.render( world.tScene(), tCamera, rtTexture, true );
+ })
+
+
+ var mirror = tQuery.createPlane().addTo(world)
+ .geometry()
+ .scaleBy(2)
+ .back()
+ .translateX(-1.5)
+ .translateZ(-1.5)
+ .rotateY(Math.PI/4)
+ .setBasicMaterial()
+ .map(rtTexture)
+ .back()
+
+ tQuery(tCamera).addTo(mirror)
+ .rotateY(Math.PI)
+ tQuery.createAxis().addTo(tCamera)
+ window.tCamera = tCamera;
+})
+</script></body>

0 comments on commit 732379a

Please sign in to comment.