Faceting Using Scheme


When using Scheme to exercise faceting, much of the preparatory work is taken care of. The user must create entities, then refinements, and then attach these refinements to the entities. Finally, the entities are faceted and the facets displayed.

Faceting an Entity in Scheme

entity:facet generates facets for an entity or list of entities. The argument entity-list specifies the facets of an entity or list of entities to save. The facets produced become part of the part. When facets are saved with the part, refinements cannot be modified unless the entity:delete-facets extension is applied. New refinement modifications must then be faceted with the entity to be saved with that entity. The optional argument view specifies which view to facet the entities, and it is usually used when view-dependent refinements have been set; the default is the active view. When the optional argument unfaceted_only is set to #t, only unfaceted geometry is faceted. This extension returns the input entity list.

entity:display-facets displays the facets of an entity or list of entities. The optional argument view specifies the view to display the entity; the default is the active view. This extension returns the number of facets displayed from the input entity-list.

The entity:count-facets extension counts the number of facets in an entity. This procedure does not facet the entities. The user must call entity:facet to facet them or nothing prints.

entity:delete-facets deletes the facets from an entity or list of entities. The argument entity-list specifies the facets of an entity or list of entities to delete. This extension returns the input entity-list.

The entity:refinement extension returns the entitys refinement. If no refinement is assigned, this extension returns #f. The entity:refinement gets all the faceting refinements attached to an ENTITY. The optional argument view is used as the base view to determine the orientation of the printed display. It defaults to the active view.

The entity:set-facet-color extension sets the color information to each facet vertex based on the input vector. The newly created VERTEX_TEMPLATE class sets up storage for the tokens used for position, normal, color, and uv. When the model is subsequently faceted, the polygons vertices contain data for each of these tokens.

entity:print-facets prints the facets of an entity or list of entities. If no entities are specified, then all entities that are both displayed and faceted are printed. This procedure does not facet the entities. The user must call entity:facet to facet them or nothing prints.

entity:write-facets writes the facets to a file. The argument entity-list specifies the entity or list of entities to include facet information. The argument file-name specifies the name of the file to create. This extension returns #t if the operation is successful.

Scheme Example

; entity:display-facets
; Create and facet a block, then display the facets.
(define ablock
    (solid:block (position 0 0 0)
    (position 25 25 25)))
;; ablock
; Facet the solid block.
(entity:facet ablock)
;; 12
; Display the facets of the solid block.
(entity:display-facets ablock)
;; ()
; Count the number of facets in the block.
(entity:count-facets ablock)
;; 12
(entity:delete-facets ablock)
;; #[entity 2 1]

Faceting Refinements in Scheme

The two Scheme extensions, entity:set-refinement and refinement, are used in conjunction with each other. The refinement extension is used to create a new refinement for faceting. A refinement is an entity created in the active part that controls how closely the surfaces of entities are approximated by their faceted representation. A refinement is associated with a face, shell, lump, or solid body. The entity:set-refinement is used to attached a refinement to an entity or a group of entities.

refinement:set-prop sets a property of a refinement to control faceting.

"surface tolerance"
is the maximum distance between facet and true surface. Setting it to 0 turns it off.
"normal tolerance"
is the maximum difference between any two normals of facet.
"aspect ratio"
is the approximate aspect ratio of each cell in grid.
"max edge length"
is the maximum size of an edge of a facet.
"max grid lines"
is the maximum number of grid lines on a face in U or V direction.
"min u_ grid lines"
is the minimum number of u grid lines used to facet a face.
"min v_ grid lines"
is the minimum number of v grid lines used to display a face.
"grading"
adjusts facets to get better parametric aspect ratio of a grid cell.
"grid mode"
specifies whether a grid is used and whether the points where the grid cuts the edge is inserted to the edge.
"triang mode"
specifies how much triangulation to do.
"adjust mode"
specifies type of triangle smoothing to do. Determines if facet nodes should be adjusted for smoothing. Also determines if the grid points should be adjusted or not.
"surf mode"
specifies the type of surface.

Scheme Example

; refinement:set-prop
; Create a new refinement.
(define my_refine (refinement))
;; my_refine
; Set a property of the refinement.
(refinement:set-prop my_refine
    surface tolerance 0.2)
;; ()
; Determine the properties of a refinement.
(refinement:props my_refine)
;; ((surface tolerance . 0.2)
;; (normal tolerance . 15)
;; (aspect ratio . 0)
;; (max edge length . 0)
;; (max grid lines . 512)
;; (grading . #f)
;; (grid mode . AF_GRID_INTERIOR)
;; (triang mode . AF_TRIANG_FRINGE_2)
;; (adjust mode . AF_ADJUST_NONE)
;; (surf mode . AF_SURF_ALL))
; Set the default property of the refinement.
(refinement:set-default my_refine)
;; ()
; entity:set-refinement
; Create a solid cylinder.
(define my_cyl
    (solid:cylinder (position 0 0 0)
    (position 8 8 0) 20))
;; my_cyl
; my_cyl => #[entity 2 1]
; Create a refinement.
(define my_refine (refinement))
;; my_refine
; my_refine => #[entity 3 1]
; Get the default refinement values.
(refinement:props my_refine)
;; ((surface tolerance . 0)
;; (normal tolerance . 15)
;; (aspect ratio . 0) (max edge length . 0)
;; (max grid lines . 513) (grading . #f)
;; (grid mode . AF_GRID_INTERIOR)
;; (triang mode . AF_TRIANG_FRINGE_2)
;; (adjust mode . AF_ADJUST_NON_GRID)
;; (surf mode . AF_SURF_ALL))
; Set the properties of the refinement.
(refinement:set-prop my_refine
    normal tolerance 20)
;; ()
; Set the refinement on the cylinder.
(entity:set-refinement my_cyl my_refine)
;; #[entity 2 1]
; Remove the refinement from the cylinder.
(entity:set-refinement my_cyl #f)
;; #[entity 2 1]

Faceting Scheme Summary

entity:count-facets
Counts the number of facets in an entity.
entity:delete-facets
Deletes the facets from an entity or list of entities. Use #t after specifying an entity to delete facets from descendents.
entity:display-facets
Displays the facets of an entity or list of entities in immediate mode only if the entity is faceted.
entity:facet
Facets an entity or list of entities.
entity:faceted?
Determines if an entity is faceted.
entity:print-facets
Prints the facets of an entity or list of entities.
entity:refinement
Gets an entitys refinement.
entity:refinements
Gets all the refinements attached to an ENTITY.
entity:set-refinement
Attaches a refinement to an entity or list of entities.
entity:write-facets
Writes facets to a file in the indexed mesh format.
refinement
Creates a refinement.
refinement?
Determines if a Scheme object is a refinement.
refinement:default
Gets the default refinement.
refinement:props
Gets the current property list of a refinement.
refinement:set-default
Sets the default refinement to the specified refinement.
refinement:set-prop
Sets a property of a refinement.

Related topics:

Refinements
Mesh Managers
The Faceting Algorithm
Step-by-Step Faceting
Discarding or Keeping Facet Data
Faceting Functions and Classes

[Top]