internal Material(SU.MaterialRef suMaterialRef) { // Get the name. SU.StringRef suStringRef = new SU.StringRef(); SU.StringCreate(suStringRef); SU.MaterialGetNameLegacyBehavior(suMaterialRef, suStringRef); Name = Convert.ToStringAndRelease(suStringRef); // Get the types. SU.MaterialGetType(suMaterialRef, out suMaterialType); SU.MaterialGetColorizeType(suMaterialRef, out suMaterialColorizeType); // Get the color and/or texture. SU.Color suColor; SU.TextureRef suTextureRef; switch (suMaterialType) { case SU.MaterialType_Colored: SU.MaterialGetColor(suMaterialRef, out suColor); Color = new Color(suColor); break; case SU.MaterialType_Textured: suTextureRef = new SU.TextureRef(); SU.MaterialGetTexture(suMaterialRef, suTextureRef); Texture = new Texture(suTextureRef); break; case SU.MaterialType_ColorizedTexture: SU.MaterialGetColor(suMaterialRef, out suColor); Color = new Color(suColor); suTextureRef = new SU.TextureRef(); SU.MaterialGetTexture(suMaterialRef, suTextureRef); Texture = new Texture(suTextureRef); break; default: throw new Exception($"Unknown material type = {suMaterialType}"); } }
internal Face(SU.FaceRef suFaceRef) { // Get its UVHelper for texture-mapping coordinates. UVHelper uvh = new UVHelper(suFaceRef); // Get the outer loop. EdgePointList edgePointList = new EdgePointList(suFaceRef); uvh.Assign(edgePointList); outerLoop = new Loop(edgePointList).edgePoints; // Get any inner loops. SU.FaceGetNumInnerLoops(suFaceRef, out long count); SU.LoopRef[] loopRefs = new SU.LoopRef[count]; long len = count; SU.FaceGetInnerLoops(suFaceRef, len, loopRefs, out count); foreach (SU.LoopRef loopRef in loopRefs) { innerLoops.Add( new Loop(new EdgePointList(loopRef)).edgePoints); } SU.MaterialRef suMaterialRef = new SU.MaterialRef(); try { SU.FaceGetFrontMaterial(suFaceRef, suMaterialRef); SU.StringRef suStringRef = new SU.StringRef(); SU.StringCreate(suStringRef); SU.MaterialGetNameLegacyBehavior(suMaterialRef, suStringRef); MaterialName = Convert.ToStringAndRelease(suStringRef); } catch (SketchUpException e) { if (e.ErrorCode == SU.ErrorNoData) { // Not an error. It just has no material. } else { throw; } } }
void UnpackMaterials(SU.ModelRef modelRef) { SU.ModelGetNumMaterials(modelRef, out long count); SU.MaterialRef[] materialRefs = new SU.MaterialRef[count]; long len = count; SU.ModelGetMaterials(modelRef, len, materialRefs, out count); foreach (SU.MaterialRef materialRef in materialRefs) { Material material = new Material(materialRef); materials.Add(material.Name, material); } }
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"); }
internal void Pack(SU.ModelRef suModelRef) { suMaterialRef = new SU.MaterialRef(); SU.MaterialCreate(suMaterialRef); SU.MaterialSetName(suMaterialRef, Name); switch (suMaterialType) { case SU.MaterialType_Colored: SU.MaterialSetColor(suMaterialRef, Color.SUColor); break; case SU.MaterialType_Textured: Texture.Pack(); SU.MaterialSetTexture(suMaterialRef, Texture.textureRef); break; case SU.MaterialType_ColorizedTexture: SU.MaterialSetColor(suMaterialRef, Color.SUColor); SU.MaterialSetColorizeType(suMaterialRef, suMaterialColorizeType); Texture.Pack(); SU.MaterialSetTexture(suMaterialRef, Texture.textureRef); break; default: throw new Exception($"Unknown material type = {suMaterialType}"); } SU.MaterialRef[] suMaterialRefs = new SU.MaterialRef[1]; suMaterialRefs[0] = suMaterialRef; SU.ModelAddMaterials(suModelRef, 1, suMaterialRefs); }
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"); }
internal Group( SU.GroupRef groupRef) { // Get the transform. SU.Transformation transformation = new SU.Transformation(); SU.GroupGetTransform(groupRef, out transformation); Transform = new Transform(transformation); // Get the name. SU.StringRef stringRef = new SU.StringRef(); SU.StringCreate(stringRef); SU.GroupGetName(groupRef, stringRef); Name = Convert.ToStringAndRelease(stringRef); // Note that a Group can upcast into a DrawingElement. // As such, it can have an instance-wide Material set for it that // SketchUp will use on any Faces that use the defalt Material. // But you cannot set the Group's material; you must // upcast first. // Upcast to a DrawingElement and get the material name. SU.DrawingElementRef drawingElementRef = SU.GroupToDrawingElement(groupRef); SU.MaterialRef materialRef = new SU.MaterialRef(); try { SU.DrawingElementGetMaterial(drawingElementRef, materialRef); stringRef = new SU.StringRef(); SU.StringCreate(stringRef); SU.MaterialGetNameLegacyBehavior(materialRef, stringRef); MaterialName = Convert.ToStringAndRelease(stringRef); } catch (SketchUpException e) { if (e.ErrorCode == SU.ErrorNoData) { // Not an error. It just has no material. } else { throw; } } // Get the entities. SU.EntitiesRef entitiesRef = new SU.EntitiesRef(); SU.GroupGetEntities(groupRef, entitiesRef); UnpackEntities(entitiesRef); }
internal CompInst(SU.ComponentInstanceRef instanceRef) { // Get the transform. SU.Transformation transformation = new SU.Transformation(); SU.ComponentInstanceGetTransform(instanceRef, out transformation); Transform = new Transform(transformation); // Get the instance name. SU.StringRef stringRef = new SU.StringRef(); SU.StringCreate(stringRef); SU.ComponentInstanceGetName(instanceRef, stringRef); InstanceName = Convert.ToStringAndRelease(stringRef); // Get the definition name. SU.ComponentDefinitionRef componentDefinitionRef = new SU.ComponentDefinitionRef(); SU.ComponentInstanceGetDefinition(instanceRef, componentDefinitionRef); stringRef = new SU.StringRef(); SU.StringCreate(stringRef); SU.ComponentDefinitionGetName(componentDefinitionRef, stringRef); ComponentName = Convert.ToStringAndRelease(stringRef); // Note that a ComponentInstance can upcast into a DrawingElement. // As such, it can have an instance-wide Material set for it that // SketchUp will use on any Faces that use the defalt Material. // But you cannot set the ComponentInstance's material; you must // upcast first. // Upcast to a DrawingElement and get the material name. SU.DrawingElementRef drawingElementRef = SU.ComponentInstanceToDrawingElement(instanceRef); SU.MaterialRef materialRef = new SU.MaterialRef(); try { SU.DrawingElementGetMaterial(drawingElementRef, materialRef); stringRef = new SU.StringRef(); SU.StringCreate(stringRef); SU.MaterialGetNameLegacyBehavior(materialRef, stringRef); MaterialName = Convert.ToStringAndRelease(stringRef); } catch (SketchUpException e) { if (e.ErrorCode == SU.ErrorNoData) { // Not an error. It just has no material. } else { throw; } } }