Browse Source

Merge pull request #52 from AtomicGameEngine/JME-ATOMIC-WEBVIEW3D

Jme atomic webview3 d
JoshEngebretson 10 years ago
parent
commit
d6d70425e2

+ 1 - 1
AtomicWebView/Resources/Components/WebView.js

@@ -110,7 +110,7 @@ function createBrowserTab(tabContainer, url) {
   layout.spacing = 8;
 
   var tabButton = new Atomic.UIButton();
-  tabButton.text = "...";
+  tabButton.text = "Loading...";
 
   // button layout and font desc
   var buttonLP = new Atomic.UILayoutParams();

+ 80 - 0
WebView3D/Resources/Components/WebTexture.js

@@ -0,0 +1,80 @@
+"atomic component";
+
+const BROWSER_WIDTH = 1024;
+const BROWSER_HEIGHT = 1024;
+const BROWSER_URL = "http://www.atomicgameengine.com/";
+
+// First create a web texture and set filtering mode
+var webTexture = new WebView.WebTexture2D();
+var texture2D = webTexture.texture2D;
+texture2D.filterMode = Atomic.FILTER_TRILINEAR;
+
+// Setup a simple material for the web texture
+var webMaterial = new Atomic.Material();
+webMaterial.setTechnique(0, Atomic.cache.getResource("Technique", "Techniques/DiffEmissive.xml"));
+webMaterial.setTexture(Atomic.TU_EMISSIVE, texture2D);
+webMaterial.setShaderParameter("MatEmissiveColor", "1 1 1 1");
+
+// Create web client with pluggable handlers
+var webClient = new WebView.WebClient();
+// Set our render handler to be the WebTexture2D we created above
+webClient.webRenderHandler = webTexture;
+// Create the browser!
+webClient.createBrowser(BROWSER_URL, BROWSER_WIDTH, BROWSER_HEIGHT);
+
+exports.component = function(self) {
+
+  var camera = self.node.scene.getComponent("Camera", true);
+  var octree = self.node.scene.getComponent("Octree", true);
+
+  // assign the web material to our model component
+  var model = self.node.getComponent("StaticModel");
+  model.setMaterial(webMaterial);
+
+  var hm = true;
+
+  // update function
+  self.update = function(timeStep) {
+
+    // 3D web texture interaction
+    var mousePos = Atomic.input.getMousePosition();
+
+    if (Atomic.input.getKeyPress(Atomic.KEY_L)) {
+
+        hm = !hm;
+    }
+
+    if (!hm)
+        return;
+
+
+    // normalize x/y
+    mousePos[0] /= Atomic.graphics.width;
+    mousePos[1] /= Atomic.graphics.height;
+
+    // calculate the screen ray at the mouse point
+    var ray = camera.getScreenRay(mousePos[0], mousePos[1]);
+
+    var result = octree.rayCastSingle(ray, Atomic.RAY_TRIANGLE_UV, Atomic.M_INFINITY, Atomic.DRAWABLE_GEOMETRY);
+
+    if (result) {
+
+      var uv = result.textureUV;
+      var x = uv[0] * BROWSER_WIDTH;
+      var y = uv[1] * BROWSER_WIDTH;
+
+      webClient.sendMouseMoveEvent(x, y, 0);
+
+      if (Atomic.input.getMouseButtonPress(Atomic.MOUSEB_LEFT)) {
+        webClient.sendMousePressEvent(x, y);
+      }
+
+    }
+
+    if (Atomic.input.mouseMoveWheel) {
+
+      webClient.sendMouseWheelEvent(0, 0, 0, 0, -Atomic.input.mouseMoveWheel);
+
+    }
+  }
+}

+ 7 - 0
WebView3D/Resources/Components/WebTexture.js.asset

@@ -0,0 +1,7 @@
+{
+	"version": 1,
+	"guid": "9066468b7796a830baaac783ff11a0b4",
+	"JavascriptImporter": {
+		"IsComponentFile": true
+	}
+}

BIN
WebView3D/Resources/Models/Plane.blend


+ 9 - 0
WebView3D/Resources/Models/Plane.blend.asset

@@ -0,0 +1,9 @@
+{
+	"version": 1,
+	"guid": "e594edaf52a3c89f44b0029130e721f0",
+	"ModelImporter": {
+		"scale": 1,
+		"importAnimations": false,
+		"animInfo": []
+	}
+}

+ 22 - 5
WebView3D/Resources/Scenes/Scene.scene

@@ -5,8 +5,8 @@
 	<attribute name="Smoothing Constant" value="50" />
 	<attribute name="Snap Threshold" value="5" />
 	<attribute name="Elapsed Time" value="0" />
-	<attribute name="Next Replicated Node ID" value="696" />
-	<attribute name="Next Replicated Component ID" value="2328" />
+	<attribute name="Next Replicated Node ID" value="699" />
+	<attribute name="Next Replicated Component ID" value="2332" />
 	<attribute name="Next Local Node ID" value="16778496" />
 	<attribute name="Next Local Component ID" value="16777216" />
 	<attribute name="Variables" />
@@ -50,7 +50,6 @@
 		<component type="StaticModel" id="1981">
 			<attribute name="Model" value="Model;7dbadf4270c90e1ec4f024c6582ce0fd.mdl" />
 			<attribute name="Material" value="Material;Models/Materials/Material #15.material;Models/Materials/Material #212.material;Models/Materials/Material #215.material;Models/Materials/Material #214.material;Models/Materials/Material #213.material;Models/Materials/creek.material;Models/Materials/grassPath.material;Models/Materials/creek.material;Models/Materials/woodFence.material;Models/Materials/creek.material;Models/Materials/woodFenceBridge.material;Models/Materials/rockPath.material;Models/Materials/woodFence.material;Models/Materials/woodFence.material;Models/Materials/woodFence.material;Models/Materials/woodFence.material;Models/Materials/woodFence.material;Models/Materials/Material #213.material;Models/Materials/Material #212.material;Models/Materials/clouds.material;Models/Materials/cabin.material;Models/Materials/Material #15.material;Models/Materials/Material #d214dfg.material;Models/Materials/Material #212.material;Models/Materials/Material #d214dfg.material;Models/Materials/Material #212.material;Models/Materials/Material #d214dfg.material;Models/Materials/Material #212.material;Models/Materials/Material #d214dfg.material;Models/Materials/Material #212.material;Models/Materials/Material #d214dfg.material;Models/Materials/Material #212.material" />
-			<attribute name="Cast Shadows" value="true" />
 			<attribute name="Geometry Enabled">
 				<variant type="Bool" value="true" />
 				<variant type="Bool" value="true" />
@@ -1692,8 +1691,8 @@
 	<node id="450">
 		<attribute name="Is Enabled" value="true" />
 		<attribute name="Name" value="Robo_01" />
-		<attribute name="Position" value="-7.9985 7.9666 0.740251" />
-		<attribute name="Rotation" value="0.40843 0 -0.91279 0" />
+		<attribute name="Position" value="-50.5209 2.98821 -13.9815" />
+		<attribute name="Rotation" value="-0.299878 0 -0.953978 0" />
 		<attribute name="Scale" value="1 1 1" />
 		<attribute name="Variables" />
 		<component type="AnimatedModel" id="2058">
@@ -29973,4 +29972,22 @@
 			</component>
 		</node>
 	</node>
+	<node id="697">
+		<attribute name="Is Enabled" value="true" />
+		<attribute name="Name" value="MovieScreen" />
+		<attribute name="Position" value="-105.328 14.7633 -10.3621" />
+		<attribute name="Rotation" value="0.718612 0 -0.695411 0" />
+		<attribute name="Scale" value="20 20 1" />
+		<attribute name="Variables" />
+		<component type="StaticModel" id="2329">
+			<attribute name="Model" value="Model;e594edaf52a3c89f44b0029130e721f0.mdl" />
+			<attribute name="Material" value="Material;" />
+			<attribute name="Geometry Enabled">
+				<variant type="Bool" value="true" />
+			</attribute>
+		</component>
+		<component type="JSComponent" id="2330">
+			<attribute name="ComponentFile" value="JSComponentFile;Components/WebTexture.js" />
+		</component>
+	</node>
 </scene>