LoadSkin loads the skin with specified index.
(skinIdx int)
| 272 | |
| 273 | // LoadSkin loads the skin with specified index. |
| 274 | func (g *GLTF) LoadSkin(skinIdx int) (*graphic.Skeleton, error) { |
| 275 | |
| 276 | // Check if provided skin index is valid |
| 277 | if skinIdx < 0 || skinIdx >= len(g.Skins) { |
| 278 | return nil, fmt.Errorf("invalid skin index") |
| 279 | } |
| 280 | skinData := g.Skins[skinIdx] |
| 281 | // Return cached if available |
| 282 | if skinData.cache != nil { |
| 283 | log.Debug("Fetching Skin %d (cached)", skinIdx) |
| 284 | return skinData.cache, nil |
| 285 | } |
| 286 | log.Debug("Loading Skin %d", skinIdx) |
| 287 | |
| 288 | // Create Skeleton and set it on Rigged mesh |
| 289 | skeleton := graphic.NewSkeleton() |
| 290 | |
| 291 | // Load inverseBindMatrices |
| 292 | ibmData, err := g.loadAccessorF32(skinData.InverseBindMatrices, "ibm", []string{MAT4}, []int{FLOAT}) |
| 293 | if err != nil { |
| 294 | return nil, err |
| 295 | } |
| 296 | |
| 297 | // Add bones |
| 298 | for i := range skinData.Joints { |
| 299 | jointNode, err := g.LoadNode(skinData.Joints[i]) |
| 300 | if err != nil { |
| 301 | return nil, err |
| 302 | } |
| 303 | var ibm math32.Matrix4 |
| 304 | ibmData.GetMatrix4(16*i, &ibm) |
| 305 | skeleton.AddBone(jointNode.GetNode(), &ibm) |
| 306 | } |
| 307 | |
| 308 | // Cache skin |
| 309 | g.Skins[skinIdx].cache = skeleton |
| 310 | |
| 311 | return skeleton, nil |
| 312 | } |
| 313 | |
| 314 | // LoadAnimationByName loads the animations with specified name. |
| 315 | // If there are multiple animations with the same name it loads the first occurrence. |
no test coverage detected