public override void Run(string path) { SU.EntitiesRef entities = SUHelper.Initialize(); SU.GeometryInputRef geometry = new SU.GeometryInputRef(); SU.GeometryInputCreate(geometry); foreach (SU.Point3D p in points) { SU.Point3D pc = p; pc.x *= SU.MetersToInches; pc.y *= SU.MetersToInches; pc.z *= SU.MetersToInches; SU.GeometryInputAddVertex(geometry, pc); } SU.LoopInputRef loop = new SU.LoopInputRef(); SU.LoopInputCreate(loop); SU.LoopInputAddVertexIndex(loop, 0); SU.LoopInputAddVertexIndex(loop, 1); SU.LoopInputAddVertexIndex(loop, 2); SU.LoopInputAddVertexIndex(loop, 3); long faceIndex; SU.GeometryInputAddFace(geometry, loop, out faceIndex); SU.MaterialRef material = new SU.MaterialRef(); SU.MaterialCreate(material); SU.MaterialSetName(material, "Pure Red"); SU.MaterialSetColor(material, new SU.Color { red = 0xFF, alpha = 0xFF }); SU.MaterialInput materialInput = new SU.MaterialInput(); materialInput.materialRef = material; SU.GeometryInputFaceSetFrontMaterial(geometry, 0, materialInput); SU.EntitiesFill(entities, geometry, true); SUHelper.Finalize(path + @"\RedQuad.skp"); }
public override void Run(string path) { SU.EntitiesRef entities = SUHelper.Initialize(); SU.GeometryInputRef geometry = new SU.GeometryInputRef(); SU.GeometryInputCreate(geometry); foreach (SU.Point3D p in points) { SU.Point3D pc = p; pc.x *= SU.MetersToInches; pc.y *= SU.MetersToInches; pc.z *= SU.MetersToInches; SU.GeometryInputAddVertex(geometry, pc); } SU.LoopInputRef loop = new SU.LoopInputRef(); SU.LoopInputCreate(loop); SU.LoopInputAddVertexIndex(loop, 0); SU.LoopInputAddVertexIndex(loop, 1); SU.LoopInputAddVertexIndex(loop, 2); SU.LoopInputAddVertexIndex(loop, 3); long faceIndex; SU.GeometryInputAddFace(geometry, loop, out faceIndex); SU.MaterialRef material = new SU.MaterialRef(); SU.MaterialCreate(material); SU.MaterialSetName(material, "Placeholder"); SU.TextureRef texture = new SU.TextureRef(); SU.TextureCreateFromFile( texture, "PlaceHolderRGBY.png", SU.MetersToInches, SU.MetersToInches); SU.MaterialSetTexture(material, texture); SU.MaterialInput materialInput = new SU.MaterialInput(); materialInput.materialRef = material; materialInput.numUVCoords = 4; materialInput.materialRef = material; materialInput.SetUVCoords( new SU.Point2D(0, 0), new SU.Point2D(1, 0), new SU.Point2D(1, .5), new SU.Point2D(0, .5)); materialInput.SetVertexIndices(0, 1, 2, 3); SU.GeometryInputFaceSetFrontMaterial(geometry, faceIndex, materialInput); loop = new SU.LoopInputRef(); SU.LoopInputCreate(loop); SU.LoopInputAddVertexIndex(loop, 3); SU.LoopInputAddVertexIndex(loop, 2); SU.LoopInputAddVertexIndex(loop, 4); SU.LoopInputAddVertexIndex(loop, 5); SU.GeometryInputAddFace(geometry, loop, out faceIndex); materialInput = new SU.MaterialInput(); materialInput.materialRef = material; materialInput.numUVCoords = 4; materialInput.materialRef = material; materialInput.SetUVCoords( new SU.Point2D(0, .5), new SU.Point2D(1, .5), new SU.Point2D(1, 1), new SU.Point2D(0, 1)); materialInput.SetVertexIndices(3, 2, 4, 5); SU.GeometryInputFaceSetFrontMaterial(geometry, faceIndex, materialInput); SU.EntitiesFill(entities, geometry, true); SUHelper.Finalize(path + @"\TwoQuadsSeamslessTexture.skp"); }
void Pack( Model model, SU.GeometryInputRef geometryInputRef, ref int vertexIndex) { const int maxUVcoords = 4; SU.LoopInputRef loopInputRef = new SU.LoopInputRef(); SU.LoopInputCreate(loopInputRef); Point2[] uvCoords = new Point2[maxUVcoords]; int[] indices = new int[maxUVcoords]; int numUVcoords = 0; // There are other ways to count foreach iterations, // but this is so simple. int edgeIndex = 0; foreach (EdgePoint edgePoint in outerLoop) { SU.GeometryInputAddVertex(geometryInputRef, edgePoint.Vertex.SUPoint3D); SU.LoopInputAddVertexIndex(loopInputRef, vertexIndex); if (edgePoint.IsSmooth) { SU.LoopInputEdgeSetSmooth(loopInputRef, edgeIndex, true); SU.LoopInputEdgeSetSoft(loopInputRef, edgeIndex, true); } if (edgePoint.UVCoords != null && numUVcoords < maxUVcoords) { uvCoords[numUVcoords] = edgePoint.UVCoords; indices[numUVcoords] = vertexIndex; numUVcoords = numUVcoords + 1; } vertexIndex = vertexIndex + 1; edgeIndex = edgeIndex + 1; } long faceIndex; try { SU.GeometryInputAddFace(geometryInputRef, loopInputRef, out faceIndex); } catch { // Success would have deallocated this for us. SU.LoopInputRelease(loopInputRef); throw; } foreach (Loop loop in innerLoops) { loopInputRef = new SU.LoopInputRef(); SU.LoopInputCreate(loopInputRef); foreach (EdgePoint edgePoint in loop.edgePoints) { SU.GeometryInputAddVertex(geometryInputRef, edgePoint.Vertex.SUPoint3D); SU.LoopInputAddVertexIndex(loopInputRef, vertexIndex); vertexIndex = vertexIndex + 1; } try { SU.GeometryInputFaceAddInnerLoop( geometryInputRef, faceIndex, loopInputRef); } catch { // Success would have deallocated this for us. SU.LoopInputRelease(loopInputRef); throw; } } if (MaterialName != null) { Material material = null; try { material = model.materials[MaterialName]; } catch (Exception e) { string msg = "\nCould not find a material named " + MaterialName; throw new Exception(e.Message + msg); } SU.MaterialInput materialInput = new SU.MaterialInput { numUVCoords = numUVcoords }; for (int i = 0; i < numUVcoords; ++i) { materialInput.UVCoords[i].x = uvCoords[i].X; materialInput.UVCoords[i].y = uvCoords[i].Y; materialInput.vertexIndices[i] = indices[i]; } materialInput.materialRef = material.suMaterialRef; SU.GeometryInputFaceSetFrontMaterial( geometryInputRef, faceIndex, materialInput); } }