WebTexture.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "atomic component";
  2. const BROWSER_WIDTH = 1024;
  3. const BROWSER_HEIGHT = 1024;
  4. // First create a web texture and set filtering mode
  5. var webTexture = new WebView.WebTexture2D();
  6. var texture2D = webTexture.texture2D;
  7. texture2D.filterMode = Atomic.FILTER_TRILINEAR;
  8. // Setup a simple material for the web texture
  9. var webMaterial = new Atomic.Material();
  10. webMaterial.setTechnique(0, Atomic.cache.getResource("Technique", "Techniques/Diff.xml"));
  11. webMaterial.setTexture(Atomic.TU_DIFFUSE, texture2D);
  12. // Create web client with pluggable handlers
  13. var webClient = new WebView.WebClient();
  14. // Set our render handler to be the WebTexture2D we created above
  15. webClient.webRenderHandler = webTexture;
  16. // Create the browser!
  17. webClient.createBrowser("http://www.atomicgameengine.com", BROWSER_WIDTH, BROWSER_HEIGHT);
  18. exports.component = function(self) {
  19. var camera = self.node.scene.getComponent("Camera", true);
  20. var octree = self.node.scene.getComponent("Octree", true);
  21. // assign the web material to our model component
  22. var model = self.node.getComponent("StaticModel");
  23. model.setMaterial(webMaterial);
  24. // update function
  25. self.update = function(timeStep) {
  26. if (Atomic.input.getMouseButtonPress(Atomic.MOUSEB_LEFT)) {
  27. var mousePos = Atomic.input.getMousePosition();
  28. // normalize x/y
  29. mousePos[0] /= Atomic.graphics.width;
  30. mousePos[1] /= Atomic.graphics.height;
  31. // calculate the screen ray at the mouse point
  32. var ray = camera.getScreenRay(mousePos[0], mousePos[1]);
  33. var result = octree.rayCastSingle(ray, Atomic.RAY_TRIANGLE_UV, Atomic.M_INFINITY, Atomic.DRAWABLE_GEOMETRY);
  34. if (result) {
  35. var uv = result.textureUV;
  36. webClient.sendMousePressEvent(uv[0] * BROWSER_WIDTH, uv[1] * BROWSER_HEIGHT);
  37. }
  38. }
  39. }
  40. }