📄 geometry_stacks.c
字号:
pts = coord->point.vals; if (!pts) return; cur_index = c2D->type.count ? 1 : 0; /*if the first type is a moveTo skip initial moveTo*/ i=0; if (cur_index) { while (c2D->type.vals[i]==0) i++; } ct_orig = orig = pts[i]; gf_path_add_move_to(st->path, orig.x, orig.y); pt_count = coord->point.count; type_count = c2D->type.count; for (; i<type_count; i++) { switch (c2D->type.vals[i]) { /*moveTo, 1 point*/ case 0: CHECK_VALID_C2D(0); orig = pts[cur_index]; if (i) gf_path_add_move_to(st->path, orig.x, orig.y); cur_index += 1; break; /*lineTo, 1 point*/ case 1: CHECK_VALID_C2D(0); end = pts[cur_index]; gf_path_add_line_to(st->path, end.x, end.y); orig = end; cur_index += 1; break; /*curveTo, 3 points*/ case 2: CHECK_VALID_C2D(2); ct_orig = pts[cur_index]; ct_end = pts[cur_index+1]; end = pts[cur_index+2]; gf_path_add_cubic_to(st->path, ct_orig.x, ct_orig.y, ct_end.x, ct_end.y, end.x, end.y); cur_index += 3; ct_orig = ct_end; orig = end; break; /*nextCurveTo, 2 points (cf spec)*/ case 3: CHECK_VALID_C2D(1); ct_orig.x = 2*orig.x - ct_orig.x; ct_orig.y = 2*orig.y - ct_orig.y; ct_end = pts[cur_index]; end = pts[cur_index+1]; gf_path_add_cubic_to(st->path, ct_orig.x, ct_orig.y, ct_end.x, ct_end.y, end.x, end.y); cur_index += 2; ct_orig = ct_end; orig = end; break; /*all XCurve2D specific*/ /*CW and CCW ArcTo*/ case 4: case 5: CHECK_VALID_C2D(2); ct_orig = pts[cur_index]; ct_end = pts[cur_index+1]; end = pts[cur_index+2]; gf_path_add_arc_to(st->path, end.x, end.y, ct_orig.x, ct_orig.y, ct_end.x, ct_end.y, (c2D->type.vals[i]==5) ? 1 : 0); cur_index += 3; ct_orig = ct_end; orig = end; break; /*ClosePath*/ case 6: gf_path_close(st->path); break; /*quadratic CurveTo, 2 points*/ case 7: CHECK_VALID_C2D(1); ct_end = pts[cur_index]; end = pts[cur_index+1]; gf_path_add_quadratic_to(st->path, ct_end.x, ct_end.y, end.x, end.y); cur_index += 2; ct_orig = ct_end; orig = end; break; } } /*what's left is an N-bezier spline*/ if (pt_count > cur_index) { /*first moveto*/ if (!cur_index) cur_index++; remain = pt_count - cur_index; if (remain>1) gf_path_add_bezier(st->path, &pts[cur_index], remain); }}static void RenderCurve2D(GF_Node *node, void *rs, Bool is_destroy){ M_Curve2D *c2D = (M_Curve2D *)node; stack2D *st = (stack2D *)gf_node_get_private(node); RenderEffect3D *eff = (RenderEffect3D *)rs; if (is_destroy) { stack2D_node_predestroy(node); return; } if (!c2D->point) return; if (gf_node_dirty_get(node)) { stack2D_reset(st); st->path->fineness = c2D->fineness; if (st->compositor->high_speed) st->path->fineness /= 2; build_curve2D(st, c2D); mesh_from_path(st->mesh, st->path); gf_node_dirty_clear(node, 0); } if (!eff->traversing_mode) stack2D_draw(st, eff); else if (eff->traversing_mode==TRAVERSE_GET_BOUNDS) eff->bbox = st->mesh->bounds;}void R3D_InitCurve2D(Render3D *sr, GF_Node *node){ stack2D *st = BaseStack2D(sr->compositor, node); gf_node_set_callback_function(node, RenderCurve2D); st->IntersectWithRay = Stack2DIntersectWithRay;}static void build_ils2d(stack2D *st, M_IndexedLineSet2D *ils2D){ u32 i; Bool started; SFVec2f *pts; M_Coordinate2D *coord = (M_Coordinate2D *)ils2D->coord; pts = coord->point.vals; if (ils2D->coordIndex.count > 0) { started = 0; for (i=0; i < ils2D->coordIndex.count; i++) { /*NO close on ILS2D*/ if (ils2D->coordIndex.vals[i] == -1) { started = 0; } else if (!started) { started = 1; gf_path_add_move_to(st->path, pts[ils2D->coordIndex.vals[i]].x, pts[ils2D->coordIndex.vals[i]].y); } else { gf_path_add_line_to(st->path, pts[ils2D->coordIndex.vals[i]].x, pts[ils2D->coordIndex.vals[i]].y); } } } else if (coord->point.count) { gf_path_add_move_to(st->path, pts[0].x, pts[0].y); for (i=1; i < coord->point.count; i++) { gf_path_add_line_to(st->path, pts[i].x, pts[i].y); } }}static void RenderILS2D(GF_Node *node, void *rs, Bool is_destroy){ Aspect2D asp; StrikeInfo *si; M_IndexedLineSet2D *ils2D = (M_IndexedLineSet2D *)node; stack2D *st = (stack2D *)gf_node_get_private(node); RenderEffect3D *eff = (RenderEffect3D *)rs; if (is_destroy) { stack2D_node_predestroy(node); return; } if (gf_node_dirty_get(node)) { stack2D_reset(st); build_ils2d(st, ils2D); mesh_new_ils(st->mesh, ils2D->coord, &ils2D->coordIndex, ils2D->color, &ils2D->colorIndex, ils2D->colorPerVertex, 0); gf_node_dirty_clear(node, 0); } if (!eff->traversing_mode) { VS_GetAspect2D(eff, &asp); VS3D_SetAntiAlias(eff->surface, (eff->surface->render->compositor->antiAlias==GF_ANTIALIAS_FULL) ? 1 : 0); if (ils2D->color) { VS3D_StrikeMesh(eff, st->mesh, Aspect_GetLineWidth(&asp), asp.pen_props.dash); } else { si = VS_GetStrikeInfo(st, &asp, eff); if (si) { VS_Set2DStrikeAspect(eff, &asp); if (!si->is_vectorial) { VS3D_StrikeMesh(eff, si->outline, Aspect_GetLineWidth(&asp), asp.pen_props.dash); } else { VS3D_DrawMesh(eff, si->outline); } } } } else if (eff->traversing_mode==TRAVERSE_GET_BOUNDS) { eff->bbox = st->mesh->bounds; } }static void ILS2D_SetColorIndex(GF_Node *node){ M_IndexedLineSet2D *ils2D = (M_IndexedLineSet2D *)node; gf_sg_vrml_field_copy(&ils2D->colorIndex, &ils2D->set_colorIndex, GF_SG_VRML_MFINT32); gf_sg_vrml_mf_reset(&ils2D->set_colorIndex, GF_SG_VRML_MFINT32);}static void ILS2D_SetCoordIndex(GF_Node *node){ M_IndexedLineSet2D *ils2D = (M_IndexedLineSet2D *)node; gf_sg_vrml_field_copy(&ils2D->coordIndex, &ils2D->set_coordIndex, GF_SG_VRML_MFINT32); gf_sg_vrml_mf_reset(&ils2D->set_coordIndex, GF_SG_VRML_MFINT32);}void R3D_InitILS2D(Render3D *sr, GF_Node *node){ M_IndexedLineSet2D *ils2D = (M_IndexedLineSet2D *)node; stack2D *st = BaseStack2D(sr->compositor, node); gf_node_set_callback_function(node, RenderILS2D); ils2D->on_set_colorIndex = ILS2D_SetColorIndex; ils2D->on_set_coordIndex = ILS2D_SetCoordIndex; st->IntersectWithRay = R3D_NoIntersectionWithRay;}static void RenderPointSet2D(GF_Node *node, void *rs, Bool is_destroy){ M_PointSet2D *ps2D = (M_PointSet2D *)node; DrawableStack *st = (DrawableStack *)gf_node_get_private(node); RenderEffect3D *eff = (RenderEffect3D *)rs; if (is_destroy) { drawable_node_destroy(node); return; } if (!ps2D->coord) return; if (gf_node_dirty_get(node)) { mesh_new_ps(st->mesh, ps2D->coord, ps2D->color); gf_node_dirty_clear(node, 0); } if (!eff->traversing_mode) { Aspect2D asp; VS_GetAspect2D(eff, &asp); VS3D_SetMaterial2D(eff->surface, asp.fill_color, asp.alpha); VS3D_DrawMesh(eff, st->mesh); } else if (eff->traversing_mode==TRAVERSE_GET_BOUNDS) { eff->bbox = st->mesh->bounds; }}void R3D_InitPointSet2D(Render3D *sr, GF_Node *node){ DrawableStack *st = BaseDrawableStack(sr->compositor, node); gf_node_set_callback_function(node, RenderPointSet2D); st->IntersectWithRay = R3D_NoIntersectionWithRay;}static void build_ifs2d(stack2D *st, M_IndexedFaceSet2D *ifs2D){ u32 i; SFVec2f *pts; u32 ci_count, c_count; Bool started; M_Coordinate2D *coord = (M_Coordinate2D *)ifs2D->coord; c_count = coord->point.count; ci_count = ifs2D->coordIndex.count; pts = coord->point.vals; if (ci_count > 0) { started = 0; for (i=0; i < ci_count; i++) { if (ifs2D->coordIndex.vals[i] == -1) { gf_path_close(st->path); started = 0; } else if (!started) { started = 1; gf_path_add_move_to(st->path, pts[ifs2D->coordIndex.vals[i]].x, pts[ifs2D->coordIndex.vals[i]].y); } else { gf_path_add_line_to(st->path, pts[ifs2D->coordIndex.vals[i]].x, pts[ifs2D->coordIndex.vals[i]].y); } } if (started) gf_path_close(st->path); } else if (c_count) { gf_path_add_move_to(st->path, pts[0].x, pts[0].y); for (i=1; i < c_count; i++) { gf_path_add_line_to(st->path, pts[i].x, pts[i].y); } gf_path_close(st->path); }}static void RenderIFS2D(GF_Node *node, void *rs, Bool is_destroy){ Aspect2D asp; StrikeInfo *si; M_IndexedFaceSet2D *ifs2D = (M_IndexedFaceSet2D *)node; stack2D *st = (stack2D *)gf_node_get_private(node); RenderEffect3D *eff = (RenderEffect3D *)rs; if (is_destroy) { stack2D_node_predestroy(node); return; } if (gf_node_dirty_get(node)) { stack2D_reset(st); build_ifs2d(st, ifs2D); mesh_new_ifs2d(st->mesh, node); gf_node_dirty_clear(node, 0); } if (!eff->traversing_mode) { VS_GetAspect2D(eff, &asp); if (ifs2D->color && !asp.filled) { /*use special func to disable outline recompute and handle recompute ourselves*/ si = VS_GetStrikeInfoIFS(st, &asp, eff); if (!si->outline) { si->outline = new_mesh(); mesh_new_ils(si->outline, ifs2D->coord, &ifs2D->coordIndex, ifs2D->color, &ifs2D->colorIndex, ifs2D->colorPerVertex, 1); } VS3D_StrikeMesh(eff, si->outline, Aspect_GetLineWidth(&asp), asp.pen_props.dash); } else { stack2D_draw(st, eff); } } else if (eff->traversing_mode==TRAVERSE_GET_BOUNDS) { eff->bbox = st->mesh->bounds; }}static void IFS2D_SetColorIndex(GF_Node *node){ M_IndexedFaceSet2D *ifs2D = (M_IndexedFaceSet2D *)node; gf_sg_vrml_field_copy(&ifs2D->colorIndex, &ifs2D->set_colorIndex, GF_SG_VRML_MFINT32); gf_sg_vrml_mf_reset(&ifs2D->set_colorIndex, GF_SG_VRML_MFINT32);}static void IFS2D_SetCoordIndex(GF_Node *node){ M_IndexedFaceSet2D *ifs2D = (M_IndexedFaceSet2D *)node; gf_sg_vrml_field_copy(&ifs2D->coordIndex, &ifs2D->set_coordIndex, GF_SG_VRML_MFINT32); gf_sg_vrml_mf_reset(&ifs2D->set_coordIndex, GF_SG_VRML_MFINT32);}static void IFS2D_SetTexCoordIndex(GF_Node *node){ M_IndexedFaceSet2D *ifs2D = (M_IndexedFaceSet2D *)node; gf_sg_vrml_field_copy(&ifs2D->texCoordIndex, &ifs2D->set_texCoordIndex, GF_SG_VRML_MFINT32); gf_sg_vrml_mf_reset(&ifs2D->set_texCoordIndex, GF_SG_VRML_MFINT32);}void R3D_InitIFS2D(Render3D *sr, GF_Node *node){ M_IndexedFaceSet2D *ifs2D = (M_IndexedFaceSet2D *)node; stack2D *st = BaseStack2D(sr->compositor, node); gf_node_set_callback_function(node, RenderIFS2D); ifs2D->on_set_colorIndex = IFS2D_SetColorIndex; ifs2D->on_set_coordIndex = IFS2D_SetCoordIndex; ifs2D->on_set_texCoordIndex = IFS2D_SetTexCoordIndex; st->IntersectWithRay = Stack2DIntersectWithRay;}static void RenderPointSet(GF_Node *node, void *rs, Bool is_destroy){ M_PointSet *ps = (M_PointSet *)node; DrawableStack *st = (DrawableStack *)gf_node_get_private(node); RenderEffect3D *eff = (RenderEffect3D *)rs; if (is_destroy) { drawable_node_destroy(node); return; } if (!ps->coord) return; if (gf_node_dirty_get(node)) { mesh_new_ps(st->mesh, ps->coord, ps->color); gf_node_dirty_clear(node, 0); } if (!eff->traversing_mode) { VS_DrawMesh(eff, st->mesh); } else if (eff->traversing_mode==TRAVERSE_GET_BOUNDS) { eff->bbox = st->mesh->bounds; }}void R3D_InitPointSet(Render3D *sr, GF_Node *node){ DrawableStack *st = BaseDrawableStack(sr->compositor, node); gf_node_set_callback_function(node, RenderPointSet); st->IntersectWithRay = R3D_NoIntersectionWithRay;}static void RenderIFS(GF_Node *node, void *rs, Bool is_destroy){ DrawableStack *st = (DrawableStack *)gf_node_get_private(node); RenderEffect3D *eff = (RenderEffect3D *)rs; if (is_destroy) { drawable_node_destroy(node); return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -