/*
 * www.javagl.de - JglTF
 *
 * Copyright 2015-2017 Marco Hutter - http://www.javagl.de
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package de.javagl.jgltf.model;

/**
 * Enumeration of the possible types of elements of an accessor
 */
public enum ElementType
{
    /**
     * The scalar type
     */
    SCALAR(1),
    
    /**
     * The 2D vector type
     */
    VEC2(2),
    
    /**
     * The 3D vector type
     */
    VEC3(3),
    
    /**
     * The 4D vector type
     */
    VEC4(4),
    
    /**
     * The 2x2 matrix type
     */
    MAT2(4),
    
    /**
     * The 3x3 matrix type
     */
    MAT3(9),
    
    /**
     * The 4x4 matrix type
     */
    MAT4(16);
    
    /**
     * The number of components that one element consists of
     */
    private final int numComponents;
    
    /**
     * Creates a new instance with the given number of components
     * 
     * @param numComponents The number of components
     */
    ElementType(int numComponents)
    {
        this.numComponents = numComponents;
    }
    
    /**
     * Returns the number of components that one element consists of
     * 
     * @return The number of components
     */
    public int getNumComponents()
    {
        return numComponents;
    }
    
    /**
     * Returns whether the given string is a valid element type name, and may be
     * passed to <code>ElementType.valueOf</code> without causing an exception.
     * 
     * @param s The string
     * @return Whether the given string is a valid element type
     */
    public static boolean contains(String s)
    {
        for (ElementType elementType : values())
        {
            if (elementType.name().equals(s))
            {
                return true;
            }
        }
        return false;
    }
    
    /**
     * Returns the element type for the given string. If the string is 
     * <code>null</code> or does not describe a valid element type,
     * then <code>null</code> is returned
     * 
     * @param string The string
     * @return The element type
     */
    public static ElementType forString(String string)
    {
        if (string == null)
        {
            return null;
        }
        if (!contains(string))
        {
            return null;
        }
        return ElementType.valueOf(string);
    }
    
}

@@ -2390,32 +2390,1527 @@
 %0A    %0D%0A    /**%0D%0A
+     * Obtains the byte stride that is implied for this element type with%0D%0A     * the given component type, %3Cb%3Eincluding%3C/b%3E any padding bytes that%0D%0A     * may have to be inserted for matrix types.%0D%0A     * %0D%0A     * According to the specification (section 3.6.2.4, Data Alignment),%0D%0A     * padding bytes may have to be inserted after each column of matrix:%0D%0A     * %3Cul%3E%0D%0A     *   %3Cli%3E%0D%0A     *     For 1-byte component types and MAT2 elements, two padding bytes%0D%0A     *     have to be inserted after each column%0D%0A     *   %3C/li%3E%0D%0A     *   %3Cli%3E%0D%0A     *     For 1-byte component types and MAT3 elements, one padding byte%0D%0A     *     has to be inserted after each column%0D%0A     *   %3C/li%3E%0D%0A     *   %3Cli%3E%0D%0A     *     For 2-byte component types and MAT3 elements, two padding bytes%0D%0A     *     have to be inserted after each column%0D%0A     *   %3C/li%3E%0D%0A     * %3C/ul%3E%0D%0A     * %0D%0A     * @param componentType The component type%0D%0A     * @return The byte stride%0D%0A     */%0D%0A    public int getByteStride(int componentType)%0D%0A    %7B%0D%0A        int n = Accessors.getNumBytesForAccessorComponentType(componentType);%0D%0A        if (n == 1)%0D%0A        %7B%0D%0A            if (this == MAT2)%0D%0A            %7B%0D%0A                return 8;%0D%0A            %7D%0D%0A            if (this == MAT3)%0D%0A            %7B%0D%0A                return 12;%0D%0A            %7D%0D%0A        %7D%0D%0A        if (n == 2)%0D%0A        %7B%0D%0A            if (this == MAT3)%0D%0A            %7B%0D%0A                return 24;%0D%0A            %7D%0D%0A        %7D%0D%0A        return numComponents * n;%0D%0A    %7D%0D%0A    %0D%0A    /**%0D%0A
      * Returns w

Add method to obtain byte stride with padding for element type