Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
DynamoSamples/src/SampleLibraryZeroTouch/Examples/ColorExample.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
84 lines (71 sloc)
3.1 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Autodesk.DesignScript.Interfaces; | |
using Autodesk.DesignScript.Runtime; | |
namespace Examples | |
{ | |
public class CustomRenderExample : IGraphicItem | |
{ | |
private CustomRenderExample(){} | |
/// <summary> | |
/// Create an object which renders custom geometry. | |
/// </summary> | |
public static CustomRenderExample Create() | |
{ | |
return new CustomRenderExample(); | |
} | |
[IsVisibleInDynamoLibrary(false)] | |
public void Tessellate(IRenderPackage package, TessellationParameters parameters) | |
{ | |
// Dynamo's renderer uses IRenderPackage objects | |
// to store data for rendering. The Tessellate method | |
// give you an IRenderPackage object which you can fill | |
// with render data. | |
// Set RequiresPerVertexColoration to let the renderer | |
// know that you needs to use a per-vertex color shader. | |
package.RequiresPerVertexColoration = true; | |
AddColoredQuadToPackage(package); | |
AddColoredLineToPackage(package); | |
} | |
private static void AddColoredQuadToPackage(IRenderPackage package) | |
{ | |
// Triangle 1 | |
package.AddTriangleVertex(0, 0, 0); | |
package.AddTriangleVertex(1, 0, 0); | |
package.AddTriangleVertex(1, 1, 0); | |
// For each vertex, add a color. | |
package.AddTriangleVertexColor(255, 0, 0, 255); | |
package.AddTriangleVertexColor(0, 255, 0, 255); | |
package.AddTriangleVertexColor(0, 0, 255, 255); | |
//Triangle 2 | |
package.AddTriangleVertex(0, 0, 0); | |
package.AddTriangleVertex(1, 1, 0); | |
package.AddTriangleVertex(0, 1, 0); | |
package.AddTriangleVertexColor(255, 0, 0, 255); | |
package.AddTriangleVertexColor(0, 255, 0, 255); | |
package.AddTriangleVertexColor(0, 0, 255, 255); | |
package.AddTriangleVertexNormal(0, 0, 1); | |
package.AddTriangleVertexNormal(0, 0, 1); | |
package.AddTriangleVertexNormal(0, 0, 1); | |
package.AddTriangleVertexNormal(0, 0, 1); | |
package.AddTriangleVertexNormal(0, 0, 1); | |
package.AddTriangleVertexNormal(0, 0, 1); | |
package.AddTriangleVertexUV(0, 0); | |
package.AddTriangleVertexUV(0, 0); | |
package.AddTriangleVertexUV(0, 0); | |
package.AddTriangleVertexUV(0, 0); | |
package.AddTriangleVertexUV(0, 0); | |
package.AddTriangleVertexUV(0, 0); | |
} | |
private static void AddColoredLineToPackage(IRenderPackage package) | |
{ | |
package.AddLineStripVertex(0,0,0); | |
package.AddLineStripVertex(5,5,5); | |
package.AddLineStripVertexColor(255,0,0,255); | |
package.AddLineStripVertexColor(255,0,0,255); | |
// Specify line segments by adding a line vertex count. | |
// Ex. The above line has two vertices, so we add a line | |
// vertex count of 2. If we had tessellated a curve with n | |
// vertices, we would add a line vertex count of n. | |
package.AddLineStripVertexCount(2); | |
} | |
} | |
} |