STK Graphics PrimitivesSend comments on this topic.
IAgStkGraphicsSurfaceMeshPrimitive Interface

Description

A triangle mesh primitive for meshes on the surface that need to conform to terrain.

Public Methods

Public Method SetDefines the surface mesh using the specified surfaceTriangulator. The mesh is rendered in the primitive's Reference Frame.
Public Method SetWithoutTexturingDefines the surface mesh using the specified surfaceTriangulator. The mesh is rendered in the primitive's Reference Frame.
Public Method SupportedDetermines whether or not the video card supports the surface mesh primitive with the given renderingMethod.
Public Method SupportedWithDefaultRenderingMethodDetermines whether or not the video card supports the surface mesh primitive. This is equivalent to calling Supported with Automatic.

Public Properties

Public Property RenderingMethodGets the rendering method used to render the mesh.
Public Property SetHintGets the primitive's Set Hint. See the Set Hint Performance Overview for selecting an appropriate value to construct the primitive with.
Public Property TextureGets or sets the texture applied to this primitive when rendering.
Public Property TextureFilterGets or sets the filter used when a Texture is applied to this primitive.
Public Property TextureMatrixGets or sets the matrix used to transform texture coordinates when a Texture is applied to this primitive.
Public Property TransparentTextureBorderGets or set the boolean that defines if the color obtained from texture coordinates beyond the texture border should be considered transparent or not. This is typically used in conjunction with the a Texture Matrix.
Public Property TriangleWindingOrderGets the orientation of front-facing triangles in the mesh.
Public Property WireframeGets or sets whether the primitive is rendered in wireframe. This is useful for debugging.

Interfaces

Implemented Interface
IAgStkGraphicsPrimitive

CoClasses that Implement IAgStkGraphicsSurfaceMeshPrimitive

Example

