Exemplo 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));
        }
      }
    }
  }
Exemplo n.º 2
0
  public static void writeScene(
      Scene theScene, m2 out, boolean wholeScene, double tol, boolean smooth, boolean inject) {
    // Write the objects in the scene.

    int numVert = 0, numNorm = 0, numTexVert = 0;
    Hashtable<String, String> groupNames = new Hashtable<String, String>();
    NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
    nf.setMaximumFractionDigits(5);
    nf.setGroupingUsed(false);
    for (int i = 0; i < theScene.getNumObjects(); i++) {
      // Get a rendering mesh for the object.

      ObjectInfo info = theScene.getObject(i);
      if (!wholeScene && !info.selected) continue;
      if (info.getObject().getTexture() == null) continue;
      FacetedMesh mesh;

      if (!smooth && info.getObject() instanceof FacetedMesh) mesh = (FacetedMesh) info.getObject();
      else mesh = info.getObject().convertToTriangleMesh(tol);
      if (mesh == null) continue;

      // Find the normals.

      Vec3 norm[];
      int normIndex[][] = new int[mesh.getFaceCount()][];
      if (mesh instanceof TriangleMesh) {
        RenderingMesh rm = ((TriangleMesh) mesh).getRenderingMesh(Double.MAX_VALUE, false, info);
        norm = rm.norm;
        for (int j = 0; j < normIndex.length; j++)
          normIndex[j] = new int[] {rm.triangle[j].n1, rm.triangle[j].n2, rm.triangle[j].n3};
      } else {
        norm = mesh.getNormals();
        for (int j = 0; j < normIndex.length; j++) {
          normIndex[j] = new int[mesh.getFaceVertexCount(j)];
          for (int k = 0; k < normIndex[j].length; k++)
            normIndex[j][k] = mesh.getFaceVertexIndex(j, k);
        }
      }
      // Write out the object.

      Mat4 trans = info.getCoords().fromLocal();
      MeshVertex vert[] = mesh.getVertices();

      System.out.println("nVertixes:\t" + out.vertex.length);
      for (int j = 0; j < vert.length; j++) {
        Vec3 v = trans.times(vert[j].r);
        float[] tf = new float[3];
        tf[0] = (float) v.x;
        tf[1] = (float) v.y;
        tf[2] = (float) v.z;
        out.vertex[j].setVertexPos(tf);
      }
      /*short faceCount[][]=new short[mesh.getFaceCount()][3];
      for(int f=0;f<mesh.getFaceCount();f++){
       faceCount[f][0]=(short) mesh.getFaceVertexIndex(f, 0);
       faceCount[f][1]=(short) mesh.getFaceVertexIndex(f, 1);
       faceCount[f][2]=(short) mesh.getFaceVertexIndex(f, 2);
      }
      System.out.println("Old nTriangles:\t"+out.movi.nTriangles);
      out.movi.setnewSize(faceCount.length, inject);
      out.movi.render();
      System.out.println("New nTriangles:\t"+out.movi.nTriangles);
      for (int j = 0; j < faceCount.length; j++)
        {
          out.movi.setnewIndex(j, faceCount[j]);

        }

      if(useuv==true){
      UVMapping uvmap=(UVMapping) info.getObject().getTextureMapping();
      Vec2 uv[]=uvmap.findTextureCoordinates(mesh);
      out.motv.setnewSize(out.movt.nVertices, inject);
      for(int n=0;n<out.movt.nVertices;n++){
       if(n<=uv.length){
       float[] txcoord={(float) uv[n].x,(float) uv[n].y};
       out.motv.setnewTexVertex(n, txcoord);}
       else{
        float[] txcoord={0.0f,0.0f};
        out.motv.setnewTexVertex(n, txcoord);
       }
      }}
      if(inject==false){
      out.moba.setnewSize(1, false);
      out.movt.render();
      out.movi.render();
      out.moba.entrys[0]=new MOBA_Entry((short)0,(short)out.movt.nVertices,0,out.movi.nTriangles);
      out.mobn.setnewSize(1, false);
      out.mobn.entrys[0]=new MOBN_Entry(out.movi.nTriangles, 1);
      }*/
      /* out.monr.setnewSize(norm.length);
      out.monr.render();
      for (int j = 0; j < norm.length; j++)
        {
       float[] tf = new float[3];
          if (norm[j] == null){
        	  tf[0]=1f;tf[1]=0f;tf[2]=0f;
        	  out.monr.setNormalPos(j, tf);}
          else
            {
              Vec3 v = trans.timesDirection(norm[j]);
              tf[0]=(float) v.x;tf[1]=(float) v.y;tf[2]=(float)v.z;
              out.monr.setnewNormalPos(j, tf);
            }
        }*/

      numVert += vert.length;
      numNorm += norm.length;
    }
    save(out);
  }