Exemplo n.º 1
0
 public VInfoReference[] InterpolateVInfos(Vec3 targetPosition)
 {
     VInfoReference[] vinfo = new VInfoReference[3];
     Vec2 ij = Util.VectorToTriangleCoords(new Vec3[] { verts[0].position.xyz, verts[1].position.xyz, verts[2].position.xyz }, targetPosition);
     double[] weights = new double[] { 1.0 - (ij.x + ij.y), ij.x, ij.y };
     vinfo[0] = new VInfoReference { objID = objID, index = verts[0].vinfo[0].index, weight = weights[0]};
     vinfo[1] = new VInfoReference { objID = objID, index = verts[1].vinfo[0].index, weight = weights[1] };
     vinfo[2] = new VInfoReference { objID = objID, index = verts[2].vinfo[0].index, weight = weights[2] };
     return vinfo;
 }
Exemplo n.º 2
0
 // Function that transforms stuff and does interpolation for vertices that were created in the middles of faces
 // TODO: replace with a generic user-vertex-info function
 public static BasicModelVert WorkingVertexToBMV(Vec3 position, VInfoReference[] vinfos, BasicModelData input_model, Mat4 input_xform, WorkingModel working_model)
 {
     Vec3 normal = Vec3.Zero;
     Vec2 uv = Vec2.Zero;
     foreach (VInfoReference vinfo in vinfos)
     {
         int index = vinfo.index;
         if (index != -1)
         {
             int tri = index / 3;
             int vert = index % 3;
             double weight = vinfo.weight;
             int normal_index = (int)(vert == 0 ? input_model.a_norm[tri] : vert == 1 ? input_model.b_norm[tri] : input_model.c_norm[tri]);
             normal += weight * input_xform.TransformVec3(new Vec3 { x = input_model.nx[normal_index], y = input_model.ny[normal_index], z = input_model.nz[normal_index] }, 0.0);
             int uv_index = (int)(vert == 0 ? input_model.a_uv[tri] : vert == 1 ? input_model.b_uv[tri] : input_model.c_uv[tri]);
             uv += weight * new Vec2 { x = input_model.u[uv_index], y = input_model.v[uv_index] };
         }
     }
     return new BasicModelVert { position = position, normal = Vec3.Normalize(normal), uv = uv };
 }