HOOPSVisualizeHPSAPI

%%%create_object_hierarchy

// create the Model object
// get a reference to the View
HPS.View myView = GetCanvas().GetAttachedLayout().GetAttachedView();
// attach the Model to the View
myView.AttachModel(myModel);
// you can also get a reference to the Model segment
HPS.SegmentKey myModelKey = myModel.GetSegmentKey();


%%%create_subsegments

// get a reference to the Model segment
HPS.SegmentKey myModelKey = myModel.GetSegmentKey();
// create children of the model segment
HPS.SegmentKey childSegment1 = myModelKey.Subsegment();
HPS.SegmentKey childSegment2 = myModelKey.Subsegment();
// create a grandchild segment by calling Subsegment on the child
HPS.SegmentKey grandchild = childSegment1.Subsegment();


%%%include

// get a reference to the Model segment
HPS.SegmentKey myModelKey = myModel.GetSegmentKey();
myModelKey.IncludeSegment(subassemblySegment); // first branch
myModelKey.IncludeSegment(subassemblySegment); // second branch


%%%segment_operations

// move a segment to a new parent
someSegment.MoveTo(newParentSegment);
// copy a segment to another parent
someSegment.CopyTo(anotherSegment);
// delete a segment
childSegment.Delete();


%%%insert_shell

HPS.Point[] myPointArray = { new HPS.Point(0, 0, 0), new HPS.Point(0, 1, 0), new HPS.Point(1, 1, 0) };
int[] myFaceList = { 3, 0, 1, 2 };
HPS.SegmentKey shellSegment = myModel.GetSegmentKey().Subsegment();
shellSegment.InsertShell(myPointArray, myFaceList);


%%%%2d_geometry

HPS.SegmentKey circleSegment = myModel.GetSegmentKey().Subsegment();
circleSegment.InsertCircle(new HPS.Point(2, 0.5f, 0), 0.5f, new HPS.Vector(0, 0, 1));
HPS.SegmentKey lineSegment = myModel.GetSegmentKey().Subsegment();
lineSegment.InsertLine(new HPS.Point(3, 0.5f, 0), new HPS.Point(4, 0.5f, 0));
lineSegment.GetVisibilityControl().SetLines(true);


%%%primitives

HPS.SegmentKey cylinderSegment = myModel.GetSegmentKey().Subsegment();
cylinderSegment.InsertCylinder(new HPS.Point(5, 0, 0.5f), new HPS.Point(5.3f, 1, 0), 0.5f);


%%%setting_attributes

myModel.GetSegmentKey().GetMaterialMappingControl().SetEdgeColor(new HPS.RGBAColor(1, 0, 0));
cylinderSegment.GetVisibilityControl().SetFaces(false);


%%%visibility

myModel.GetSegmentKey().GetVisibilityControl().SetEdges(true);


%%%line_settings

// change face color of shell to blue
shellSegment.GetMaterialMappingControl().SetFaceColor(new HPS.RGBAColor(0, 1, 0));
// increase edge weight of circle
circleSegment.GetEdgeAttributeControl().SetWeight(3.0f);
// change the solid line to a dashed line
lineSegment.GetPortfolioControl().Push(myPortfolio);
myPortfolio.DefineLinePattern("dashed_pattern", myLinePatternKitpk);
lineSegment.GetLineAttributeControl().SetPattern("dashed_pattern");


%%%circle_segment

circleSegment.MoveTo(shellSegment);


%%%file_import

HPS.Stream.ImportNotifier notifier = null;
HPS.Stream.ImportOptionsKit in_options = new HPS.Stream.ImportOptionsKit();
in_options.SetSegment(GetModel().GetSegmentKey());
// empty this segment
GetModel().GetSegmentKey().Flush();
try
{
notifier = HPS.Stream.File.Import(path_to_file, in_options);
notifier.Wait();
}
{
// handle error
}
GetView().FitWorld();
GetView().Update();


%%%set_rendering_mode

HPS.Rendering.Mode render_mode = GetView().GetRenderingMode();
if (render_mode == HPS.Rendering.Mode.HiddenLine)
GetView().SetRenderingMode(HPS.Rendering.Mode.Default);
else
GetView().SetRenderingMode(HPS.Rendering.Mode.HiddenLine);
GetView().Update();


%%%shadows

GetView().SetRenderingMode(HPS.Rendering.Mode.GouraudWithLines);
bool state, ignore_transparency;
uint resolution, blurring;
GetView().GetSegmentKey().GetVisualEffectsControl().ShowSimpleShadow(out state, out resolution, out blurring, out ignore_transparency);
if (state == true) // toggle the effect
vxfkit.SetShadowMaps(false).SetSimpleShadow(false);
else
vxfkit.SetShadowMaps(false).SetSimpleShadow(true).SetSimpleShadowPlane(new HPS.Plane(0, 1, 0, 0.005f));
GetView().GetSegmentKey().SetVisualEffects(vxfkit);
GetView().Update();


