Building objects as quad patches

Technical discussions
Post Reply
Claude
Posts: 23
Joined: Thu Jan 05, 2017 3:58 am

Building objects as quad patches

Post by Claude »

Dear Sir, Madam
My application,is written in VB.Net, VS 2013, Framework 4.0.

I downloaded your demo and had a look at the various examples in VB which in majority read a .gml file. In my application, the parts are various types of cutting tools, and several movements of the tools in animations. The coordinates of all the patches defining these volumes are calculated and thus known. There are also some 2D results.

I want to be able to programmatically define my parts by specifying to KernelCad, from within the application code, the coordinates of the patches defining the volumes of the cutting tools, the orientation of the axis of rotation of each component, and their movements when animated.

Could you identify, a sample app. written in VB with KernelCad that shows how to do this ? Seeing this would certainly help me decide whether it is worthwhile to invest the time to integrate the KernelCad module in my application.

Thanks, Claude

nickz
Site Admin
Posts: 236
Joined: Fri Jul 26, 2013 3:58 am

Re: Building objects as quad patches

Post by nickz »

Hi Claude
Welcome to DInsight. You have an interesting business.

Apart from Data Flow all samples use .glm for simplicity. Glm is an internal format. It is practically dump of the memory structures KernelCAD works with at runtime. Regarding external formats KC can read and save Step, iges, AutoCAD formats (in purchased version) and several mesh formats. Full list: http://www.dynoinsight.com/Help/Export1.aspx

You will be able to do all these tasks. Movements and animations are easy. Collision example shows it when you press the Move button. OnMove() handler in Collision.vb starts animation and OnTimer() advances position of the object using I3DObject interface. There are also IFrame* set of interfaces, which gives access to position and orientation.

When you define surface of an object its definition is relative to its own local axes (local frame). Moving an object needs only change in location and/or orientation of the local frame. Collision Path example does this on a higher level by defining the path in advance.

Objects can be arranged in a hierarchy to move together

As always, the important part is how surface of an object is defined. We have a number of types of surfaces optimised for different things. You will probably need:
1. STEP – compliant bspline objects: http://www.dynoinsight.com/Help/Geom/Ob ... jects.aspx
2. Native KernelCAD 3DS objects: http://www.dynoinsight.com/Help/3DSection.aspx. These are designed exactly for things like gear, i.e. for axially-symmetric (nearly) objects. They are defined by an axis and arc/line splines in cross-section (variable along the axis)
3. Objects with free-form mesh surface: http://www.dynoinsight.com/Help/MeshSection.aspx – useful for various auxiliary tasks

The objects and surfaces can be created or modified at runtime. Adding, deleting or changing structure of the model programmatically is easy too.

We have many customers using KC in VB .Net. V5.0 is built and tested with Visual Studio 2013.

Not all samples have a VB version, unfortunately. I think the best way to provide you a demo would be to add a VB version of a missing sample. If you think the first type would be well suited for you, the best sample would be either Modeling Curves or Shape Explorer. For the second type the Applications\Gear sample would do the best.

Best regards
Nick
DInsight

Claude
Posts: 23
Joined: Thu Jan 05, 2017 3:58 am

Re: Building objects as quad patches

Post by Claude »

Thank you for the comprehensive reply, Nick

What I mean by patches: the coordinates and encoding of every rectangular flat patch

What I need to know and see is what command(s) are used in KernelCad to programmatically pass on the coordinates, define the edges from the coordinates, define the patches from the edges, and then the complete part from the patches ?

This will tell me how intensive the implementation may prove to be.

Best regards, Claude

nickz
Site Admin
Posts: 236
Joined: Fri Jul 26, 2013 3:58 am

Re: Building objects as quad patches

Post by nickz »

Hi Claude
I see what you mean. Quads are useful when there is an obvious way to slice the object into layers
http://www.dynoinsight.com/Help/Interfa ... px#AddQuad is a simple way to build the surface with quads
Cheers
Nick

