Index
The HT for 3D Web provides hexahedral, shape3d, etc., a variety of conventional 3D models, such as predefined spheres, cylinders, etc., ht.Shape type can achieve 3D model effects of wall, pipe and polygon, etc., this manual will introduce more flexible 3D model function to meet the modeling requirements of different industry equipment and different environment scenes.
The custom 3D model has the following advantages:
3D model of any shape and style3D model data with type datasBlender, 3ds Max and Maya and other third-party modeling tools, see OBJ ManualThis manual describes some of the extended model library functions provided by the ht-modeling.js modeling extension package.
The 3D model is synthesized by the most basic triangular plane stitching, for example, 1 rectangle can be composed of 2 triangles, 1 cubes consist of 6, 12 triangles, and so on, more complex models can be synthesized by many small triangular combinations. So the 3D model is defined as the description of all triangles of the constructed model, and each triangle consists of three vertices Vertex, each vertex vertex determined by x, y, z three dimensional coordinates that HT uses the right-hand rule to determine the front of the three-vertex tectonic triangular surface.
The simplest 3D model description is described by a top-point group, such as p1-p2-p3, which is a three-point triangle that can be described as an array of [p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, p3.x, p3.y, p3.z], more triangles are shown in the following illustration:
The above description format is simple and easy to understand, but more data to repeat, for example, the vertices 1, 2 and 3 are described in the triangle definitions of T1, T2 and T3 respectively, so the vertices and triangles can be separated in a way that describes the vertices with two arrays, an array describes vertex vertices, abbreviated as vs in HT, the other array describes the triangle corresponding vertex index indices, abbreviated as is in HT. The index described in the previous illustration is as follows:
From the geometric model angle above the definition is enough to build a complete 3D model, generally the interface renders also need to define the color or the tile determines the rendering effect, the use of tile rendering method needs to define its corresponding tiling location information, refer to UV Mapping hexahedral chapters, referred to briefly as uv in HT. This parameter is not defined if the model is rendered only with normal colors.
The effect of the 3D scene model also depends on the angle between the normal vector and the light of each triangle surface. Normal vector normal in the model of HT is represented by the abbreviation ns, generally HT can automatically calculate ns information according to the vertex, but some models to achieve special rendering effect, each vertex can pass ns specifies the corresponding normal vector value, which is understood by reference to Phong Shading.
The following definition models are used for reference in the xzy axis size of the 1 range, [0, 0, 0] corresponds to the central position of the data, if the xzy axis has an absolute value of more than 0.5, it means that it exceeds the size defined by the data size3d.
Through ht.Default.setShape3dModel(name, model) function, can register custom 3D model:
name The model name, and if the name is the same as the predefined, the predefined model is replaced.model The JSON type object, and its specific attribute parameters are defined as follows, where the bottom_*, top_*, from_* and to_* respectively correspond to shape3d.bottom.*, shape3d.top.*, shape3d.from.* and shape3d.to.* control parameters. For example, the 3D model can define the top_* model information, but whether the top plane display is controlled by the shape3d.top.visible parameter, and the top plane color is controlled by the shape3d.top.color parameter, whether the top plane is tiled is controlled by shape3d.top.image parameter, if the model does not define top_* information, then the shape3d.top.* parameter is meaningless.
vs: Vertex coordinates array is: Vertex index arrayuv: Vertex map coordinates array ns: Vertex normal vector array bottom_vs: Bottom vertex coordinate array bottom_is: Bottom vertex indices arraybottom_uv: Bottom vertex tile coordinate array bottom_ns: Bottom vertex normal vector arraytop_vs: Top vertex coordinate array top_is: Top vertex indices arraytop_uv: Top vertex tile coordinate array top_ns: Bottom vertex normal vector arrayfrom_vs: From vertex coordinate array from_is: From vertex indices arrayfrom_uv: From vertex tile coordinate array from_ns: From vertex normal vector arrayto_vs: To vertex coordinate array to_is: To vertex indices arrayto_uv: To vertex tile coordinate array to_ns: To vertex normal vector arrayTo sum up, the process of customizing the model is:
3D model JSON data structure information objectJSON model object into the system, ht.Default.setShape3dModel('dragon', dragonModel)node.setStyle('shape3d', 'dragon')Similar to 2D pictures do not require global registration, you can directly set the content of the data properties node.setImage('www.google.com/logo.png'), 3D also supports this simplified approach, to build 3D JSON model object is set to the data attribute: node.setStyle('shape3d', dragonModel), but this approach is detrimental to the DataModel serialization data export, which results in the same model's data repeating output 3D model information, and the 3D model information data volume is very large in general, do not recommend the DataModel of the overall model information together, we generally see 3D model information and picture information as peripheral resource information, proposed DataModel data model information separately storage management.
The custom 3D model is very flexible, but for complex models, hand-written vertex workloads and difficulty are high, so HT abstracts several types of models, providing a convenient way to build the function API, with the following functions in addition to createFrameModel to introduce ht-modeling.js expansion pack, the rest has been provided by ht.js:
ht.Default.createBoxModel() builds the hexahedral model, which displays the same colors and tiles on six sides of the model
ht.Default.createSphereModel(side, sideFrom, sideTo, from, to, resolution) building sphere model:
side: Total number of edgessideFrom: Starting edge indexsideTo: Ending edge indexfrom: Is there a starting planeto: Is there a ending planeresolution: Represents the number of differential segmentsht.Default.createSmoothSphereModel(hResolution, vResolution, hStart, hArc, vStart, vArc, radius) building the smooth sphere model:
hResolution: Horizontal directional differential segment numbervResolution: Vertial directional differential segment numberhStart: The starting angle of horizontal direction, the default is 0 hArc: Horizontal direction total radian, the default is Math.PI*2vStart: Vertial direction total Radian, the default is 0 vArc: Total radian in vertical direction, the default is Math.PI radius: Sphere radius, the default is 0.5ht.Default.createCylinderModel(side, sideFrom, sideTo, from, to, top, bottom) building the cylinder model:
side: Total number of sidesideFrom: The index of the start sidesideTo: The index of the end sidefrom: Is there a starting planeto: Is there a ending planetop: Is there a topbottom: Is there a bottomht.Default.createSmoothCylinderModel(resolution, top, bottom, topRadius, bottomRadius, start, arc, height) building the smooth cylinder model:
resolution: Represents the number of differential segmentstop: Is there a topbottom: Is there a bottomtopRadius: Top radius, the default is 0.5bottomRadius: Bottom radius, the default is 0.5start: Starting angle, the default is 0.5arc: Total radian, the default is Math.PI*2height: The height of cylinder, the default is 1ht.Default.createConeModel(side, sideFrom, sideTo, from, to, bottom) building the cone model:
side: Total number of sidesideFrom: The index of the start sidesideTo: The index of the end sidefrom: Is there a starting planeto: Is there a ending planebottom: Is there a bottomht.Default.createSmoothConeModel(bottom, resolution, start, arc, radius) building the smooth cone model:
bottom: Is there a bottomresolution: Represents the number of differential segmentsstart: Starting angle, the default is 0.5arc: Total radian, the default is Math.PI*2radius: Bottom radius, the default is 0.5ht.Default.createTorusModel(side, sideFrom, sideTo, from, to, radius, resolution) build the torus model:
side: Total number of sidesideFrom: The index of the start sidesideTo: The index of the end sidefrom: Is there a starting planeto: Is there a ending planeradius: The tube radius of the ring, the default value is 0.17, the desirable range 0~2.5resolution: The number of circular differential sectionsht.Default.createSmoothTorusModel(radius, tubeRadius, hResolution, vResolution, start, arc) building the smooth torus model:
radius: Ring radius positiontubeRadius: Circular radius size of sectionhResolution: Ring horizontal direction differential segment numbervResolution: The number of circular differential sectionsstart: Starting angle, the default is 0arc: Total radian, the default is Math.PI*2ht.Default.createRoundRectModel(top, bottom) build the round rectangle model:
top: Is there a topbottom: Is there a bottomht.Default.createStarModel(top, bottom) building the star model:
top: Is there a topbottom: Is there a bottomht.Default.createRectModel(top, bottom) building the rectangle model:
top: Is there a topbottom: Is there a bottomht.Default.createTriangleModel(top, bottom) build the triangle model:
top: Is there a topbottom: Is there a bottomht.Default.createRightTriangleModel(top, bottom) building the right triangle model:
top: Is there a topbottom: Is there a bottomht.Default.createParallelogramModel(top, bottom) build the parallelogram model:
top: Is there a topbottom: Is there a bottomht.Default.createTrapezoidModel(top, bottom) building the trapezoid model:
top: Is there a topbottom: Is there a bottomht.Default.createExtrusionModel(array, segments, top, bottom, resolution, repeatUVLength, tall, elevation) according to the xz planar polygon, squeeze to a 3D model.
array: Defines all point coordinates of the xz plane, in the format of: [x1, z1, x2, z2 ...]segments: Defines a point connection style, an array element is an integer value, and a null represents all points connected to a line moveTo, occupy 1 point informationlineTo, occupy 1 point informationquadraticCurveTo, occupy 2 point informationbezierCurveTo, occupy 3 point informationclosePath, do not occupy a bit of informationtop: Is there a topbottom: Is there a bottomresolution: Differential segment numberrepeatUVLength: Default is NULL, the top and bottom of the tile will be set according to the length of the set value to repeattall: Model height, the default is 0.5elevation: The y axis position of the model center, the default is 0ht.Default.createRingModel(array, segments, resolution, top, bottom, side, sideFrom, sideTo, from, to) according to the curve of the xy plane, around a week to a 3D model.
array: Defines all point coordinates of the xz plane, in the format of: [x1, z1, x2, z2 ...]segments: Defines a point connection style, an array element is an integer value, and a null represents all points connected to a line moveTo, occupy 1 point informationlineTo, occupy 1 point informationquadraticCurveTo, occupy 2 point informationbezierCurveTo, occupy 3 point informationclosePath, do not occupy a bit of informationresolution: Differential segment numbertop: Is there a topbottom: Is there a bottomside: Total number of sidesideFrom: The starting side of indexsideTo: The ending side of indexfrom: Is there a starting planeto: Is there a ending planeht.Default.createSmoothRingModel(array, segments, vResolution, start, arc, hResolution) according to the curve of the xy plane, around a week to a smooth 3D model.
array: Defines all point coordinates of the xz plane, in the format of: [x1, z1, x2, z2, ...]segments: Defines a point connection style, an array element is an integer value, and a null represents all points connected to a line moveTo, occupy 1 point informationlineTo, occupy 1 point informationquadraticCurveTo, occupy 2 point informationbezierCurveTo, occupy 3 point informationclosePath, do not occupy a bit of informationvResolution: Curve differential segment numberstart: Starting angle, the default is 0 arc: Total radian, the default is Math.PI*2hResolution: Horizontal surround differential segment numberht.Default.createFrameModel(dx, dy, dz, params) building a framework body model
dx: x axle frame thickness, the default is 0.07dy: y axle frame thickness, the default is 0.07dz: z axle frame thickness, the default is 0.07params is JSON structure object parameters, object properties are:top: true represents the overall coverage, false means that the surface is NULL, the rest of the attributes are hollow, or the default effectbottom: true represents the overall coverage, false means that the surface is NULL, the rest of the attributes are hollow, or the default effectleft: true represents the overall coverage, false means that the surface is NULL, the rest of the attributes are hollow, or the default effectright: true represents the overall coverage, false means that the surface is NULL, the rest of the attributes are hollow, or the default effectfront: true represents the overall coverage, false means that the surface is NULL, the rest of the attributes are hollow, or the default effectback: true represents the overall coverage, false means that the surface is NULL, the rest of the attributes are hollow, or the default effectIn addition to the underlying properties associated with building model vertices described in the Model Basics section, model JSON objects can also define the following properties:
s3: Array types such as [0.5, 2.0, 3.0], representing the model x axis to narrow the direction of the half, the model y axis to expand double, the model z axis direction of triple largert3: Array type such as [10,-20, 30], represents the model x axis direction translation 10, model y axis direction translation -20, model z axis direction translation 30r3: Array types such as [Math.PI/2, 0, 0], represents the model with x axis rotation Math.PI/2 radians, y and z axes' direction are unchanged rotationMode: Rotate model, control the three axes of r3 rotation sequence, the default is xzyThe following property values are default to style corresponding to shape3d, if set on the model, the definition on the model has a higher priority:
color: The default is #3498DB, the overall color in 3d graphic topColor: The default is undefined, the top surface color in 3d graphic bottomColCor: The default is undefined, the bottom surface color in 3d graphic fromColor: The default is undefined, the start surface color in 3d graphic toColor: The default is undefined, the end surface color in 3d graphic image: The default is undefined, the overall tile in 3d graphic topImage: The default is undefined, the top surface tile in 3d graphic bottomImage: The default is undefined, the bottom surface tile in 3d graphic fromImage: The default is undefined, the start surface tile in 3d graphic toImage: The default is undefined, the end surface tile in 3d graphic light: The default is true, whether the 3d graphic affected by lightside: The default value is 0, which determines that the 3d graphic appears as a few-edged, 0 as a smooth surface effectsideFrom: The default is undefined, which determines the starting side position of 3d graphicssideTo: The default is undefined, which determines the end side position of 3d graphicsvisible: The default value is true to determine whether the 3d graphic is visible, which does not affect the label, note and icons and other parts of the elementfromVisible: The default value is true to determine whether the starting surface of 3d graphic is visibletoVisible: The default value is true to determine whether the end surface of 3d graphic is visibletopVisible: The default value is true to determine whether the top surface of 3d graphic is visiblebottomVisible: The default value is true to determine whether the bottom surface of 3d graphic is visibletorusRadius: The default is 0.17, which determines the radius of the 3d annular tuberesolution: The default is 24, determines the 3d graph segment number, and the side is similar but determines the different direction of the segment, the larger the value the more uniform but affect performanceopacity: The default is undefined, which determines the transparency of the 3d graphic, the value range 0~1reverseFlip: The default is false to determine whether the negative side of the 3d graphic shows positive contentreverseColor: #868686, determines the reverse color of 3d graphicsreverseCull: The default is false to determine whether the reverse side of 3d graphics is displayed, hidden back can improve performancetransparent: The default is false to determine whether the 3d graphic is transparentuvOffset: The default is undefined, which determines the uv offset of the 3d graphics overall tile, in the format [0.5, 0.5]uvScale: The default is undefined, which determines the uv scale of the 3d graphics overall tile, in the format [3, 2]topUvOffset: The default is undefined, which determines the uv offset of the 3d graphics top surface tile, in the format [0.5, 0.5]topUvScale: The default is undefined, which determines the uv scale of the 3d graphics top surface tile, in the format [3, 2]bottomUvOffset: The default is undefined, which determines the uv offset of the 3d graphics bottom surface tile, in the format [0.5, 0.5]bottomUvScale: The default is undefined, which determines the uv scale of the 3d graphics bottom surface tile, in the format [3, 2]fromUvOffset: The default is undefined, which determines the uv offset of the 3d graphics starting surface tile, in the format [0.5, 0.5]fromUvScale: The default is undefined, which determines the uv scale of the 3d graphics starting surface tile, in the format [3, 2]toUvOffset: The default is undefined, which determines the uv offset of the 3d graphics end surface tile, in the format [0.5, 0.5]toUvScale: The default is undefined, which determines the uv scale of the 3d graphics end surface tile, in the format [3, 2]More complex models often need a combination of small models, using the current knowledge can set different parts of the model shape3d property separately through numbers of Node datas, if the effect of multiple parts to stick together, you can adsorbed these Node datas together to each other in rings through Node#setHost function.
But such a solution would result in inconvenient object management, for example, a chair can be composed of four legs and a plane, but from an object management perspective or user perspective, we hope that the whole chair is a Node object, there is only one node in the TreeView view, this is the best occasion to use the model composition feature.
The definition of a composite model is very simple and flexible, and multiple models can be combined in an Array array
ht.Default.setShape3dModel('A', modelA);
ht.Default.setShape3dModel('B', modelB);
ht.Default.setShape3dModel('C', ['A', 'B']);
The above code defines the A, B and C three models, in which the model C is a combination of the A and B models.
ht.Default.setShape3dModel('E', ['A', 'B', 'sphere', modelD])
The array elements of the composite model can not only be the newly defined model names, also can be predefined model names, as well as model JSON objects directly, the above code defines the new model E, which is defined by a custom A and B model, predefined sphere spheres, and modelD combination of the four models.
ht.Default.setShape3dModel('F', [
{
shape3d: 'box',
color: 'yellow'
},
{
shape3d: 'box',
s3: [0.5, 0.5, 1.1],
color: 'red'
}
]);
The attributes of the chapter Model Properties can be set not only on the JSON object of the model, you can also set on a new element object in a composite model array, which defines the new model F, which is composed of two box models, the model type is defined by the shape3d element attribute, you can also set model parameters such as color and s3.
ht.Default.setShape3dModel('G', [
{
shape3d: ['cylinder', {shape3d: 'cone', color: 'green', t3: [1, 0, 0]}],
color: 'yellow',
t3: [-0.5, 0, -1]
},
{
shape3d: 'box',
s3: [0.3, 0.3, 0.3],
color: 'red'
}
]);
The shape3d property values of a group element object, also can be an array type to achieve infinite recursive combination hierarchy nesting, the above code definition of the G model rendering effect as follows:
Refer to Databinding Manual
HT provides a number of primitive types of primitives, but in order to quickly build a room building, a variety of scene decorations, the modeling expansion pack adds more primitive types, facilitating users to quickly build project scenes with APIs or visual editing tools.
ht.Symbol inherits from ht.Node, often used to display flower pots, billboards and other decorative pictures of the plane, its default setting of all.visible to false, overloaded with setIcon function, in the setting icon of the same time through addStyleIcon will also be used to display pictures in Graph3dView. Generally using Symbol requires only the constructor or the setIcon to input the parameter, then the p3 position can be set.
ht.Symbol(icon, autorotate, transaprent)setIcon(icon, autorotate, transaprent)icon Specify pictures to displayautorotate The default is false, which controls whether the direction of the eye is automatically oriented, can be set to true or x, y, z, where y represents a qualification to rotate along the y axistransaprent Represents whether to display as transparent, default to falseThe setIcon function returns the registered json object, which can be used to set additional parameters, see the 3D Manual Icon Chapter
CSG is the abbreviation of Constructive Solid Geometry modeling technology, by tailoring subtract, fusion union and intersection intersect operations combine complex model effects, HT encapsulates ht.CSGNode and ht.CSGShape and other data types to support the combination of CSG, often used in the wall of doors and windows hollowed out the application scene.
'ht.CSGNode inherits from ht.Node, when the style of the shape3d attribute is shown to be null show the cube effect, if the CSGNode adsorbed to the host CSGNode or CSGShape by sethost, the host CSGNode or CSGShape can be combined with the adsorption of CSGNode datas for CSG modeling.
attach.cull: The default is false, which determines whether the intersecting part is excludedattach.operation: The default is subtract, the following values are desirable:subtract: Represents a knockout clipping of host CSGNode or CSGShape datasunion: Represents the fusion of CSGNode or CSGShape datas of hostintersect: Represents the intersection part of CSGNode or CSGShape of hosthost dataWhen the host CSGNode or CSGShape is combined to generate the new model part of the rendering by the csg.* parameters to control, is the same control mode with all.* and other facets of the six-face body, refer to 3D Manual of the Cube Chapter.
csg.light: Whether it is affected by light, when the light is affected by the brightness of the front, the side looks darkcsg.visible: Is it visiblecsg.color: Colorcsg.image: Tile, the priority is higher than csg.colorcsg.blend: Dyed color, the priority is higher than csg.color, if there is a tile, dying the tilecsg.opacity: Transparentcy, the value range 0~1csg.reverse.flip: Whether the reverse shows the positive contentcsg.reverse.color: Reverse color, the inner face color of the cubecsg.reverse.cull: Whether the reverse is visible, that means whether the cube interior surface is displayed, the general six-side closed cubes, do not display to improve performancecsg.transparent: Whether transparent, if the color|image|opacity attribute appears in a transparent region, it should be set to true in generalNote that there is no csg.uv, csg.uv.scale and csg.uv.offset, etc., tile-related parameters, csg related surface of the uv value is determined by the adsorption of the cube tile parameters, only the tile picture parameters determined by host csg.image parameter.
We can understand the
CSG.*as the seventh face exceptleft/rigth/top/bottom/front/back
ht.CSGBox inherits from ht.CSGNode, in addition to having the knocked out function of CSGNode of the parent class, can also be rotated and expand and closed on six surfaces, so the following related style attribute is added, the following is only described as front because of the identical parameters of six sides:
front.toggleable: Whether to allow double click to expand and close operation, the default is falsefront.expanded: Is currently expanded, the default is falsefront.angle: Current state rotation angle, the default is 0front.start: The starting rotation radian of the close state, the default is 0front.end: The end rotation radians of the expand state, the default is Math.PI/2front.axis: The rotation axis of the expand and close operation, the default is leftleft: Rotate with left as an axisright: Rotate with right as an axistop: Rotate with top as an axisbottom: Rotate with bottom as an axisv: Rotate with an intermediate vertical line as an axis h: Rotate with intermediate horizontal line as an axis These two parameters of front.expanded and front.angle are generally not operated by the user, ht.CSGBox` provides the following function encapsulation, refer to Form Manual Example Unboxing
toggleFace(face, anim): The toggle surface is currently expanded or closed, faces desirable value left|right|top|bottom|front|back, anim represents whether animation or notisFaceExpanded(face): Determines whether the surface is currently in a state of expansion, faces desirable value left|right|top|bottom|front|backsetFaceExpanded(face, expanded, anim): Set surface expansion or close status, expanded desirable value true|false, anim represents whether animation or notNote that there is no
all.*corresponding to the six-plane uniform parameters,CSGBoxrelated surface parameters can only be set independently of each surface
ht.DoorWindow inherits from ht.CSGNode, in addition to having the function of ht.CSGNode of father class, can also carry out the whole rotation to expand and close operation, often used as the business object of the door or window, adsorbed in CSGNode or CSGShape host as the wall of the data, DoorWindow adds the following style parameters to the control, where dw is the abbreviation of DoorWindow:
dw.flip: Flip the display of the data, equivalent to rotate 180 degrees along the z axisdw.s3: Zoom in on the original base of the data display size, the default value is [0.999, 0.999, 0.5] represents x and y shrinks 0.001, z shrinks 0.5dw.t3: An absolute position offset on the original basis for the display position of the data, and the default value is NULL for no offsetdw.toggleable: Allow double click to expand and close operations, the default is true dw.expanded: Whether the current data is expanded, the default is falsedw.angle: Current state rotation angle, the default is 0dw.start: The starting rotation radian of the close state, the default is 0dw.end: Expand the end of the state rotation radians, the default is Math.PI/2dw.axis: Expand and close the rotation axis of the operation, the following values are desirable, the default is leftleft: Rotate with left as an axisright: Rotate with right as an axis top: Rotate with top as an axis bottom: Rotate with bottom as an axis v: Rotate with an intermediate vertical line as an axis h: Rotate with an intermediate horizontal line as an axis
DoorWindowtype can also be combined with theOBJformat3Dmodel to show more realistic windows and doors effects, see Obj Manual windows and doors application example
ht.CSGShape inherits from ht.Shape, currently only supports the not ignoring the segments parameters of the line wall effect, CSGNode if through setHost adsorption to the host CSGShape, CSGShape can be with the adsorbed CSGNode datas to CSG modeling.
attach.index: The default is -1, used for CSGNode adsorption to Shape datas, which represents the segment index of the Shapeattach.offset: The default is 0, which is used in conjunction with the attach.index parameter, which represents the offset position of the segment where the CSGShape data residesattach.offset.relative: The default is false, and if true, the offset represents the length of the segment multiplied by attach.offset valueattach.offset.opposite: The default is false, used in conjunction with attach.offset parameter to represent the positive or reverse direction of the line segmentattach.thickness: Node defaults are null, CSGNode defaults to 1.001, CSGNode the height attribute value by Shape thickness multiplied by that valueattach.gap: The default is 0, which represents the offset from the vertical direction of the line segmentattach.gap.relative: The default is false, and if true the offset from the vertical direction of the line to Shape thickness value multiplied by attach.gapWhen the style parameter is set by the adsorbent CSGNode, it will automatically adjusts its size, position, and rotation angle so that it remains positioned on the Shape corresponding segment, and this function applies not only to ht.CSGShape, also applies to ht.Sha pe's parent data, note that the adsorption function on this segment does not take into account the Shape type of rotation.
CSGShape type to ht.Shape has been simplified, and the setRotation, setRotationX and setRotationZ rotation functions are not supported except for segments parameters.