func ensureSiblings(xn *xmlx.Node, namesVals map[string]string) { var sn *xmlx.Node for n, v := range namesVals { if sn = subNode(xn.Parent, n); sn == nil { sn = xmlx.NewNode(xn.Type) sn.Name.Local = n xn.Parent.AddChild(sn) } sn.Value = v } }
func processNode(xn *xmlx.Node) { if (!Force) && (xn.Name.Local == "COLLADA") { if _, ver := ugo.ParseVersion(attVal(xn, "version")); ver >= 1.5 { skipped = true return } } xn.Name.Space = "" for _, att := range xn.Attributes { att.Name.Space = "" } switch xn.Name.Local { case "COLLADA": setAttr(xn, "version", "1.5", false) setAttr(xn, "xmlns", "http://www.collada.org/2008/03/COLLADASchema", false) case "array": if !ustr.IsOneOf(xn.Parent.Name.Local, "array", "newparam", "setparam") { delNode(xn) } case "argument", "texenv": delAttr(xn, "unit") case "cg_value_type", "connect_param", "generator", "tapered_capsule", "tapered_cylinder", "texture_unit": delNode(xn) case "code", "include": if !ustr.IsOneOf(xn.Parent.Name.Local, "profile_CG", "profile_GLES2", "profile_GLSL") { delNode(xn) } case "color_target", "depth_target", "stencil_target": if val := surfaceImages[xn.Value]; len(val) == 0 { setAttr(ensureChild(xn, "param"), "ref", xn.Value, false) } else { setAttr(ensureChild(xn, "instance_image"), "url", "#"+val, false) } xn.Value = "" case "float_array": restrictAttr(xn, "digits", 1, 17) restrictAttr(xn, "magnitude", -324, 308) case "image": convertImage(xn) case "instance_effect": if xn.Parent.Name.Local == "render" { id := fmt.Sprintf("render_%v", time.Now().UnixNano()) matNode := xmlx.NewNode(xn.Type) matNode.Name.Local = "material" setAttr(matNode, "id", id, false) matsLibNode := ensureChild(srcDoc.Root.Children[0], "library_materials") matsLibNode.AddChild(matNode) oldParent := xn.Parent _, pos := moveNode(xn, matNode, "") instNode := xmlx.NewNode(xn.Type) instNode.Name.Local = "instance_material" setAttr(instNode, "url", "#"+id, false) instNode.Parent = oldParent oldParent.Children[pos] = instNode } case "magfilter", "minfilter", "mipfilter": if (xn.Value == "NONE") && (xn.Name.Local != "mipfilter") { xn.Value = "NEAREST" } else { switch xn.Value { case "NEAREST_MIPMAP_NEAREST": ensureSiblings(xn, map[string]string{"minfilter": "NEAREST", "mipfilter": "NEAREST"}) case "LINEAR_MIPMAP_NEAREST": ensureSiblings(xn, map[string]string{"minfilter": "LINEAR", "mipfilter": "NEAREST"}) case "NEAREST_MIPMAP_LINEAR": ensureSiblings(xn, map[string]string{"minfilter": "NEAREST", "mipfilter": "LINEAR"}) case "LINEAR_MIPMAP_LINEAR": ensureSiblings(xn, map[string]string{"minfilter": "LINEAR", "mipfilter": "LINEAR"}) } } case "mipmap_bias": renameNode(xn, "mip_bias") case "mipmap_maxlevel": renameNode(xn, "mip_max_level") case "newparam": if !ustr.IsOneOf(xn.Parent.Name.Local, "effect", "profile_CG", "profile_COMMON", "profile_GLSL", "profile_GLES", "profile_GLES2") { delNode(xn) } case "radius": if vals := ustr.Split(xn.Value, " "); (xn.Parent.Name.Local == "capsule") && (len(vals) > 0) && (len(vals) < 3) { for len(vals) < 3 { vals = append(vals, "1.0") } xn.Value = strings.Join(vals, " ") } case "setparam": if !ustr.IsOneOf(xn.Parent.Name.Local, "instance_effect", "usertype") { delNode(xn) } case "shader": convertShader(xn) case "surface": convertSurface(xn) case "texture_pipeline": if xn.Parent.Name.Local != "states" { delNode(xn) } case "transparent": setAttr(xn, "opaque", "A_ONE", true) case "usertype": renameAttr(xn, "name", "typename") if !ustr.IsOneOf(xn.Parent.Name.Local, "newparam", "setparam", "array", "bind_uniform") { delNode(xn) } else { for _, sn := range xn.Children { if sn.Name.Local != "setparam" { delNode(sn) } } } default: if (xn.Parent != nil) && (xn.Parent.Name.Local == "pass") { switch xn.Name.Local { case "annotate", "extra", "evaluate", "states", "program": break case "color_target", "depth_target", "stencil_target", "color_clear", "depth_clear", "stencil_clear", "draw": moveNode(xn, ensureChild(xn.Parent, "evaluate"), "") case "shader": moveNode(xn, ensureChild(xn.Parent, "program"), "") default: moveNode(xn, ensureChild(xn.Parent, "states"), "") } } if strings.HasPrefix(xn.Name.Local, "wrap_") && (xn.Value == "NONE") { xn.Value = "BORDER" } if (xn.Name.Local != "sampler") && strings.HasPrefix(xn.Name.Local, "sampler") && !strings.HasPrefix(xn.Name.Local, "sampler_") { if sn := subNode(xn, "source"); sn != nil { sn.Name.Local = "instance_image" setAttr(sn, "url", "#"+surfaceImages[sn.Value], false) sn.Value = "" } } } for _, sn := range xn.Children { processNode(sn) } }