three实现360全景沙漠中的环面玻璃材质效果代码

代码语言:html

所属分类:三维

代码描述:three实现360全景沙漠中的环面玻璃材质效果代码

代码标签: three 360 全景 沙漠 环面 玻璃 材质

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

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

<head>

  <meta charset="UTF-8">
  

  
<style>
* {
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
  margin: 0;
  padding: 0;
}
body {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
}
canvas {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  margin: 0;
  padding: 0;
}
</style>



</head>

<body  >
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.145.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.145.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/ammo.wasm.min.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/ParametricGeometry.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/ParametricGeometries.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/CurveExtras.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/GroundProjectedEnv.js"></script>
      <script  type="module">
async function e() {
  function e(e, t = {
    x: 1,
    y: 1,
    z: 1 })
  {
    let n = null;
    u.setValue(0, 0, 0);
    let o = e.attributes.position.array;
    n = new Ammo.btConvexHullShape();
    for (let e = 0, t = o.length; e < t; e += 3) {
      u.setValue(o[e], o[e + 1], o[e + 2]);
      const i = e >= t - 3;
      n.addPoint(u, i);
    }
    return n && (u.setValue(t.x, t.y, t.z), n.setLocalScaling(u), n.setMargin(0)), n;
  }
  function n(e, t, n, i = null) {
    m = e.position, h = e.quaternion, c.setIdentity(), u.setValue(m.x, m.y, m.z), c.setOrigin(u),
    c.setRotation(new o.btQuaternion(h.x, h.y, h.z, h.w)), u.setValue(0, 0, 0);
    const a = new o.btDefaultMotionState(c),s = u;
    t > 0 && n.calculateLocalInertia(t, s);
    const r = new o.btRigidBodyConstructionInfo(t, a, n, s),d = new o.btRigidBody(r);
    "ball" == e.name || "sphere_i" == e.name ? (d.setFriction(0), d.setRestitution(0),
    d.setDamping(0, 0)) : "curve" == e.name ? (d.setFriction(0), d.setRestitution(0),
    d.setDamping(0, 0)) : "torus" == e.name || "sphere_o" == e.name ? (d.setFriction(.1),
    d.setRestitution(0), d.setDamping(0, 0)) : "wall" == e.name ? (d.setFriction(10),
    d.setRollingFriction(1), d.setRestitution(0), d.setDamping(0, 0)) : (d.setFriction(1),
    d.setRollingFriction(.5), d.setRestitution(0), d.setDamping(0, 0)), "ball" == e.name && i && (u.setValue(i.x, i.y, i.z),
    d.setLinearVelocity(u)), d.name = e.name, l.addRigidBody(d), t > 0 && (p.push(e),
    g.set(e, d));
  }
  if ("Ammo" in window == !1) return;
  const o = await Ammo(),i = new o.btDefaultCollisionConfiguration(),a = new o.btCollisionDispatcher(i),s = new o.btDbvtBroadphase(),r = new o.btSequentialImpulseConstraintSolver(),l = new o.btDiscreteDynamicsWorld(a, s, r, i);
  l.setGravity(new o.btVector3(0, -10, 0)), Ammo.btGImpactCollisionAlgorithm.prototype.registerAlgorithm(l.getDispatcher());
  let c = new o.btTransform();
  const d = new o.btTransform();
  let m,u = new o.btVector3(0, 0, 0),h = new o.btQuaternion(0, 0, 0, 0),w = (new THREE.Vector3(0, 0, 1).normalize(),
  null),E = "",p = [],g = new WeakMap(),M = 0;
  return setInterval(function () {
    const e = performance.now();
    if (M > 0) {
      const t = (e - M) / 1e3;
      l.stepSimulation(t, 10);
    }
    M = e;
    for (let e = 0, n = p.length; e < n; e++) {
      if (!p[e]) continue;
      let n = p[e];
      if (n.isInstancedMesh) {
        let e = n.instanceMatrix.array;
        if (!g.has(n)) continue;
        let o = g.get(n);
        for (let n = 0; n < o.length; n++) o[n] && (o[n].getMotionState().getWorldTransform(d),
        m = d.getOrigin(), h = d.getRotation(), t(m, h, e, 16 * n));
        g.set(n, o), n.instanceMatrix.needsUpdate = !0;
      } else if (n.isMesh) {
        if (!g.has(n)) continue;
        g.get(n).getMotionState().getWorldTransform(d), m = d.getOrigin(), h = d.getRotation(),
        n.position.set(m.x(), m.y(), m.z()), n.quaternion.set(h.x(), h.y(), h.z(), h.w());
      }
    }
  }, 1e3 / 60), {
    addMesh: function (t, o = 0) {
      const i = e(t.geometry, t.scale);
      if (!i) return !1;
      n(t, o, i);
    },
    addStaticMesh: function (e) {
      const t = function (e, t = {
        x: 1,
        y: 1,
        z: 1 })
      {
        let n = new Ammo.btTriangleMesh(),o = e.attributes.position.array;
        for (let e = 0; 3 * e < o.length; e++) n.addTriangle(new Ammo.btVector3(o[9 * e], o[9 * e + 1], o[9 * e + 2]), new Ammo.btVector3(o[9 * e + 3], o[9 * e + 4], o[9 * e + 5]), new Ammo.btVector3(o[9 * e + 6], o[9 * e + 7], o[9 * e + 8]), !1);
        let i = new Ammo.btBvhTriangleMeshShape(n, !0, !0);
        return i && (u.setValue(t.x, t.y, t.z), i.setLocalScaling(u), i.setMargin(0)), i;
      }(e.geometry, e.scale);
      if (!t) return !1;
      n(e, 0, t);
    },
    addCompoundMesh: function (t, i = 0, a = []) {
      let s = new o.btCompoundShape();
      for (let n = 0; n < a.length; n++) {
        let o = e(a[n], t.scale);
        if (!o) return !1;
        u.setValue(0, 0, 0), c.setIdentity(), c.setOrigin(u), s.addChildShape(c, o);
      }
      n(t, i, s);
    },
    addConcaveMesh: function (e, t = 0) {
      if ((!e.name || e.name && e.name != E) && (w = function (e, t = {
        x: 1,
        y: 1,
        z: 1 })
      {
        let n = null;
        const o = null !== e.index ? e.index : void 0,i = e.attributes;
        if (void 0 === i.position) return;
        const a = i.position;
        let s = [],r = [];
        for (let e = 0; e < a.count; e++) s.push({
          x: a.getX(e),
          y: a.getY(e),
          z: a.getZ(e) });

        if (void 0 !== o) for (let e = 0; e < o.count; e += 3) r.push({
          a: o.getX(e),
          b: o.getX(e + 1),
       .........完整代码请登录后点击上方下载按钮下载查看

网友评论0