Claude
Posts: 23
Joined: Thu Jan 05, 2017 3:58 am

Re: Building objects as quad patches

Post by Claude »

Good day Nick,
Sorry for my very late reply, but things got a bit hectic. I am now looking again at KCad.

I do have several questions, as follows:

*General approach to Quad meshes.*

Basically, a model, for example the pinion or the gear, will be a bunch of
Quads. From one of your examples, I made the following summary as the
sequence to be followed to create such a mesh.
1)

Code: Select all

	' Pointer to New KCad Model (like face cutter)
	m_iModel = KernCad.GetModel()
2)

Code: Select all

	' Create "Points" by providing coordinates
	' These points are associated to a "Layer"
	' Layers can be anywhere in space and need not be
	' on the same X Y or Z level
	'
	'
	'Build external surface of a simplest prizm
	'Layer 0
	'
	m_layers(0).SetPoint(0, 0.0, 0.0, 0.0)
	m_layers(0).SetPoint(1, 1.0, 0.0, 0.0)
	m_layers(0).SetPoint(2, 0.0, 1.0, 0.0)

	'Layer 1
	'
	m_layers(1).SetPoint(0, 0.0, 0.0, 1.0)
	m_layers(1).SetPoint(1, 1.0, 0.0, 1.0)
	m_layers(1).SetPoint(2, 0.0, 1.0, 1.0)
3)

Code: Select all

	' Create "Vertex"
	' Addvertex converts a Point into a Vertex that
	' can be used to create "Quads", i.e. a Patch with
	' a Normal used for shading and hidden line removal
	'
	For Each layer As Layer In m_layers
		For Each pt As Pnt In layer.m_points
			iBuilder.AddVertex(pt.m_d(0), pt.m_d(1), pt.m_d(2))
		Next
	Next
4)

Code: Select all

	' Add the "Quads" to the model
	'
	For i = 0 To m_countLayers - 2 Step 1
		AddLayerQuads(i, iBuilder)
	Next i
5)

Code: Select all

	' Once the Model is completed, ensure that the
	' normal vectors to the Quad patches are Ok.
	'
	iMeshMods.FixupNormals(30, 0)
Could you confirm that this is the correct sequence ?

Thanks, Claude

nickz
Site Admin
Posts: 236
Joined: Fri Jul 26, 2013 3:58 am

Re: Building objects as quad patches

Post by nickz »

Hi Claude
1. Yes. m_iModel = KernCad.GetModel() is the correct way to access the model. Apart from some advanced attributes, model is a collection of objects (sections in KC-speak). It looks like in your case there will be a single object. You can retrieve it via m_iModel.GetSection(0), which returns an ISection

For an example, Line Dim iSect As ISection = iModel2.AddNewItem(EObjectType.eObjTypeMeshSection)
adds a new empty section and returns its reference in one step

The surface of a section is built as a mesh (more below). So there is a reference to it obtained via Dim iMesh As IMesh = iSect, (for an example). Mesh builder is a simplified way to build meshes without using lists

The steps 2 to 5 are correct. A few points just in case:

In 3D apps/CAD vertex is more common term than point because 3D graphics needs more information per point than the three coordinates. Normally it is normal to adjacent surface required to do proper lighting and colour or texture coordinates.

Building surfaces with quads is not always convenient (case of a single flat triangle or a tetrahedron). Triangles (simplexes) are the basic elements from which meshes (surfaces) are built. Similarly to your case quads are often useful though. That is why the mesh builder has both AddQuad() and AddSimplex()

Generally notion of mesh does not have layers. Mesh is a set of vertices and simplexes. A simplex connects three vertices. So it is absolutely generic. There are no quads in mesh itself. IMeshBuilder_KC.AddQuad() adds two simplexes instead. You define layers ourselves as part of application code for the case when it makes sense. Layers simplify construction when the surface is nearly an extrusion of something, possibly with some deformations (rotations) on the way

Kind regards
Nick

Post Reply