%%%loading_shell

HPS.Model model = HPS.Factory.CreateModel(); // creating the Model
GetView().AttachModel(model); // attaching it to the view
HPS.Stream.ImportNotifier notifier = new HPS.Stream.ImportNotifier();
try
{
HPS.Stream.ImportOptionsKit importOptionsKit = new HPS.Stream.ImportOptionsKit();
importOptionsKit.SetSegment(model.GetSegmentKey()); // model from file is imported into our model segment
notifier = HPS.Stream.File.Import(path_to_file, importOptionsKit);
notifier.Wait(); // pauses this thread until the file is finished loading
}
{
// handle exception
}
canvas.GetFrontView().FitWorld().Update();


%%%set_color

mySegmentKey.GetMaterialMappingControl()
.SetFaceColor(new HPS.RGBAColor(1.0f, 0.0f, 0.0f, 0.5f))
.SetEdgeColor(new HPS.RGBAColor(0, 0, 0));
mySegmentKey.GetVisibilityControl().SetEdges(true);


%%%set_face_texture

mySegmentKey.GetMaterialMappingControl()
.SetFaceTexture("woodDiffuse",
HPS.Material.Texture.Channel.DiffuseTexture);


%%%face_level_texturing

// building the array of six materials
HPS.MaterialKit[] materialKitArray = new HPS.MaterialKit[] { new HPS.MaterialKit(), new HPS.MaterialKit(),
new HPS.MaterialKit(), new HPS.MaterialKit(),
new HPS.MaterialKit(), new HPS.MaterialKit() };
materialKitArray[0].SetDiffuseTexture("woodDiffuse"); // sets a texture on the material
// ... set other materials
HPS.MaterialPaletteDefinition mpd = myPortfolio.DefineMaterialPalette
("myPalette", materialKitArray); // defines a palette using the materials
// the palette is made active on the segment
model.GetSegmentKey().SetMaterialPalette("myPalette");


%%%set_face_colors

ulong[] faceIndices = { 0, 1, 2, 3, 4, 5 };
float[] materialIndices = { 0, 1, 2, 3, 4, 5 };
myShellKey.SetFaceIndexColorsByList(faceIndices, 0);


%%%search

HPS.SearchResults searchResults;
ulong numResults = model.GetSegmentKey().Find(HPS.Search.Type.Shell, // searching for circles
HPS.Search.Space.SegmentOnly, // within all subsegments
out searchResults); // search results returned here
HPS.SearchResultsIterator it = searchResults.GetIterator();
while (it.IsValid())
{
HPS.Key key = it.GetItem();
if (key.Type() == HPS.Type.ShellKey)
{
myShellKey = new HPS.ShellKey(key);
}
it.Next();
}


%%%set_diffuse_color

materialKitArray[1].SetDiffuse(new HPS.RGBAColor(1.0f, 0.0f, 0.0f, 0.5f));


%%%set_bump

model.GetSegmentKey().InsertDistantLight(new HPS.Vector(1, 1, 1));
materialKitArray[2].SetDiffuseTexture("my_texture");
materialKitArray[2].SetBump("my_heightmap");


%%%multitexturing

textureOptionsKit.SetModulation(true);
materialKitArray[3].SetDiffuseTexture("brickDiffuse", 0);
materialKitArray[3].SetDiffuseTexture("grassDiffuse", 1);


%%%mmk

HPS.MaterialMappingKit myMaterialMappingKit = new HPS.MaterialMappingKit();
myMaterialMappingKit.SetFaceColor(new HPS.RGBAColor(0, 0, 1));
myShellKit.SetMaterialMapping(myMaterialMappingKit);


%%%import_notifier

HPS.Stream.ImportNotifier notifier = new HPS.Stream.ImportNotifier(); ;
try
{
HPS.Stream.ImportOptionsKit importOptionsKit = new HPS.Stream.ImportOptionsKit();
importOptionsKit.SetSegment(mySegmentKey);
notifier = HPS.Stream.File.Import(filename, importOptionsKit);
// pauses this thread until the HSF is finished loading
notifier.Wait();
}
{
// handle exception
}


%%%get_model_key

HPS.SegmentKey modelSegmentKey = GetTopView().GetAttachedModel().GetSegmentKey();


%%%reflection

modelSegmentKey.GetVisualEffectsControl().SetSimpleReflection(true, 0.5f, 1U, false, 0, 2.0f);
// parameters for equation of a plane
modelSegmentKey.GetVisualEffectsControl().SetSimpleReflectionPlane(new HPS.Plane(0, 1, 0, 0.375f));


%%%set_shadows

modelSegmentKey.GetVisibilityControl().SetShadows(true);
modelSegmentKey.GetVisualEffectsControl().SetShadowMaps(true, 16, 2048, true, true);


%%%shadow_attributes

