three+oimo实现三维篮球场投篮得分代码

代码语言:html

所属分类:三维

代码描述:three+oimo实现三维篮球场投篮得分代码,点击鼠标左键投篮。

代码标签: three oimo 三维 篮球 投篮 得分 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">

  
  
  
<style>
@import url('https://fonts.googleapis.com/css?family=Roboto+Condensed|Playfair+Display:700i|Didact+Gothic');
     html,body{
      overflow: hidden;
      background:black;
   
      font-family: monospace;
      font-family: 'Roboto', sans-serif;
     }
      html {
        box-sizing: border-box;
      }
      *, *:before, *:after {
        box-sizing: inherit;
      }
      *{
        margin:0;
        padding: 0;
      }
      h1{
        font-family: "Roboto Condensed", "Helvetica Neue", Helvetica, Arial, sans-serif;
        font-size: 30px;
        line-height: 1;
      }
   
       section{
          color: white;
          max-width: 275px;
          width: 100%;
          display: none;
          font-size: 14px
        }
        p{
          color: rgba(255,255,255,0.5);
        }
        a{
          color: white;
        }
    
        span.low{
          color: #a32e2c;
        }
        .btn-group{
          display: flex;
          -webkit-display: flex;
          justify-content: space-between;
          -webkit-justify-content: space-between;
          width: 100%;
          padding: 50px 25px;
          position: absolute;
          left: 0;
          bottom: 0;
          visibility: hidden;
        }
        .btn-group span{
          width: 75px;
          height: 75px;
          border-radius: 50%;
          background: white;
          background: #222;
          color: white;
          text-align: center;
          display: flex;
          -webkit-display: flex;
          align-items: center;
          -webkit-align-items: center;
          justify-content: center;
          -webkit-justify-content: center;
          font-weight: bold;
          font-size: 30px;
          box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.5);
        }

        #VR {
          position: fixed;
          top: 20px;
          right: 20px;
          outline: none;
          border: none;
          width: 60px;
          height: 40px;
          z-index: 100;
          background: rgba(135,206,250,0.75);
          display: flex;
          -webkit-display: flex;
          justify-content: center;
          -webkit-justify-content: center;
          align-items: center;
          -webkit-align-items: center;
          visibility: hidden;
        }

        #VR svg {
          width: 60px;
          height: 35px;
          transform: scale(2);
          -webkit-transform: scale(2);
          fill: white;
        }
        button {
          background: none;
          border:none;
        }

        button:hover {
          cursor: pointer;
        }
        button#start{
          color:white;
          border: 2px solid white;
          padding: 10px 20px;
          font-weight: bold;
          font-family: "Roboto Condensed", "Helvetica Neue", Helvetica, Arial, sans-serif;
          font-size: 18px;
          margin: 10px 0;
        }

      @media (min-width: 1300px){
        section{
          display: block;
          position: absolute;
          top: 50px;
          left: 50px;
        }
      }


    /* Show only on touchscreen devices */
    @media (pointer: coarse) {
      .btn-group, #VR{
          visibility: visible;
        }
        .hide{
           visibility: hidden;
        }
    }
</style>


  
  
</head>

<body translate="no">
  <button id='VR' class='button toggleVR' onclick='toggleVR()' title='Toggle VR Mode for Mobile Devices Only'>
    <svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="-12 -12 48 48"><path fill="#fff" d="M23.058 5.038H.942c-.522 0-.942.422-.942.94V18.02c0 .522.423.942.942.942H8.8c.26 0 .492-.174.564-.425.88-3.028 1.062-4.754 2.724-4.754 1.66 0 1.905 1.973 2.685 4.766.068.243.29.41.543.41h7.743c.52 0 .94-.424.94-.943V5.982c0-.522-.42-.944-.942-.944zm-16.43 9.467c-1.384 0-2.504-1.12-2.504-2.504s1.12-2.503 2.504-2.503 2.5 1.12 2.5 2.504-1.12 2.505-2.5 2.505zm10.744 0c-1.384 0-2.504-1.12-2.504-2.504s1.12-2.503 2.504-2.503c1.383 0 2.504 1.12 2.504 2.504s-1.12 2.505-2.504 2.505z"/></svg>
  </button>



<section>
  <h1 id="title">Click<span class="low">To</span>Shoot</h1>
  <p>move and click mouse to shoot</p>
  <p>Score:<small>0<small></p>
</section>


  <div class="btn-group">
    <span>RL</span>
    <span>RR</span>
  </div>




<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.124.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jsonloader.126.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/DeviceOrientationControls.126.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.126.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/StereoEffect.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/TweenMax.min.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/Projector.126.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/oimo.1.0.9.js"></script>
  
      <script >
const randnum = (min, max) => Math.round(Math.random() * (max - min) + min);

//=========================================================================================== scene
var scene = new THREE.Scene();

//=========================================================================================== camera
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000);


//=========================================================================================== canvas
renderer = new THREE.WebGLRenderer({
  alpha: true,
  antialias: true });

renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMapEnabled = true; //Shadow
renderer.shadowMapSoft = true; // Shadow
renderer.shadowMapType = THREE.PCFShadowMap; //Shadow
document.body.appendChild(renderer.domElement);