Draw a filled STK area target on terrain
[C#]
IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;
IAgStkGraphicsTerrainOverlay overlay = scene.CentralBodies.Earth.Terrain.AddUriString(
    terrainFile);

IAgStkGraphicsSurfaceTriangulatorResult triangles =
    manager.Initializers.SurfacePolygonTriangulator.Compute("Earth", ref positions);

IAgStkGraphicsSurfaceMeshPrimitive mesh = manager.Initializers.SurfaceMeshPrimitive.Initialize();
((IAgStkGraphicsPrimitive)mesh).Color = Color.Purple;
mesh.Set(triangles);
manager.Primitives.Add((IAgStkGraphicsPrimitive)mesh);
Draw a filled, dynamically textured extent on terrain
[C#]
IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;
IAgStkGraphicsProjectionRasterStreamPluginActivator activator =
    manager.Initializers.ProjectionRasterStreamPluginActivator.Initialize();
IAgStkGraphicsProjectionRasterStreamPluginProxy proxy =
    activator.CreateFromDisplayName("ProjectionRasterStreamPlugin.CSharp");

//
// Use reflection to set the plugin's properties
//
Type plugin = proxy.RealPluginObject.GetType();
plugin.GetProperty("RasterPath").SetValue(proxy.RealPluginObject, rasterFile, null);

IAgStkGraphicsRasterStream rasterStream = proxy.RasterStream;
rasterStream.UpdateDelta = 0.025;

IAgStkGraphicsRendererTexture2D texture = manager.Textures.FromRaster((IAgStkGraphicsRaster)rasterStream);
Array extent = ((IAgStkGraphicsGlobeOverlay)overlay).Extent;
IAgStkGraphicsSurfaceTriangulatorResult triangles = manager.Initializers.SurfaceExtentTriangulator.ComputeSimple("Earth", ref extent);
IAgStkGraphicsSurfaceMeshPrimitive mesh = manager.Initializers.SurfaceMeshPrimitive.Initialize();
((IAgStkGraphicsPrimitive)mesh).Translucency = 0.2f;
mesh.Texture = texture;
mesh.Set(triangles);
manager.Primitives.Add((IAgStkGraphicsPrimitive)mesh);
Draw a filled, textured extent on terrain
[C#]
IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;
Array overlayExtent = ((IAgStkGraphicsGlobeOverlay)overlay).Extent;
IAgStkGraphicsSurfaceTriangulatorResult triangles =
    manager.Initializers.SurfaceExtentTriangulator.ComputeSimple("Earth", ref overlayExtent);
IAgStkGraphicsRendererTexture2D texture = manager.Textures.LoadFromStringUri(
    textureFile);
IAgStkGraphicsSurfaceMeshPrimitive mesh = manager.Initializers.SurfaceMeshPrimitive.Initialize();
((IAgStkGraphicsPrimitive)mesh).Translucency = 0.3f;
mesh.Texture = texture;
mesh.Set(triangles);
manager.Primitives.Add((IAgStkGraphicsPrimitive)mesh);
Draw a moving water texture using affine transformations
[C#]
IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;
Array cartographicExtent = new object[] 
{
    -96,
    22,
    -85,
    28 
};

IAgStkGraphicsSurfaceTriangulatorResult triangles =
    manager.Initializers.SurfaceExtentTriangulator.ComputeSimple("Earth", ref cartographicExtent);

IAgStkGraphicsRendererTexture2D texture = manager.Textures.LoadFromStringUri(
    textureFile);
IAgStkGraphicsSurfaceMeshPrimitive mesh = manager.Initializers.SurfaceMeshPrimitive.Initialize();
((IAgStkGraphicsPrimitive)mesh).Translucency = 0.3f;
mesh.Texture = texture;
mesh.TextureFilter = manager.Initializers.TextureFilter2D.LinearRepeat;
mesh.Set(triangles);
manager.Primitives.Add((IAgStkGraphicsPrimitive)mesh);


internal void TimeChanged(IAgStkGraphicsScene scene, AgStkObjectRoot root, double TimeEpSec)
{
    //
    //  Translate the surface mesh every animation update
    //
    if (m_Primitive != null)
    {
        IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;

        m_Translation = (float)TimeEpSec;
        m_Translation /= 1000;

        Matrix transformation = new Matrix();
        transformation.Translate(-m_Translation, 0); // Sign determines the direction of apparent flow

        // Convert the matrix to an object array
        Array transformationArray = Array.CreateInstance(typeof(object), transformation.Elements.Length);
        for (int i = 0; i < transformationArray.Length; ++i)
        {
            transformationArray.SetValue((object)transformation.Elements.GetValue(i), i);
        }

        ((IAgStkGraphicsSurfaceMeshPrimitive)m_Primitive).TextureMatrix =
            manager.Initializers.TextureMatrix.InitializeWithAffineTransform(ref transformationArray);
    }
}
Draw a filled STK area target on the globe
[C#]
IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;
//
// Load the UAV image where each corner maps to a longitude and latitude defined 
// in degrees below.
//
//    lower left  = (-0.386182, 42.938583)
//    lower right = (-0.375100, 42.929871)
//    upper right = (-0.333891, 42.944780)
//    upper left  = (-0.359980, 42.973438)
//
IAgStkGraphicsRendererTexture2D texture = manager.Textures.LoadFromStringUri(
    textureFile);

//
// Define the bounding extent of the image.  Create a surface mesh that uses this extent.
//
IAgStkGraphicsSurfaceMeshPrimitive mesh = manager.Initializers.SurfaceMeshPrimitive.Initialize();
mesh.Texture = texture;

Array cartographicExtent = new object[] 
{
    -0.386182,
    42.929871,
    -0.333891,
    42.973438 
};

IAgStkGraphicsSurfaceTriangulatorResult triangles = manager.Initializers.SurfaceExtentTriangulator.ComputeSimple("Earth", ref cartographicExtent);
mesh.Set(triangles);
((IAgStkGraphicsPrimitive)mesh).Translucency = 0.0f;

//
// Create the texture matrix that maps the image corner points to their actual
// cartographic coordinates.  A few notes:
//
// 1. The TextureMatrix does not do any special processing on these values
//    as if they were cartographic coordinates.
//
// 2. Because of 1., the values only have to be correct relative to each
//    other, which is why they do not have to be converted to radians.
//
// 3. Because of 2., if your image straddles the +/- 180 degs longitude line, 
//    ensure that longitudes east of the line are greater than those west of
//    the line.  For example, if one point were 179.0 degs longitude and the
//    other were to the east at -179.0 degs, the one to the east should be
//    specified as 181.0 degs.
//

Array c0 = new object[] { -0.386182, 42.938583 };
Array c1 = new object[] { -0.375100, 42.929871 };
Array c2 = new object[] { -0.333891, 42.944780 };
Array c3 = new object[] { -0.359980, 42.973438 };

mesh.TextureMatrix = manager.Initializers.TextureMatrix.InitializeWithRectangles(
    ref c0, ref c1, ref c2, ref c3);
//
// Enable the transparent texture border option on the mesh so that the texture will not
// bleed outside of the trapezoid.
//
mesh.TransparentTextureBorder = true;

//
// Add the surface mesh to the Scene manager
//
manager.Primitives.Add((IAgStkGraphicsPrimitive)mesh);
Draw a filled STK area target on terrain
[Visual Basic .NET]
Dim manager As IAgStkGraphicsSceneManager = DirectCast(root.CurrentScenario, IAgScenario).SceneManager
Dim overlay As IAgStkGraphicsTerrainOverlay = scene.CentralBodies.Earth.Terrain.AddUriString( _
    terrainFile)

Dim triangles As IAgStkGraphicsSurfaceTriangulatorResult = manager.Initializers.SurfacePolygonTriangulator.Compute("Earth", positions)

Dim mesh As IAgStkGraphicsSurfaceMeshPrimitive = manager.Initializers.SurfaceMeshPrimitive.Initialize()
DirectCast(mesh, IAgStkGraphicsPrimitive).Color = Color.Purple
mesh.Set(triangles)
manager.Primitives.Add(DirectCast(mesh, IAgStkGraphicsPrimitive))
Draw a filled, dynamically textured extent on terrain
[Visual Basic .NET]
Dim manager As IAgStkGraphicsSceneManager = DirectCast(root.CurrentScenario, IAgScenario).SceneManager

Dim activator As IAgStkGraphicsProjectionRasterStreamPluginActivator = manager.Initializers.ProjectionRasterStreamPluginActivator.Initialize()
Dim proxy As IAgStkGraphicsProjectionRasterStreamPluginProxy = activator.CreateFromDisplayName("ProjectionRasterStreamPlugin.VBNET")

'
' Use reflection to set the plugin's properties
'
Dim plugin As Type = proxy.RealPluginObject.[GetType]()
plugin.GetProperty("RasterPath").SetValue(proxy.RealPluginObject, rasterFile, Nothing)

Dim rasterStream As IAgStkGraphicsRasterStream = proxy.RasterStream
rasterStream.UpdateDelta = 0.025

Dim texture As IAgStkGraphicsRendererTexture2D = manager.Textures.FromRaster(DirectCast(rasterStream, IAgStkGraphicsRaster))
Dim extent As Array = DirectCast(overlay, IAgStkGraphicsGlobeOverlay).Extent
Dim triangles As IAgStkGraphicsSurfaceTriangulatorResult = manager.Initializers.SurfaceExtentTriangulator.ComputeSimple("Earth", extent)
Dim mesh As IAgStkGraphicsSurfaceMeshPrimitive = manager.Initializers.SurfaceMeshPrimitive.Initialize()
DirectCast(mesh, IAgStkGraphicsPrimitive).Translucency = 0.2F
mesh.Texture = texture
mesh.Set(triangles)
manager.Primitives.Add(DirectCast(mesh, IAgStkGraphicsPrimitive))
Draw a filled, textured extent on terrain
[Visual Basic .NET]
Dim manager As IAgStkGraphicsSceneManager = DirectCast(root.CurrentScenario, IAgScenario).SceneManager
Dim overlayExtent As Array = DirectCast(overlay, IAgStkGraphicsGlobeOverlay).Extent
Dim triangles As IAgStkGraphicsSurfaceTriangulatorResult = manager.Initializers.SurfaceExtentTriangulator.ComputeSimple("Earth", overlayExtent)
Dim texture As IAgStkGraphicsRendererTexture2D = manager.Textures.LoadFromStringUri( _
    textureFile)
Dim mesh As IAgStkGraphicsSurfaceMeshPrimitive = manager.Initializers.SurfaceMeshPrimitive.Initialize()
DirectCast(mesh, IAgStkGraphicsPrimitive).Translucency = 0.3F
mesh.Texture = texture
mesh.Set(triangles)
manager.Primitives.Add(DirectCast(mesh, IAgStkGraphicsPrimitive))
Draw a moving water texture using affine transformations
[Visual Basic .NET]
Dim manager As IAgStkGraphicsSceneManager = DirectCast(root.CurrentScenario, IAgScenario).SceneManager
Dim cartographicExtent As Array = New Object() {-96, 22, -85, 28}

Dim triangles As IAgStkGraphicsSurfaceTriangulatorResult = manager.Initializers.SurfaceExtentTriangulator.ComputeSimple("Earth", cartographicExtent)

Dim texture As IAgStkGraphicsRendererTexture2D = manager.Textures.LoadFromStringUri( _
	textureFile)
Dim mesh As IAgStkGraphicsSurfaceMeshPrimitive = manager.Initializers.SurfaceMeshPrimitive.Initialize()
DirectCast(mesh, IAgStkGraphicsPrimitive).Translucency = 0.3F
mesh.Texture = texture
mesh.TextureFilter = manager.Initializers.TextureFilter2D.LinearRepeat
mesh.Set(triangles)
manager.Primitives.Add(DirectCast(mesh, IAgStkGraphicsPrimitive))


Friend Sub TimeChanged(scene As IAgStkGraphicsScene, root As AgStkObjectRoot, TimeEpSec As Double)
	'
	'  Translate the surface mesh every animation update
	'
	If m_Primitive IsNot Nothing Then
		Dim manager As IAgStkGraphicsSceneManager = DirectCast(root.CurrentScenario, IAgScenario).SceneManager

		m_Translation = CSng(TimeEpSec)
		m_Translation /= 1000

		Dim transformation As New Matrix()
		transformation.Translate(-m_Translation, 0)
		' Sign determines the direction of apparent flow
		' Convert the matrix to an object array
		Dim transformationArray As Array = Array.CreateInstance(GetType(Object), transformation.Elements.Length)
		For i As Integer = 0 To transformationArray.Length - 1
			transformationArray.SetValue(DirectCast(transformation.Elements.GetValue(i), Object), i)
		Next

		DirectCast(m_Primitive, IAgStkGraphicsSurfaceMeshPrimitive).TextureMatrix = manager.Initializers.TextureMatrix.InitializeWithAffineTransform(transformationArray)
	End If
End Sub
Draw a filled STK area target on the globe
[Visual Basic .NET]
Dim manager As IAgStkGraphicsSceneManager = DirectCast(root.CurrentScenario, IAgScenario).SceneManager
'
' Load the UAV image where each corner maps to a longitude and latitude defined 
' in degrees below.
'
'    lower left  = (-0.386182, 42.938583)
'    lower right = (-0.375100, 42.929871)
'    upper right = (-0.333891, 42.944780)
'    upper left  = (-0.359980, 42.973438)
'

Dim texture As IAgStkGraphicsRendererTexture2D = manager.Textures.LoadFromStringUri( _
    textureFile)

'
' Define the bounding extent of the image.  Create a surface mesh that uses this 
' extent.
'
Dim mesh As IAgStkGraphicsSurfaceMeshPrimitive = manager.Initializers.SurfaceMeshPrimitive.Initialize()
mesh.Texture = texture

Dim cartographicExtent As Array = New Object() {-0.386182, 42.929871, -0.333891, 42.973438}

Dim triangles As IAgStkGraphicsSurfaceTriangulatorResult = manager.Initializers.SurfaceExtentTriangulator.ComputeSimple("Earth", cartographicExtent)
mesh.Set(triangles)
DirectCast(mesh, IAgStkGraphicsPrimitive).Translucency = 0.0F

'
' Create the texture matrix that maps the image corner points to their actual
' cartographic coordinates.  A few notes:
'
' 1. The TextureMatrix does not do any special processing on these values
'    as if they were cartographic coordinates.
'
' 2. Because of 1., the values only have to be correct relative to each
'    other, which is why they do not have to be converted to radians.
'
' 3. Because of 2., if your image straddles the +/- 180 degs longitude line, 
'    ensure that longitudes east of the line are greater than those west of
'    the line.  For example, if one point were 179.0 degs longitude and the
'    other were to the east at -179.0 degs, the one to the east should be
'    specified as 181.0 degs.
'

Dim c0 As Array = New Object() {-0.386182, 42.938583}
Dim c1 As Array = New Object() {-0.3751, 42.929871}
Dim c2 As Array = New Object() {-0.333891, 42.94478}
Dim c3 As Array = New Object() {-0.35998, 42.973438}

mesh.TextureMatrix = manager.Initializers.TextureMatrix.InitializeWithRectangles(c0, c1, c2, c3)

'
' Enable the transparent texture border option on the mesh so that the texture will not
' bleed outside of the trapezoid.
'
mesh.TransparentTextureBorder = True

'
' Add the surface mesh to the Scene manager
'
manager.Primitives.Add(DirectCast(mesh, IAgStkGraphicsPrimitive))
Draw a new Surface Mesh
[Python - STK API]
# IAgScenario scenario: Scenario object
manager = scenario.SceneManager
cartesianPts = [[6030.721052], [1956.627139], [-692.397578], [5568.375825], [2993.600713], [-841.076362], [5680.743568], [2490.379622], [-1480.882721]]  # X, Y, Z (km)

triangles = manager.Initializers.SurfacePolygonTriangulator.Compute('Earth', cartesianPts)
surfaceMesh = manager.Initializers.SurfaceMeshPrimitive.Initialize()
surfaceMesh.Color = Colors.Red
surfaceMesh.Set(triangles)
manager.Primitives.Add(surfaceMesh)
manager.Render()

Draw a new Surface Mesh
[MATLAB]
% IAgScenario scenario: Scenario object
manager = scenario.SceneManager;
cartesianPts = {6030.721052;1956.627139;-692.397578;
    5568.375825;2993.600713;-841.076362;
    5680.743568;2490.379622;-1480.882721};  % X, Y, Z (km)

triangles = manager.Initializers.SurfacePolygonTriangulator.Compute('Earth', cartesianPts);
surfaceMesh = manager.Initializers.SurfaceMeshPrimitive.Initialize();
surfaceMesh.Color = 255;    % red
surfaceMesh.Set(triangles);
manager.Primitives.Add(surfaceMesh);
manager.Render();


        

See Also

© 2024 Analytical Graphics, Inc. All Rights Reserved.