modelSegmentKey.GetVisualEffectsControl().SetSimpleShadow(true); // enables simple shadows
modelSegmentKey.GetVisualEffectsControl().SetSimpleShadowPlane(new HPS.Plane(0, 1, 0, 0.425f)); // sets the plane where the shadows are projected
modelSegmentKey.GetVisualEffectsControl().SetSimpleShadowColor(new RGBAColor(0.2f, 0.2f, 0.2f)); // color of the shadow
modelSegmentKey.GetVisualEffectsControl().SetSimpleShadowLightDirection(new Vector(0, 1, 0)); // light direction


%%%ppe

ppek.SetBloom(true, 10.0f); // enables bloom. strength can be set from 0 to 10
myWindowKey.SetPostProcessEffects(ppek);
ppek.SetBloom(false); // disables bloom


%%%create_style

mySegmentKey.GetPortfolioControl().Push(myPortfolio);
NamedStyleDefinition myHighlightStyle = myPortfolio.DefineNamedStyle("myStyle", HPS.Database.CreateRootSegment());
myHighlightStyle.GetSource().GetMaterialMappingControl().SetFaceColor(new HPS.RGBAColor(1.0f, 1.0f, 0.0f));
myHighlightStyle.GetSource().GetMaterialMappingControl().SetEdgeColor(new HPS.RGBAColor(1.0f, 0.0f, 0.0f));
myHighlightStyle.GetSource().GetVisibilityControl().SetFaces(true).SetEdges(true);
mySegmentKey.GetStyleControl().PushNamed("myStyle");


%%%attach_operator

// Get a reference to your View object. In this case I'm using the View from the mfc_sandbox application.
HPS.View myView = GetCanvas().GetAttachedLayout().GetAttachedView();
HPS.HighlightOperator myHighlightOperator = new HPS.HighlightOperator();
// operator becomes 'active' after pushing it onto the operator stack
myView.GetOperatorControl().Push(myHighlightOperator);
// set the highlight style, which we previously defined
HPS.HighlightOptionsKit hok = new HPS.HighlightOptionsKit("myHighlightStyle");
myHighlightOperator.SetHighlightOptions(hok);


%%%processing_selection

HPS.SelectionResults selectionResults = myHighlightOperator.GetActiveSelection();
HPS.SelectionResultsIterator it = selectionResults.GetIterator();
while (it.IsValid())
{
HPS.SelectionItem selectionItem = it.GetItem();
HPS.Key key;
if (selectionItem.ShowSelectedItem(out key))
{
if (key.Type() == HPS.Type.ShellKey)
{
HPS.ShellKey shellKey = new HPS.ShellKey(key);
// do something with this object
}
}
it.Next();
}


%%%basic_setup

myWindowKey.GetMaterialMappingControl().SetWindowColor(new RGBAColor(1, 1, 1)).SetWindowContrastColor(new RGBAColor(1, 1, 1))
.SetFaceColor(new RGBAColor(1, 0.75f, 0)).SetEdgeColor(new RGBAColor(0.2f, 0.2f, 0.2f)).SetLineColor(new RGBAColor(0.2f, 0.2f, 0.2f));
myWindowKey.GetVisibilityControl().SetLeaderLines(true).SetEdges(true);
myWindowKey.GetTextAttributeControl().SetBackground(true).SetSize(24, Text.SizeUnits.Points)
.SetAlignment(Text.Alignment.Center, Text.ReferenceFrame.WorldAligned, Text.Justification.Center);
myWindowKey.GetDrawingAttributeControl().SetWorldHandedness(Drawing.Handedness.Left);
myWindowKey.GetMaterialMappingControl().SetWindowColor(new RGBAColor(1.0f, 1.0f, 1.0f));
myWindowKey.GetCameraControl().SetPosition(new HPS.Point(8, -4, 10));
myWindowKey.GetCameraControl().SetProjection(HPS.Camera.Projection.Perspective);
// add a portfolio to the window
myWindowKey.GetPortfolioControl().Push(portfolio);


%%%insert_cube

// this is the cube that our leader line will be pointing to
HPS.SegmentKey cubeSegmentKey = myWindowKey.Subsegment();
cubeSegmentKey.GetMaterialMappingControl().SetFaceColor(new RGBAColor(0.4f, 0.68f, 0.96f));
cubeSegmentKey.GetPortfolioControl().Push(portfolio);
cubeSegmentKey.GetVisibilityControl().SetEdges(true);
// insert the cube at [0,1,0]
HPS.ShellKey myShellKey = InsertCube(cubeSegmentKey, new HPS.Point(0, 1, 0), 1.0f);


%%%create_textbox

