diff --git a/struct.go b/struct.go index 1b6e903..efb1d58 100644 --- a/struct.go +++ b/struct.go @@ -504,11 +504,6 @@ func (n *NormalTexture) MarshalJSON() ([]byte, error) { return out, err } -// NewOcclusionTexture returns a default OcclusionTexture. -func NewOcclusionTexture(index int32) *OcclusionTexture { - return &OcclusionTexture{Index: index, Strength: 1} -} - // An OcclusionTexture references to an occlusion texture type OcclusionTexture struct { Extensions Extensions `json:"extensions,omitempty"` @@ -518,6 +513,11 @@ type OcclusionTexture struct { Strength float64 `json:"strength" validate:"gte=0,lte=1"` } +// NewOcclusionTexture returns a default OcclusionTexture. +func NewOcclusionTexture(index int32) *OcclusionTexture { + return &OcclusionTexture{Index: index, Strength: 1} +} + // UnmarshalJSON unmarshal the texture info with the correct default values. func (o *OcclusionTexture) UnmarshalJSON(data []byte) error { type alias OcclusionTexture @@ -537,8 +537,8 @@ func (o *OcclusionTexture) MarshalJSON() ([]byte, error) { if o.Index == -1 { out = removeProperty([]byte(`"index":-1`), out) } - if o.Strength == -1 { - out = removeProperty([]byte(`"strength":-1`), out) + if o.Strength == 1 { + out = removeProperty([]byte(`"strength":1`), out) } out = sanitizeJSON(out) } @@ -577,11 +577,11 @@ func (p *PBRMetallicRoughness) MarshalJSON() ([]byte, error) { type alias PBRMetallicRoughness out, err := json.Marshal(&struct{ *alias }{alias: (*alias)(p)}) if err == nil { - if p.MetallicFactor == -1 { - out = removeProperty([]byte(`"metallicFactor":-1`), out) + if p.MetallicFactor == 1 { + out = removeProperty([]byte(`"metallicFactor":1`), out) } - if p.RoughnessFactor == -1 { - out = removeProperty([]byte(`"roughnessFactor":-1`), out) + if p.RoughnessFactor == 1 { + out = removeProperty([]byte(`"roughnessFactor":1`), out) } if p.BaseColorFactor == [4]float64{1, 1, 1, 1} { out = removeProperty([]byte(`"baseColorFactor":[1,1,1,1]`), out) diff --git a/struct_test.go b/struct_test.go index cbac045..2bb74fc 100644 --- a/struct_test.go +++ b/struct_test.go @@ -785,9 +785,9 @@ func TestOcclusionTexture_MarshalJSON(t *testing.T) { want []byte wantErr bool }{ - {"default", &OcclusionTexture{Index: -1, Strength: -1}, []byte(`{}`), false}, + {"default", &OcclusionTexture{Index: -1, Strength: 1}, []byte(`{}`), false}, {"empty", &OcclusionTexture{Index: 0, Strength: 0}, []byte(`{"index":0,"strength":0}`), false}, - {"nodefault", &OcclusionTexture{Index: 1, Strength: 1}, []byte(`{"index":1,"strength":1}`), false}, + {"nodefault", &OcclusionTexture{Index: 1, Strength: 0.5}, []byte(`{"index":1,"strength":0.5}`), false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -810,9 +810,9 @@ func TestPBRMetallicRoughness_MarshalJSON(t *testing.T) { want []byte wantErr bool }{ - {"default", &PBRMetallicRoughness{MetallicFactor: -1, RoughnessFactor: -1, BaseColorFactor: [4]float64{1, 1, 1, 1}}, []byte(`{}`), false}, + {"default", &PBRMetallicRoughness{MetallicFactor: 1, RoughnessFactor: 1, BaseColorFactor: [4]float64{1, 1, 1, 1}}, []byte(`{}`), false}, {"empty", &PBRMetallicRoughness{MetallicFactor: 0, RoughnessFactor: 0, BaseColorFactor: [4]float64{0, 0, 0, 0}}, []byte(`{"baseColorFactor":[0,0,0,0],"metallicFactor":0,"roughnessFactor":0}`), false}, - {"nodefault", &PBRMetallicRoughness{MetallicFactor: 1, RoughnessFactor: 1, BaseColorFactor: [4]float64{1, 0.5, 1, 1}}, []byte(`{"baseColorFactor":[1,0.5,1,1],"metallicFactor":1,"roughnessFactor":1}`), false}, + {"nodefault", &PBRMetallicRoughness{MetallicFactor: 0.5, RoughnessFactor: 0.5, BaseColorFactor: [4]float64{1, 0.5, 1, 1}}, []byte(`{"baseColorFactor":[1,0.5,1,1],"metallicFactor":0.5,"roughnessFactor":0.5}`), false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {