SHARE
TWEET

Urbisworld source code

a guest Nov 22nd, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.  
  3. var scene = new THREE.Scene();
  4. var camera = new THREE.PerspectiveCamera(37.5, 500 / 500, 0.1, 2000);
  5.     var strDownloadMime = "image/octet-stream";
  6. camera.position.y = 1.33;
  7. camera.position.z = 10;
  8.  
  9. var renderer = new THREE.WebGLRenderer({alpha: true, antialias: true, preserveDrawingBuffer: true});
  10. renderer.setSize(500, 500);
  11. document.getElementById("canvas").appendChild(renderer.domElement);
  12. renderer.shadowMapEnabled = true;
  13. renderer.shadowMapType = THREE.PCFSoftShadowMap;
  14.  
  15. var manager = new THREE.LoadingManager();
  16. var done = "0";
  17. manager.onLoad = function ( item, loaded, total ) {
  18.   var percentage = loaded / total * 100;
  19.    done = "1";
  20.  
  21. };
  22. manager.onError = function ( item, loaded, total ) {
  23. console.log("ERROR");
  24. };
  25.  var textureLoader = new THREE.TextureLoader(manager);
  26. var light2 = new THREE.DirectionalLight(0xffffff, 1);
  27. light2.position.x = -2;
  28. light2.position.y = 5;
  29. light2.position.z = 5;
  30. light2.castShadow = true;
  31. light2.shadowDarkness = 0.2;
  32. light2.lookAt(new THREE.Vector3(0,-1,0));
  33. scene.add(light2);
  34.  
  35. hemiLight = new THREE.HemisphereLight( 0xffffff, 0xffffff, 0.4);
  36. hemiLight.color.setHSL( 1, 1, 1 );
  37. hemiLight.position.set( 0, 400, 0 );
  38. scene.add( hemiLight );
  39.  
  40. var facematerial = new THREE.MeshPhongMaterial({
  41.    side: THREE.DoubleSide,
  42.    transparent: true,
  43.  });
  44. var headmaterial = new THREE.MeshPhongMaterial({
  45.    shininess: 10,
  46.    side: THREE.DoubleSide,
  47.    color: "#f7f7f7",
  48.  });
  49.  var torsomaterial = new THREE.MeshPhongMaterial({
  50.     shininess: 0,
  51.     side: THREE.DoubleSide,
  52.     color: "#191919",
  53.   });
  54.   var rarmmaterial = new THREE.MeshPhongMaterial({
  55.      shininess: 10,
  56.      side: THREE.DoubleSide,
  57.      color:  "#191919",
  58.    });
  59.    var larmmaterial = new THREE.MeshPhongMaterial({
  60.       shininess: 10,
  61.       side: THREE.DoubleSide,
  62.       color: "#191919" ,
  63.     });
  64.     var rlegmaterial = new THREE.MeshPhongMaterial({
  65.        shininess: 10,
  66.        side: THREE.DoubleSide,
  67.        color: "#da0000",
  68.      });
  69.      var llegmaterial = new THREE.MeshPhongMaterial({
  70.         shininess: 10,
  71.         side: THREE.DoubleSide,
  72.         color: "#da0000",
  73.       });
  74. var geometryhead = new THREE.BoxGeometry(0.85, 0.85, 0.85);
  75. var head = new THREE.Mesh(geometryhead, headmaterial);
  76. scene.add(head);
  77. head.position.y = -1.12;
  78. head.rotation.y = 0.55;
  79. head.position.x = 0;
  80. head.position.z = 1.4;
  81.  var facetexture = textureLoader.load( '/threejs/smile.png');
  82. var geometryface = new THREE.BoxGeometry(0.90, 0.90, 0.01);
  83. var face = new THREE.Mesh(geometryface, facematerial);
  84. scene.add(face);
  85. face.position.y = -0.95;
  86. face.rotation.y = 0.55;
  87. face.position.x = 0.2;
  88. face.position.z = 2.35;
  89. face.material.map = facetexture;
  90. var geometryTorsoBlock = new THREE.BoxGeometry(2, 2, 1);
  91. var TorsoBlock = new THREE.Mesh(geometryTorsoBlock, torsomaterial);
  92. scene.add(TorsoBlock);
  93. TorsoBlock.position.y = -3;
  94. TorsoBlock.rotation.y = 0.50;
  95.  
  96. var geometryTorso = new THREE.BoxGeometry(2, 2, 1);
  97. var torso = new THREE.Mesh(geometryTorso, torsomaterial);
  98. scene.add(torso);
  99. torso.position.y = -3;
  100. torso.rotation.y = 0.50;
  101.  
  102.  
  103. var geometryLeftArmBlock = new THREE.BoxGeometry(1, 2, 1);
  104. var LeftArmBlock = new THREE.Mesh(geometryLeftArmBlock, larmmaterial);
  105. scene.add(LeftArmBlock);
  106. LeftArmBlock.position.y = -3;
  107. LeftArmBlock.position.x = 1.30;
  108. LeftArmBlock.rotation.y = 0.50;
  109. LeftArmBlock.position.z = -0.70;
  110.  
  111.  
  112. var geometryLeftArm = new THREE.BoxGeometry(1, 2, 1);
  113. var LeftArm = new THREE.Mesh(geometryLeftArm, larmmaterial);
  114. scene.add(LeftArm);
  115. LeftArm.position.y = -3;
  116. LeftArm.position.x = 1.30;
  117. LeftArm.rotation.y = 0.50;
  118. LeftArm.position.z = -0.70;
  119.  
  120. var geometryRightArmBlock = new THREE.BoxGeometry(1, 2, 1);
  121. var RightArmBlock = new THREE.Mesh(geometryRightArmBlock, rarmmaterial);
  122. scene.add(RightArmBlock);
  123. RightArmBlock.position.y = -3;
  124. RightArmBlock.position.x = -1.30;
  125. RightArmBlock.rotation.y = 0.50;
  126. RightArmBlock.position.z = 0.70;
  127.                 RightArmBlock.castShadow = true;
  128.  
  129. var geometryRightArm = new THREE.BoxGeometry(1, 2, 1);
  130. var RightArm = new THREE.Mesh(geometryRightArm, rarmmaterial);
  131. scene.add(RightArm);
  132. RightArm.position.y = -3;
  133. RightArm.position.x = -1.30;
  134. RightArm.rotation.y = 0.50;
  135. RightArm.position.z = 0.70;
  136.  
  137.  
  138. var geometryLeftLeg = new THREE.BoxGeometry(1, 2, 1);
  139. var LeftLeg = new THREE.Mesh(geometryLeftLeg, llegmaterial );
  140. scene.add(LeftLeg);
  141. LeftLeg.position.y = -5;
  142. LeftLeg.position.x = 0.45;
  143. LeftLeg.rotation.y = 0.50;
  144. LeftLeg.position.z = -0.25;
  145.  
  146.  
  147. var geometryRightLeg = new THREE.BoxGeometry(1, 2, 1);
  148. var RightLeg = new THREE.Mesh(geometryRightLeg, rlegmaterial);
  149. scene.add(RightLeg);
  150. RightLeg.position.y = -5;
  151. RightLeg.position.x = -0.45;
  152. RightLeg.rotation.y = 0.50;
  153. RightLeg.position.z = 0.25;
  154.  
  155.  
  156. var canvas = document.getElementsByTagName('canvas');
  157.  
  158.  var objLoader = new THREE.OBJLoader(manager);
  159.  var hatmaterial = new THREE.MeshPhongMaterial({
  160.     side: THREE.DoubleSide,
  161.     transparent: true,
  162.   });
  163.  var texture1 = textureLoader.load( '/threejs/tex.png');
  164.  var materialshirt = new THREE.MeshPhongMaterial({
  165.     side: THREE.DoubleSide,
  166.     transparent: true,
  167.   });
  168. objLoader.load('shirt.obj', function(object1) {
  169.   object1.position.y = -3;
  170.   object1.rotation.y = 2.071;
  171. object1.rotation.z = 3.1415926535;
  172.  
  173. object1.scale.set(0.01,0.01,0.01);
  174. object1.traverse( function ( child ) {
  175.  
  176.   if ( child.isMesh )  {
  177.   child.material = materialshirt;
  178.    child.material.map = texture1;
  179. }
  180. } );
  181.  
  182. scene.add(object1);
  183.  
  184. });
  185.  
  186. var texture2 = textureLoader.load( '/threejs/tex.png');
  187. var materialpants = new THREE.MeshPhongMaterial({
  188.      side: THREE.DoubleSide,
  189.      transparent: true,
  190.  });
  191. objLoader.load('pants.obj', function(object2) {
  192.     object2.position.y = -5;
  193.   object2.rotation.y = 2.08;
  194. object2.rotation.z = 3.14159;
  195. object2.position.x = 0.1;
  196. object2.scale.set(0.01,0.01,0.01);
  197. object2.traverse( function ( child ) {
  198.  
  199.  if ( child.isMesh ){
  200. child.material = materialpants;
  201.  child.material.map = texture2;
  202. }
  203. } );
  204.  
  205. scene.add(object2);
  206.  
  207. });
  208. var doneval = 0;
  209. var fullydone = 0;
  210. var render = function() {
  211. requestAnimationFrame(render);
  212. camera.lookAt(new THREE.Vector3(0,-3,0));
  213. renderer.render(scene, camera);
  214. doneval = done;
  215. if (done != "1"){
  216. console.log(doneval);
  217. }
  218.  
  219. if(doneval == "1" && fullydone == "0"){
  220.  
  221. var photoa = canvas['0'].toDataURL();
  222. var photo = photoa.replace('data:image/png;base64,', '');
  223. $.ajax({
  224.   type: 'POST',
  225.   data: {  photodata:photo  },
  226.   dataType: 'text',
  227.   url: 'imgupload.php',
  228.   success: function(data) {
  229.                 console.log(data);
  230.  
  231.              }
  232.   });
  233.   fullydone = "1";
  234.  
  235.   }
  236.  
  237.  
  238. };
  239. render();
  240.  
  241. </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top