// create a segment for the rectangle where the text will be placed
HPS.SegmentKey rectangleSegmentKey = myWindowKey.Subsegment();
// define the vertices of the textbox rectangle
HPS.ShapePoint leftBottom = new HPS.ShapePoint(-1, -1);
HPS.ShapePoint leftTop = new HPS.ShapePoint(-1, 1);
HPS.ShapePoint rightBottom = new HPS.ShapePoint(1, -1);
HPS.ShapePoint rightTop = new HPS.ShapePoint(1, 1);
HPS.ShapePoint [] textBoxRectanglePoints = { leftBottom, rightBottom, rightTop, leftTop };
// use a PolygonShapeElement to contain our textbox rectangle
HPS.PolygonShapeElement rectangleBackgroundShape = new HPS.PolygonShapeElement(textBoxRectanglePoints);


%%%create_line_anchor

// set the anchor at the top right vertex of our textbox rectangle
HPS.AnchorShapeElement lineAnchor = new HPS.AnchorShapeElement(rightTop);
// define the intermediate point where the leader line will bend
HPS.ShapeCoordinate intermediatePoint_1 = new HPS.ShapeCoordinate(1.5f, 2.5f);
HPS.ShapePoint[] intermediatePoints = { new HPS.ShapePoint(intermediatePoint_1.x, intermediatePoint_1.y) };
// and set the intermediate point
lineAnchor.SetIntermediatePoints(intermediatePoints);


%%%create_shapekit

// add our textbox background and line anchors to a ShapeKit
HPS.ShapeKit rectangle_shape = new HPS.ShapeKit();
HPS.ShapeElement [] rectangle_elements = { rectangleBackgroundShape, lineAnchor };
rectangle_shape.SetElements(rectangle_elements);
// define the rectangle_shape in our portfolio and add to the rectangle segment
portfolio.DefineShape("anchored_leader_line_rectangle", rectangle_shape);
rectangleSegmentKey.GetTextAttributeControl().SetBackground("anchored_leader_line_rectangle");
// create a TextKey and insert the text into it
HPS.TextKey rectangle_text = rectangleSegmentKey.InsertText(
new HPS.Point(2, -2, 0), "Vertex is 0.5, 0.5, -0.5\nin world space.");
rectangle_text.SetColor(
new RGBAColor(0.1f, 0.1f, 0.1f)).SetFont("stroked").SetBold(true).SetSize(26, HPS.Text.SizeUnits.Points);
// put an outline around the text box
rectangleSegmentKey.GetEdgeAttributeControl().SetWeight(2, HPS.Edge.SizeUnits.Pixels);
// define where the leader line will point, just a little bit offset from the cube vertex of 0.5, 0.5, -0.5
HPS.Point leader_line_position = new HPS.Point(0.47f, 0.5f, -0.57f) ;
rectangle_text.SetLeaderLine(leader_line_position);


%%%line_pattern

// create the line
HPS.SolidLinePatternElement slpe = new SolidLinePatternElement();
slpe.SetColor(new RGBAColor(0.2f, 0.2f, 0.2f));
HPS.LinePatternParallelKit lppk = new LinePatternParallelKit();
lppk.SetBody(slpe);


%%%add_arrowhead

// define the glyph for the leader line arrow as a triangle
// give it a little offset so it doesn't overlap with the cube
HPS.GlyphKit glyphKit = new HPS.GlyphKit();
glyphKit = HPS.GlyphKit.GetDefault(HPS.Glyph.Default.SolidTriangleRight).SetOffset(new HPS.GlyphPoint(127, 0));
portfolio.DefineGlyph("anchored_leader_line_triangle", glyphKit);
// create a glyph line pattern element
// use SetSize function to control size of glyph
glyph_pattern.SetSize(15, HPS.LinePattern.SizeUnits.Pixels);
glyph_pattern.SetSource("anchored_leader_line_triangle");
glyph_pattern.SetInsetBehavior(HPS.LinePattern.InsetBehavior.Trim);
// set glyph as the endcap of the line, and define the weight of the line
lppk.SetEndCap(glyph_pattern);
lppk.SetWeight(1, HPS.LinePattern.SizeUnits.Pixels);


%%%wrap_up

// create a line pattern kit, define it in the portfolio, and set in the rectangle segment
lpk.SetParallel(lppk);
portfolio.DefineLinePattern("myLinePattern", lpk);
rectangleSegmentKey.GetLineAttributeControl().SetPattern("myLinePattern");
rectangleSegmentKey.GetVisibilityControl().SetLines(true); // ensure lines visible


%%%full_program