//=========================================================================================== add VR
renderer.setPixelRatio(window.devicePixelRatio); //VR
var effect = new THREE.StereoEffect(renderer); //VR
effect.setSize(window.innerWidth, window.innerHeight); //VR
var VR = false;

function toggleVR() {
  if (VR) {
    VR = false;
    camera.rotation.reorder('ZYX');
    camera.lookAt(0, 0, 0);
  } else {
    VR = true;
    controls = new THREE.DeviceOrientationControls(camera);
    requestFullscreen(document.documentElement);
  }
  renderer.setSize(window.innerWidth, window.innerHeight);
}



//=========================================================================================== post processing
/* var renderScene = new THREE.RenderPass(scene, camera);

  var effectFXAA = new THREE.ShaderPass(THREE.FXAAShader);
  effectFXAA.uniforms['resolution'].value.set(1 / window.innerWidth, 1 / window.innerHeight );

  var copyShader = new THREE.ShaderPass(THREE.CopyShader);
  copyShader.renderToScreen = true;
  

  //var bloomStrength = 2;
  //var bloomRadius = 5;
  //var bloomThreshold = 0.4;
  var bloomStrength = 1;
  var bloomRadius = 0;
  var bloomThreshold = .5;
  var bloomPass = new THREE.UnrealBloomPass(new THREE.Vector2(window.innerWidth, window.innerHeight),bloomStrength, bloomRadius, bloomThreshold);
  
  var composer = new THREE.EffectComposer(renderer);
  composer.setSize(window.innerWidth, window.innerHeight);
  composer.addPass(renderScene);
  composer.addPass(effectFXAA);
  composer.addPass(bloomPass);
  composer.addPass(copyShader);
*/
//=========================================================================================== resize
window.addEventListener("resize", function () {
  let width = window.innerWidth;
  let height = window.innerHeight;
  renderer.setSize(width, height);
  camera.aspect = width / height;
  camera.updateProjectionMatrix();
});


//=========================================================================================== fog
scene.fog = new THREE.FogExp2(new THREE.Color("black"), 0.0001);

//=========================================================================================== light
var sphereLight = new THREE.SphereGeometry(1.05);
var sphereLightMaterial = new THREE.MeshBasicMaterial({
  color: new THREE.Color("white") });

var sphereLightMesh = new THREE.Mesh(sphereLight, sphereLightMaterial);
sphereLightMesh.castShadow = true;
sphereLightMesh.position.set(0, 5.5, 0);
//scene.add(sphereLightMesh);


var distance = 150;
var intensity = 1;


var pointLight = new THREE.PointLight(new THREE.Color('white'), intensity, distance);
pointLight.position.set(0, 5, -6);
scene.add(pointLight);


var pointLight3 = new THREE.PointLight(new THREE.Color('blue'), intensity / 1.25, distance);
pointLight3.position.set(0, 0, 0);
scene.add(pointLight3);





var spotLight = new THREE.SpotLight(0xffffff, 0, distance);
spotLight.position.set(0, 10, 0);

spotLight.castShadow = true;
scene.add(spotLight);



//=========================================================================================== floor
/*var groundMaterial = new THREE.MeshPhongMaterial({
  color: new THREE.Color('#fff'),
  specular: new THREE.Color('skyblue'),
  shininess: 50,
});
var groundGeo = new THREE.PlaneGeometry(200, 200);
var ground = new THREE.Mesh(groundGeo, groundMaterial);

ground.position.set(0, 0, 0);
ground.rotation.x = (-Math.PI / 2);
ground.receiveShadow = true;
scene.add(ground);
*/








//=========================================================================================== model
//3d
loader = new THREE.LegacyJSONLoader();
loader.load('//repo.bfw.wiki/bfwrepo/js/custom/hoop-goal.js', function (geometry, materials) {
  var wall = new THREE.Mesh(geometry, materials);
  wall.position.set(0, 0, 0);
  wall.rotateY(Math.PI);
  wall.scale.set(4, 4, 4);
  wall.castShadow = true;
  scene.add(wall);

});


//===================================================== add model
var loader = new THREE.LegacyJSONLoader();
loader.load("//repo.bfw.wiki/bfwrepo/js/custom/court.js", function (geometry, materials) {
  var obj = new THREE.Mesh(geometry, materials);
  obj.scale.set(1, 1, 1);
  obj.receiveShadow = true;
  obj.position.set(0, .2, -40);
  /*  obj.rotateY(-Math.PI);*/
  scene.add(obj);

});




//===================================================== add group
var lightGroup = new THREE.Group();
lightGroup.position.set(-25, 0, -40);
scene.add(lightGroup);

lightGroup2 = lightGroup.clone();
lightGroup2.position.set(25, 0, 0);
lightGroup2.rotateY(Math.PI);
scene.add(lightGroup2);



lightGroup3 = lightGroup.clone();
lightGroup3.position.set(-15, 0, 8);
scene.add(lightGroup3);



//===========================================.........完整代码请登录后点击上方下载按钮下载查看

网友评论0