Esempio n. 1
0
  /**
   * Update local information from the scene. It's important that this method is synchronized
   * because we get ConcurrentModificationException's during rendering otherwise.
   *
   * <p>This method is called from sceneChanged().
   */
  protected synchronized void updateCharges(Scene theScene) {
    // Clear cached infos.
    cachedBounds = null;
    cachedWire = null;
    charges.clear();

    setPositive = null;
    setNegative = null;

    // Get all selection sets.
    Object layersObj = theScene.getMetadata("selectionsPlugin.selectionSets");

    if (layersObj == null) return;

    if (!(layersObj instanceof ArrayList)) return;

    ArrayList<ObjectSet> layers = (ArrayList<ObjectSet>) layersObj;

    // Try to find those which are of interest for us.
    for (ObjectSet set : layers) {
      if (set.getName().equals(setNamePositive)) {
        setPositive = set;
      } else if (set.getName().equals(setNameNegative)) {
        setNegative = set;
      }
    }

    // Create charges.
    if (setPositive != null) {
      for (ObjectInfo oi : setPositive.getObjects(theScene)) {
        if (oi.getObject() instanceof Sphere) {
          Sphere s = (Sphere) oi.getObject();
          double q = s.getRadii().x;
          Vec3 pos = oi.getCoords().getOrigin();

          charges.add(new SphereCharge(pos, q));
        }
      }
    }

    if (setNegative != null) {
      for (ObjectInfo oi : setNegative.getObjects(theScene)) {
        if (oi.getObject() instanceof Sphere) {
          Sphere s = (Sphere) oi.getObject();
          double q = -s.getRadii().x;
          Vec3 pos = oi.getCoords().getOrigin();

          charges.add(new SphereCharge(pos, q));
        }
      }
    }
  }
Esempio n. 2
0
  @Override
  public WireframeMesh getWireframeMesh() {
    if (cachedWire != null) return cachedWire;

    // This is a dirty hack.
    // TODO: Remove it!

    Vec3 vert[] = new Vec3[0];
    int[] from = new int[0];
    int[] to = new int[0];

    if (charges.size() <= 0) {
      cachedWire = new NullObject().getWireframeMesh();
      return cachedWire;
    }

    for (Charge c : charges) {
      double rad = c.w;
      Sphere s = new Sphere(rad, rad, rad);
      WireframeMesh wfm = s.getWireframeMesh();

      Vec3[] vert2 = new Vec3[vert.length + wfm.vert.length];
      int i;
      for (i = 0; i < vert.length; i++) vert2[i] = vert[i];
      for (Vec3 v : wfm.vert) vert2[i++] = v.plus(new Vec3(c.x, c.y, c.z));

      int[] from2 = new int[from.length + wfm.from.length];
      for (i = 0; i < from.length; i++) from2[i] = from[i];
      for (int foreign = 0; foreign < wfm.from.length; foreign++)
        from2[i++] = wfm.from[foreign] + vert.length;
      from = from2;

      int[] to2 = new int[to.length + wfm.to.length];
      for (i = 0; i < to.length; i++) to2[i] = to[i];
      for (int foreign = 0; foreign < wfm.to.length; foreign++)
        to2[i++] = wfm.to[foreign] + vert.length;
      to = to2;

      vert = vert2;
    }

    return (cachedWire = new WireframeMesh(vert, from, to));
  }