myWindowKey.GetMaterialMappingControl().SetWindowColor(new RGBAColor(1, 1, 1)).SetWindowContrastColor(new RGBAColor(1, 1, 1))
.SetFaceColor(new RGBAColor(1, 0.75f, 0)).SetEdgeColor(new RGBAColor(0.2f, 0.2f, 0.2f)).SetLineColor(new RGBAColor(0.2f, 0.2f, 0.2f));
myWindowKey.GetVisibilityControl().SetLeaderLines(true).SetEdges(true);
myWindowKey.GetTextAttributeControl().SetBackground(true).SetSize(24, Text.SizeUnits.Points)
.SetAlignment(Text.Alignment.Center, Text.ReferenceFrame.WorldAligned, Text.Justification.Center);
myWindowKey.GetDrawingAttributeControl().SetWorldHandedness(Drawing.Handedness.Left);
myWindowKey.GetMaterialMappingControl().SetWindowColor(new RGBAColor(1.0f, 1.0f, 1.0f));
myWindowKey.GetCameraControl().SetPosition(new HPS.Point(8, -4, 10));
myWindowKey.GetCameraControl().SetProjection(HPS.Camera.Projection.Perspective);
// add a portfolio to the window
myWindowKey.GetPortfolioControl().Push(portfolio);
// this is the cube that our leader line will be pointing to
HPS.SegmentKey cubeSegmentKey = myWindowKey.Subsegment();
cubeSegmentKey.GetMaterialMappingControl().SetFaceColor(new RGBAColor(0.4f, 0.68f, 0.96f));
cubeSegmentKey.GetPortfolioControl().Push(portfolio);
cubeSegmentKey.GetVisibilityControl().SetEdges(true);
// insert the cube at [0,1,0]
HPS.ShellKey myShellKey = InsertCube(cubeSegmentKey, new HPS.Point(0, 1, 0), 1.0f);
// create a segment for the rectangle where the text will be placed
HPS.SegmentKey rectangleSegmentKey = myWindowKey.Subsegment();
// define the vertices of the textbox rectangle
HPS.ShapePoint leftBottom = new HPS.ShapePoint(-1, -1);
HPS.ShapePoint leftTop = new HPS.ShapePoint(-1, 1);
HPS.ShapePoint rightBottom = new HPS.ShapePoint(1, -1);
HPS.ShapePoint rightTop = new HPS.ShapePoint(1, 1);
HPS.ShapePoint [] textBoxRectanglePoints = { leftBottom, rightBottom, rightTop, leftTop };
// use a PolygonShapeElement to contain our textbox rectangle
HPS.PolygonShapeElement rectangleBackgroundShape = new HPS.PolygonShapeElement(textBoxRectanglePoints);
// set the anchor at the top right vertex of our textbox rectangle
HPS.AnchorShapeElement lineAnchor = new HPS.AnchorShapeElement(rightTop);
// define the intermediate point where the leader line will bend
HPS.ShapeCoordinate intermediatePoint_1 = new HPS.ShapeCoordinate(1.5f, 2.5f);
HPS.ShapePoint[] intermediatePoints = { new HPS.ShapePoint(intermediatePoint_1.x, intermediatePoint_1.y) };
// and set the intermediate point
lineAnchor.SetIntermediatePoints(intermediatePoints);
// add our textbox background and line anchors to a ShapeKit
HPS.ShapeKit rectangle_shape = new HPS.ShapeKit();
HPS.ShapeElement [] rectangle_elements = { rectangleBackgroundShape, lineAnchor };
rectangle_shape.SetElements(rectangle_elements);
// define the rectangle_shape in our portfolio and add to the rectangle segment
portfolio.DefineShape("anchored_leader_line_rectangle", rectangle_shape);
rectangleSegmentKey.GetTextAttributeControl().SetBackground("anchored_leader_line_rectangle");
// create a TextKey and insert the text into it
HPS.TextKey rectangle_text = rectangleSegmentKey.InsertText(
new HPS.Point(2, -2, 0), "Vertex is 0.5, 0.5, -0.5\nin world space.");
rectangle_text.SetColor(
new RGBAColor(0.1f, 0.1f, 0.1f)).SetFont("stroked").SetBold(true).SetSize(26, HPS.Text.SizeUnits.Points);
// put an outline around the text box
rectangleSegmentKey.GetEdgeAttributeControl().SetWeight(2, HPS.Edge.SizeUnits.Pixels);
// define where the leader line will point, just a little bit offset from the cube vertex of 0.5, 0.5, -0.5
HPS.Point leader_line_position = new HPS.Point(0.47f, 0.5f, -0.57f) ;
rectangle_text.SetLeaderLine(leader_line_position);
// create the line
HPS.SolidLinePatternElement slpe = new SolidLinePatternElement();
slpe.SetColor(new RGBAColor(0.2f, 0.2f, 0.2f));
HPS.LinePatternParallelKit lppk = new LinePatternParallelKit();
lppk.SetBody(slpe);
// define the glyph for the leader line arrow as a triangle
// give it a little offset so it doesn't overlap with the cube
HPS.GlyphKit glyphKit = new HPS.GlyphKit();
glyphKit = HPS.GlyphKit.GetDefault(HPS.Glyph.Default.SolidTriangleRight).SetOffset(new HPS.GlyphPoint(127, 0));
portfolio.DefineGlyph("anchored_leader_line_triangle", glyphKit);
// create a glyph line pattern element
// use SetSize function to control size of glyph
glyph_pattern.SetSize(15, HPS.LinePattern.SizeUnits.Pixels);
glyph_pattern.SetSource("anchored_leader_line_triangle");
glyph_pattern.SetInsetBehavior(HPS.LinePattern.InsetBehavior.Trim);
// set glyph as the endcap of the line, and define the weight of the line
lppk.SetEndCap(glyph_pattern);
lppk.SetWeight(1, HPS.LinePattern.SizeUnits.Pixels);
// create a line pattern kit, define it in the portfolio, and set in the rectangle segment
lpk.SetParallel(lppk);
portfolio.DefineLinePattern("myLinePattern", lpk);
rectangleSegmentKey.GetLineAttributeControl().SetPattern("myLinePattern");
rectangleSegmentKey.GetVisibilityControl().SetLines(true); // ensure lines visible


