-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c32ed42
Showing
14 changed files
with
261 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["es2015", "react"] | ||
} |
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,4 @@ | ||
.idea | ||
*.log | ||
node_modules | ||
build |
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,2 @@ | ||
examples | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Richard Anaya | ||
|
||
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. |
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,8 @@ | ||
#aframe-html | ||
|
||
This is a component for easily adding HTML as a material to your 3d objects in aframe VR. | ||
|
||
Features | ||
* Load content from a url (note: you'll be restricted by what urls you use unless you use CORS or proxy) | ||
* Modify content directly | ||
* Simulate mouse events ("mousedown","mouseup","mousemove","click") |
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,5 @@ | ||
require("aframe") | ||
require("aframe-canvas") | ||
require("./index.js") | ||
window.React = require("react") | ||
window.ReactDOM = require("react-dom") |
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,11 @@ | ||
<html> | ||
<head> | ||
<script src="../../build/bundle.js"></script> | ||
</head> | ||
<body> | ||
<a-scene> | ||
<a-sky color="#999999"></a-sky> | ||
<a-plane position="0 1.25 -1" scale="3 3 3" html-material="url:test.html;width:200;height:200"/> | ||
</a-scene> | ||
</body> | ||
</html> |
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,5 @@ | ||
<html> | ||
<body> | ||
<h1>This is a <b>test</b></h1> | ||
</body> | ||
</html> |
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,16 @@ | ||
<html> | ||
<head> | ||
<script src="../../build/bundle.js"></script> | ||
</head> | ||
<body> | ||
<a-scene> | ||
<a-sky color="#999999"></a-sky> | ||
<a-plane id="screen" position="0 1.25 -1" scale="3 3 3" html-material="width:200;height:200"/> | ||
</a-scene> | ||
</body> | ||
<script> | ||
var component = document.querySelector("#screen").components["html-material"]; | ||
component.getDocument().body.innerHTML = "Hello World!" | ||
component.updateTexture(); | ||
</script> | ||
</html> |
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,19 @@ | ||
<html> | ||
<head> | ||
<script src="../../build/bundle.js"></script> | ||
</head> | ||
<body> | ||
<a-scene> | ||
<a-sky color="#999999"></a-sky> | ||
<a-plane id="screen" position="0 1.25 -1" scale="3 3 3" html-material="width:200;height:200"/> | ||
</a-scene> | ||
</body> | ||
<script> | ||
var component = document.querySelector("#screen").components["html-material"]; | ||
ReactDOM.render( | ||
React.createElement("div",null,"Hello React!"), | ||
component.getDocument().body | ||
); | ||
component.updateTexture(); | ||
</script> | ||
</html> |
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,34 @@ | ||
<html> | ||
<head> | ||
<script src="../../build/bundle.js"></script> | ||
</head> | ||
<body> | ||
<a-scene> | ||
<a-sky color="#999999"></a-sky> | ||
<a-plane id="screen" position="0 1.25 -1" scale="3 3 3" html-material="width:200;height:200"/> | ||
</a-scene> | ||
</body> | ||
<script> | ||
var component = document.querySelector("#screen").components["html-material"]; | ||
|
||
var clicked = false; | ||
|
||
var render = function(){ | ||
ReactDOM.render( | ||
React.createElement("button",{style:{position:"absolute",top:"100px",left:"100px",background:clicked?"red":"auto"},onClick:buttonClicked},"Click Me"), | ||
component.getDocument().body | ||
); | ||
component.updateTexture(); | ||
} | ||
|
||
var buttonClicked = function(){ | ||
clicked = true; | ||
render(); | ||
} | ||
render(); | ||
|
||
setTimeout(function(){ | ||
component.triggerEventAt("click",101,101); | ||
},3000) | ||
</script> | ||
</html> |
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,84 @@ | ||
// aframe-html.js | ||
// repo : https://github.com/richardanaya/aframe-html | ||
// license : MIT | ||
|
||
(function (window, module, AFRAME, rasterizeHTML) { | ||
"use strict"; | ||
AFRAME = AFRAME.aframeCore || AFRAME; | ||
|
||
AFRAME.registerComponent('html-material', { | ||
schema: { | ||
url: { | ||
type: 'string', | ||
default: "" | ||
}, | ||
width: { | ||
type: 'int', | ||
default: 0 | ||
}, | ||
height: { | ||
type: 'int', | ||
default: 0 | ||
} | ||
}, | ||
|
||
update: function () { | ||
var _this = this; | ||
if(!this.canvas){ | ||
this.canvas = document.createElement("canvas"); | ||
} | ||
this.canvas.width = this.data.width; | ||
this.canvas.height = this.data.height; | ||
var _this = this; | ||
var ctx = this.canvas.getContext("2d") | ||
ctx.clearRect(0,0,this.data.width,this.data.height); | ||
var texture = new THREE.Texture(this.canvas); | ||
var material = new THREE.MeshBasicMaterial({ map: texture, transparent: true }); | ||
this.el.object3D.children[0].material = material; | ||
|
||
if(!this.frame) { | ||
this.frame = document.createElement("iframe"); | ||
this.el.appendChild(this.frame); | ||
} | ||
|
||
var frameDocument = _this.frame.contentWindow.document; | ||
|
||
this.getDocument = function(){ | ||
return frameDocument; | ||
} | ||
this.updateTexture = function(){ | ||
rasterizeHTML.drawDocument(frameDocument, ctx.canvas, {width: _this.data.width}).then(function success(renderResult) { | ||
texture.needsUpdate = true; | ||
}, function error(e) { | ||
console.log(e) | ||
}); | ||
} | ||
|
||
function triggerMouseEvent (node, eventType) { | ||
var clickEvent = document.createEvent ('MouseEvents'); | ||
clickEvent.initEvent (eventType, true, true); | ||
node.dispatchEvent (clickEvent); | ||
} | ||
|
||
this.triggerEventAt = function(e,x,y){ | ||
var target = frameDocument.elementFromPoint(x,y); | ||
triggerMouseEvent(target,e); | ||
} | ||
|
||
if(this.data.url != ""){ | ||
this.frame.src = this.data.url; | ||
this.frame.addEventListener("load",function(){ | ||
frameDocument = _this.frame.contentWindow.document; | ||
_this.updateTexture(); | ||
}) | ||
} | ||
|
||
|
||
} | ||
}); | ||
})( | ||
typeof window !== "undefined" ? window : {}, | ||
typeof module !== "undefined" ? module : {}, | ||
typeof require !== "undefined" ? require("aframe") : (AFRAME || window.AFRAME), | ||
typeof require !== "undefined" ? require("rasterizehtml") : rasterizeHTML | ||
); |
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,37 @@ | ||
{ | ||
"name": "aframe-html", | ||
"version": "0.0.1", | ||
"description": "A component rendering and interacting with HTML in VR", | ||
"main": "index.js", | ||
"scripts": { | ||
"dev": "node node_modules/concurrently/src/main.js --kill-others \"./node_modules/webpack/bin/webpack.js --progress --colors --watch\" \"./node_modules/http-server/bin/http-server -s -c-1 -p 9998 .\" \"echo LISTENING ON localhost:9998\"" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/richardanaya/aframe-html.git" | ||
}, | ||
"keywords": [ | ||
"aframe", | ||
"html", | ||
"vr", | ||
"3d" | ||
], | ||
"author": "Richard Anaya <[email protected]> (http://www.richardanaya.com/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/richardanaya/aframe-html/issues" | ||
}, | ||
"homepage": "https://github.com/richardanaya/aframe-html#readme", | ||
"dependencies": { | ||
"aframe": "latest", | ||
"rasterizehtml": "^1.2.2" | ||
}, | ||
"devDependencies": { | ||
"concurrently": "^2.1.0", | ||
"http-server": "^0.9.0", | ||
"nodemon": "^1.9.2", | ||
"webpack": "^1.13.1", | ||
"react": "^15.1.0", | ||
"react-dom": "^15.1.0" | ||
} | ||
} |
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,12 @@ | ||
module.exports = { | ||
entry: "./examples.js", | ||
output: { | ||
path: __dirname+"/build/", | ||
filename: "bundle.js" | ||
}, | ||
module: { | ||
loaders: [ | ||
|
||
] | ||
} | ||
}; |