ThreeBSP.js 源码下载

通过git上的ThreeBSP.coffee转换为js代码,有需要的拿走不谢。

// Generated by CoffeeScript 1.12.7
(function() {
  var BACK, COPLANAR, EPSILON, FRONT, SPANNING, Timelimit, returning,
    bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    slice = [].slice,
    extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
    hasProp = {}.hasOwnProperty;

  EPSILON = 1e-5;

  COPLANAR = 0;

  FRONT = 1;

  BACK = 2;

  SPANNING = 3;

  returning = function(value, fn) {
    fn();
    return value;
  };

  Timelimit = (function() {
    function Timelimit(timeout, progress) {
      this.timeout = timeout;
      this.progress = progress;
      this.doTask = bind(this.doTask, this);
      this.finish = bind(this.finish, this);
      this.start = bind(this.start, this);
      this.check = bind(this.check, this);
      "NOTHING";
    }

    Timelimit.prototype.check = function() {
      var elapsed;
      if (this.started == null) {
        return;
      }
      return returning((elapsed = Date.now() - this.started), (function(_this) {
        return function() {
          var ref, ref1, ref2;
          if ((ref = elapsed >= _this.timeout) != null ? ref : 2e308) {
            throw new Error("Timeout reached: " + elapsed + "/" + _this.timeout + ", " + ((ref1 = _this.tasks) != null ? ref1 : 0) + " tasks unfinished " + ((ref2 = _this.done) != null ? ref2 : 0) + " finished.");
          }
        };
      })(this));
    };

    Timelimit.prototype.start = function() {
      if (this.started == null) {
        this.started = Date.now();
      }
      if (this.tasks == null) {
        this.tasks = 0;
      }
      if (this.total == null) {
        this.total = 0;
      }
      this.total += 1;
      this.tasks += 1;
      return this.check();
    };

    Timelimit.prototype.finish = function() {
      var elapsed;
      if ((this.tasks != null) && this.tasks < 1) {
        throw new Error("Finished more tasks than started");
      }
      this.tasks -= 1;
      elapsed = this.check();
      if (this.done == null) {
        this.done = 0;
      }
      this.done += 1;
      if (this.progress != null) {
        this.progress(this.done, this.total);
      }
      if (this.tasks === 0) {
        "Finished " + this.done + " tasks in " + elapsed + "/" + this.timeout + " ms";
        return this.started = this.done = this.total = void 0;
      }
    };

    Timelimit.prototype.doTask = function(block) {
      var result;
      this.start();
      result = block();
      this.finish();
      return result;
    };

    return Timelimit;

  })();

  window.ThreeBSP = (function() {
    function ThreeBSP(treeIsh, matrix1, options) {
      var base, ref, ref1, ref2, ref3;
      this.matrix = matrix1;
      this.options = options != null ? options : {};
      this.intersect = bind(this.intersect, this);
      this.union = bind(this.union, this);
      this.subtract = bind(this.subtract, this);
      this.toGeometry = bind(this.toGeometry, this);
      this.toMesh = bind(this.toMesh, this);
      this.toTree = bind(this.toTree, this);
      this.withTimer = bind(this.withTimer, this);
      if ((this.matrix != null) && !(this.matrix instanceof THREE.Matrix4)) {
        this.options = this.matrix;
        this.matrix = void 0;
      }
      if (this.options == null) {
        this.options = {};
      }
      if (this.matrix == null) {
        this.matrix = new THREE.Matrix4();
      }
      if ((base = this.options).timer == null) {
        base.timer = new Timelimit((ref = (ref1 = this.options.timer) != null ? ref1.timeout : void 0) != null ? ref : this.options.timeout, (ref2 = (ref3 = this.options.timer) != null ? ref3.progress : void 0) != null ? ref2 : this.options.progress);
      }
      this.tree = this.toTree(treeIsh);
    }

    ThreeBSP.prototype.withTimer = function(new_timer, block) {
      var old_timer;
      old_timer = this.options.timer;
      try {
        this.options.timer = new_timer;
        return block();
      } finally {
        this.options.timer = old_timer;
      }
    };

    ThreeBSP.prototype.toTree = function(treeIsh) {
      var face, fn1, geometry, i, k, len, polygons, ref;
      if (treeIsh instanceof ThreeBSP.Node) {
        return treeIsh;
      }
      polygons = [];
      geometry = treeIsh instanceof THREE.Geom
  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值