%%%cube_program

protected ShellKey InsertCube(SegmentKey segmentKey, Point center, float size)
{
float halflength = size / 2;
Point[] pointArray = { new Point(-halflength + center.x, -halflength + center.y, halflength + center.z),
new Point(halflength + center.x, -halflength + center.y, halflength + center.z),
new Point(halflength + center.x, halflength + center.y, halflength + center.z),
new Point(-halflength + center.x, halflength + center.y, halflength + center.z),
new Point(-halflength + center.x, -halflength + center.y, -halflength + center.z),
new Point(halflength + center.x, -halflength + center.y, -halflength + center.z),
new Point(halflength + center.x, halflength + center.y, -halflength + center.z),
new Point(-halflength + center.x, halflength + center.y, -halflength + center.z)
};
int[] faceList = { 4, 0, 1, 2, 3, 4, 1, 5, 6, 2, 4, 5, 6, 7, 4, 4, 4, 7, 3, 0, 4, 3, 2, 6, 7, 4, 0, 4, 5, 1 };
return segmentKey.InsertShell(pointArray, faceList);
}


%%%import_file

HPS.Model myModel = Factory.CreateModel();
SegmentKey modelSegment = myModel.GetSegmentKey();
// Modify this path to point to your model file.
string filename = "C:\\myData\\bnc.hsf";
HPS.Stream.ImportNotifier importNotifier = new Stream.ImportNotifier();
try
{
HPS.Stream.ImportOptionsKit myImportOptionsKit = new Stream.ImportOptionsKit();
myImportOptionsKit.SetSegment(modelSegment); // set destination segment
importNotifier = HPS.Stream.File.Import(filename, myImportOptionsKit);
// Pauses this thread until the HSF is finished loading.
importNotifier.Wait();
}
catch (HPS.IOException)
{
// handle exception
}


%%%update_info_sample

WindowInfoControl windowInfo = window.GetWindowInfoControl();
UpdateInfo updateInfo = new HPS.UpdateInfo();
int static_models_created = 0;
if (windowInfo.ShowLastUpdateInfo(out updateInfo))
{
// This should be 1.
static_models_created = (int)updateInfo.statics_created_count;
}


%%%set_static_model

// Attach the model to the front View of the Canvas.
_canvas.GetFrontView().AttachModel(myModel);
modelSegment.GetPerformanceControl().SetStaticModel(Performance.StaticModel.Attribute);
// An Exhaustive update after an initial file load will build a static model.
window.UpdateWithNotifier(Window.UpdateType.Exhaustive).Wait();


%%%update_info_sample

WindowInfoControl windowInfo = window.GetWindowInfoControl();
UpdateInfo updateInfo = new HPS.UpdateInfo();
int static_models_created = 0;
if (windowInfo.ShowLastUpdateInfo(out updateInfo))
{
// This should be 1.
static_models_created = (int)updateInfo.statics_created_count;
}


%%%static_model_change

// Changing the modelling matrix will invalidate the current static model.
_canvas.GetFrontView().GetAttachedModel().GetSegmentKey().GetModellingMatrixControl().Scale(2.0f, 2.0f, 2.0f);


%%%set_resource_monitor

window.GetDebuggingControl().SetResourceMonitor(true);


%%%first_update

window.UpdateWithNotifier(Window.UpdateType.Default).Wait();
if (windowInfo.ShowLastUpdateInfo(out updateInfo))
// This should still be 0.
static_models_created = (int)updateInfo.statics_created_count;


%%%second_update

window.UpdateWithNotifier(Window.UpdateType.Default).Wait();
if (windowInfo.ShowLastUpdateInfo(out updateInfo))
// This should now be 1.
static_models_created = (int)updateInfo.statics_created_count;


%%%full_program_static_model_tutorial

HPS.Model myModel = Factory.CreateModel();
SegmentKey modelSegment = myModel.GetSegmentKey();
// Modify this path to point to your model file.
string filename = "C:\\myData\\bnc.hsf";
HPS.Stream.ImportNotifier importNotifier = new Stream.ImportNotifier();
try
{
HPS.Stream.ImportOptionsKit myImportOptionsKit = new Stream.ImportOptionsKit();
myImportOptionsKit.SetSegment(modelSegment); // set destination segment
importNotifier = HPS.Stream.File.Import(filename, myImportOptionsKit);
// Pauses this thread until the HSF is finished loading.
importNotifier.Wait();
}
catch (HPS.IOException)
{
// handle exception
}
// Attach the model to the front View of the Canvas.
_canvas.GetFrontView().AttachModel(myModel);
modelSegment.GetPerformanceControl().SetStaticModel(Performance.StaticModel.Attribute);
// An Exhaustive update after an initial file load will build a static model.
window.UpdateWithNotifier(Window.UpdateType.Exhaustive).Wait();
WindowInfoControl windowInfo = window.GetWindowInfoControl();
UpdateInfo updateInfo = new HPS.UpdateInfo();
int static_models_created = 0;
if (windowInfo.ShowLastUpdateInfo(out updateInfo))
{
// This should be 1.
static_models_created = (int)updateInfo.statics_created_count;
}
// Changing the modelling matrix will invalidate the current static model.
_canvas.GetFrontView().GetAttachedModel().GetSegmentKey().GetModellingMatrixControl().Scale(2.0f, 2.0f, 2.0f);
window.GetDebuggingControl().SetResourceMonitor(true);
window.UpdateWithNotifier(Window.UpdateType.Default).Wait();
if (windowInfo.ShowLastUpdateInfo(out updateInfo))
// This should still be 0.
static_models_created = (int)updateInfo.statics_created_count;
window.UpdateWithNotifier(Window.UpdateType.Default).Wait();
if (windowInfo.ShowLastUpdateInfo(out updateInfo))
// This should now be 1.
static_models_created = (int)updateInfo.statics_created_count;


%%%%00700_skybox

View myView = HPS.Factory.CreateView();
myCanvas.AttachViewAsLayout(myView);
// import the images
ImageKit frontImg = HPS.Image.File.Import(image_path_positive_z, iok);
ImageKit leftImg = HPS.Image.File.Import(image_path_negative_x, iok);
ImageKit rightImg = HPS.Image.File.Import(image_path_positive_x, iok);
ImageKit backImg = HPS.Image.File.Import(image_path_negative_z, iok);
ImageKit bottomImg = HPS.Image.File.Import(image_path_negative_y, iok);
ImageKit topImg = HPS.Image.File.Import(image_path_positive_y, iok);
// Set up the Images in a portfolio
HPS.PortfolioKey myPortfolioKey = myCanvas.GetPortfolioKey();
HPS.ImageDefinition frontDef = myPortfolioKey.DefineImage("frontDef", frontImg);
HPS.ImageDefinition leftDef = myPortfolioKey.DefineImage("leftDef", leftImg);
HPS.ImageDefinition rightDef = myPortfolioKey.DefineImage("rightDef", rightImg);
HPS.ImageDefinition backDef = myPortfolioKey.DefineImage("backDef", backImg);
HPS.ImageDefinition topDef = myPortfolioKey.DefineImage("topDef", topImg);
HPS.ImageDefinition botDef = myPortfolioKey.DefineImage("botDef", bottomImg);
// Define the Cubemap texture
HPS.CubeMapDefinition skybox = myPortfolioKey.DefineCubeMap("skybox", backDef, frontDef, leftDef, rightDef, botDef, topDef);
myView.GetSegmentKey().GetSubwindowControl().SetBackground(Subwindow.Background.Cubemap, "skybox"); // Set the skybox texture
// As a convenience, display the NavCube in the scene
myView.GetNavigationCubeControl().SetVisibility(true).SetInteractivity(true);
// For demonstration purposes, create a new cube to go in the center of the screen
HPS.SegmentKey cubeSegmentKey = myView.GetSegmentKey().Subsegment();
cubeSegmentKey.GetMaterialMappingControl().SetFaceColor(new RGBAColor(0.4f, 0.4f, 0.4f, 0.6f));
cubeSegmentKey.GetVisibilityControl().SetEdges(false);
HPS.ShellKey myShellKey = InsertCube(cubeSegmentKey, new HPS.Point(0, 0, 0), 0.5f);
SmoothTransHandler myHandler = new SmoothTransHandler(); // Instantiate a custom event handler
HPS.EventDispatcher dispatcher = HPS.Database.GetEventDispatcher(); // Get an event dispatcher
dispatcher.Subscribe(myHandler, HPS.Object.ClassID<SmoothTransitionCompleteEvent>());
// Get the window key and set up the camera
myView.Update();
camkit.Orbit(180, 0);
camkit.Zoom(0.2f);
camkit.SetField(16,12); // Adjust field of view according to desired resolution
myView.SmoothTransition(camkit, 2);
while (!myHandler.transitionComplete)
{
; // Wait for the first 180 rotation to complete
}
camkit.Orbit(180, 0);
myHandler.transitionComplete = false;
myView.SmoothTransition(camkit, 2);
while (!myHandler.transitionComplete)
{
; // Wait for the next 180 rotation to complete
}


%%%%00700_skybox_import_images

// import the images
ImageKit frontImg = HPS.Image.File.Import(image_path_positive_z, iok);
ImageKit leftImg = HPS.Image.File.Import(image_path_negative_x, iok);
ImageKit rightImg = HPS.Image.File.Import(image_path_positive_x, iok);
ImageKit backImg = HPS.Image.File.Import(image_path_negative_z, iok);
ImageKit bottomImg = HPS.Image.File.Import(image_path_negative_y, iok);
ImageKit topImg = HPS.Image.File.Import(image_path_positive_y, iok);


%%%%00700_skybox_smooth_transition_handler

class SmoothTransHandler : HPS.EventHandler
{
public volatile bool transitionComplete = false;
~SmoothTransHandler() { Shutdown(); } // Destructor
public override HandleResult Handle(Event in_event)
{
transitionComplete = true; // Update the member variable
return HandleResult.Handled;
}
};


%%%%00700_skybox_cube_program

protected ShellKey InsertCube(SegmentKey segmentKey, Point center, float size)
{
float halflength = size / 2;
Point[] pointArray = { new Point(-halflength + center.x, -halflength + center.y, halflength + center.z),
new Point(halflength + center.x, -halflength + center.y, halflength + center.z),
new Point(halflength + center.x, halflength + center.y, halflength + center.z),
new Point(-halflength + center.x, halflength + center.y, halflength + center.z),
new Point(-halflength + center.x, -halflength + center.y, -halflength + center.z),
new Point(halflength + center.x, -halflength + center.y, -halflength + center.z),
new Point(halflength + center.x, halflength + center.y, -halflength + center.z),
new Point(-halflength + center.x, halflength + center.y, -halflength + center.z)
};
int[] faceList = { 4, 0, 1, 2, 3, 4, 1, 5, 6, 2, 4, 5, 6, 7, 4, 4, 4, 7, 3, 0, 4, 3, 2, 6, 7, 4, 0, 4, 5, 1 };
return segmentKey.InsertShell(pointArray, faceList);
}


%%%%00700_skybox_portfolio

// Set up the Images in a portfolio
HPS.PortfolioKey myPortfolioKey = myCanvas.GetPortfolioKey();
HPS.ImageDefinition frontDef = myPortfolioKey.DefineImage("frontDef", frontImg);
HPS.ImageDefinition leftDef = myPortfolioKey.DefineImage("leftDef", leftImg);
HPS.ImageDefinition rightDef = myPortfolioKey.DefineImage("rightDef", rightImg);
HPS.ImageDefinition backDef = myPortfolioKey.DefineImage("backDef", backImg);
HPS.ImageDefinition topDef = myPortfolioKey.DefineImage("topDef", topImg);
HPS.ImageDefinition botDef = myPortfolioKey.DefineImage("botDef", bottomImg);
// Define the Cubemap texture
HPS.CubeMapDefinition skybox = myPortfolioKey.DefineCubeMap("skybox", backDef, frontDef, leftDef, rightDef, botDef, topDef);
myView.GetSegmentKey().GetSubwindowControl().SetBackground(Subwindow.Background.Cubemap, "skybox"); // Set the skybox texture


%%%%00700_skybox_animation

// As a convenience, display the NavCube in the scene
myView.GetNavigationCubeControl().SetVisibility(true).SetInteractivity(true);
// For demonstration purposes, create a new cube to go in the center of the screen
HPS.SegmentKey cubeSegmentKey = myView.GetSegmentKey().Subsegment();
cubeSegmentKey.GetMaterialMappingControl().SetFaceColor(new RGBAColor(0.4f, 0.4f, 0.4f, 0.6f));
cubeSegmentKey.GetVisibilityControl().SetEdges(false);
HPS.ShellKey myShellKey = InsertCube(cubeSegmentKey, new HPS.Point(0, 0, 0), 0.5f);
SmoothTransHandler myHandler = new SmoothTransHandler(); // Instantiate a custom event handler
HPS.EventDispatcher dispatcher = HPS.Database.GetEventDispatcher(); // Get an event dispatcher
dispatcher.Subscribe(myHandler, HPS.Object.ClassID<SmoothTransitionCompleteEvent>());
// Get the window key and set up the camera
myView.Update();
camkit.Orbit(180, 0);
camkit.Zoom(0.2f);
camkit.SetField(16,12); // Adjust field of view according to desired resolution
myView.SmoothTransition(camkit, 2);
while (!myHandler.transitionComplete)
{
; // Wait for the first 180 rotation to complete
}
camkit.Orbit(180, 0);
myHandler.transitionComplete = false;
myView.SmoothTransition(camkit, 2);
while (!myHandler.transitionComplete)
{
; // Wait for the next 180 rotation to complete
}