Class BlenderFactoryBase

  • Direct Known Subclasses:
    BlenderFactory

    public class BlenderFactoryBase
    extends java.lang.Object
    This is the base class for generated factory classes of a specific blender version.

    Factory classes are part of the utils package and optional. This base class contains the public factory methods to create blocks for facades, arrays and pointers. It also contains utilities to create new blender files in a derived factory class.

    Author:
    homac
    • Field Detail

      • blend

        protected BlenderFile blend
        Blender file associated with this instance of a factory.
    • Constructor Detail

      • BlenderFactoryBase

        public BlenderFactoryBase​(BlenderFile blend)
                           throws java.io.IOException
        Creates a new factory associated with the given blender file. All blocks instantiated by this factory will be allocated in the given blender file.
        Parameters:
        blend -
        Throws:
        java.io.IOException
    • Method Detail

      • getNullPointer

        public static CPointer<java.lang.Object> getNullPointer​(BlenderFile blend)
                                                         throws java.io.IOException
        Create a null pointer object associated with the given blender file. Since pointers have architecture specific properties, they have to be associated with a blender file (which defines the encoding).
        Returns:
        Null pointer object.
        Throws:
        java.io.IOException
      • getNullPointer

        public CPointer<java.lang.Object> getNullPointer()
        Returns a null pointer object associated with the blender file of this factory. Since pointers have architecture specific properties, they have to be associated with a blender file (which defines the encoding).
        Returns:
        Null pointer object.
      • newCStructBlock

        public static <T extends CFacade> T newCStructBlock​(Identifier blockCode,
                                                            java.lang.Class<T> facetClass,
                                                            BlenderFile blend)
                                                     throws java.io.IOException
        Allocate a new block for one instance of a C struct.

        This method allocates a new block in the given blender file and assigns it to a facet of the given class (facetClass).

        Example:
         BlenderFile blend = BlenderFactory.newBlenderFile(new File("my.blend"));
         Scene scene = BlenderFactory.newDNAStructBlock(BlockCodes.CODE_SCE, Scene.class, blend);
         
        Throws:
        java.io.IOException
      • newCStructBlock

        public static <T extends CFacadeCArrayFacade<T> newCStructBlock​(Identifier blockCode,
                                                                          java.lang.Class<T> facetClass,
                                                                          int count,
                                                                          BlenderFile blend)
                                                                   throws java.io.IOException
        Allocate a new block for multiple instances of a C struct.

        This method allocates a new block of apropriate size to fit 'count' instances of the given C struct in the given blender file and assigns it to an array facet of the given class type (facetClass).

        Example:
         BlenderFile blend = BlenderFactory.newBlenderFile(new File("my.blend"));
         CArrayFacade<Scene> scene = BlenderFactory.newDNAStructBlock(BlockCodes.CODE_SCE, Scene.class, 2, blend);
         
        Throws:
        java.io.IOException
      • newCArrayBlock

        public static <T> CArrayFacade<T> newCArrayBlock​(Identifier blockCode,
                                                         java.lang.Class<T> componentType,
                                                         int arrayLength,
                                                         BlenderFile blend)
                                                  throws java.io.IOException
        Allocate a new block for one instance of a one-dimensional array of any non-pointer component type which is either a scalar or a DNA struct.

        This method allocates a new block of appropriate size to fit an array of the given arrayLength and the given componentType in the given blender file and assigns it to an array facet.

        Example:
                        // 1-dim float array with 4 elems
                        CArrayFacade<Float> rgba = BlenderFactory.newDNAArrayBlock(BlockCodes.CODE_DATA, Float.class, 4, blend);
         
        Parameters:
        blockCode - Code of the new block. Frequently ID_DATA for arrays.
        componentType - Component type of the array.
        arrayLength - length of the array
        blend - blender file to add block to.
        Returns:
        CArrayFacade facet to access array data in the new block.
        Throws:
        java.io.IOException
      • newCArrayBlock

        public static <T> CArrayFacade<T> newCArrayBlock​(Identifier blockCode,
                                                         java.lang.Class<?>[] typeList,
                                                         int[] dimensions,
                                                         BlenderFile blend)
                                                  throws java.io.IOException
        Allocate a new block for one instance of a multi-dimensional array of any component type supported by blender.

        This method allocates a new block of appropriate size to fit an array of the given arrayLength and the given component type specification (typeList) and the given lengths for each dimension, in the given blender file and assigns it to an array facade. Refer to CArrayFacade and CPointer to understand the concept of type specifications by type lists.

        Example:
                // 2-dim 4x4 float array
                Class<?>[] typeList = new Class[]{CArrayFacade.class, Float.class};
                int[] dimensions = new int[]{4,4};
                CArrayFacade<CArrayFacade<Float>> mv_mat4x4 = BlenderFactory.newDNAArrayBlock(BlockCodes.CODE_DATA, typeList, dimensions, blend);
                
                // 1-dim array of pointers on bytes (e.g. strings)
                typeList = new Class[]{CArrayFacade.class, CPointer.class, Byte.class};
                dimensions = new int[]{4};
                CArrayFacade<CPointer<Byte>> fileList = BlenderFactory.newDNAArrayBlock(BlockCodes.CODE_DATA, typeList, dimensions, blend);
         
        Parameters:
        blockCode - Code of the new block. Frequently ID_DATA for arrays.
        typeList - type specification for all referenced types
        dimensions - length of each array dimension
        blend - blender file to add block to.
        Throws:
        java.io.IOException
      • newCPointerBlock

        public static <T> CPointer<CPointer<T>> newCPointerBlock​(Identifier blockCode,
                                                                 java.lang.Class<?>[] typeList,
                                                                 BlenderFile blend)
                                                          throws java.io.IOException
        This method creates a block with a single pointer in it. The returned pointer is a pointer on this created pointer. To change the value of that pointer use the method CPointer.set(Object) of the pointer on the pointer.
        Parameters:
        blockCode -
        typeList -
        blend - blender file to add block to.
        Returns:
        a pointer on the pointer stored in the block.
        Throws:
        java.io.IOException
      • newCPointerBlock

        public static <T> CArrayFacade<CPointer<T>> newCPointerBlock​(Identifier blockCode,
                                                                     java.lang.Class<?>[] typeList,
                                                                     int count,
                                                                     BlenderFile blend)
                                                              throws java.io.IOException
        This method creates a block with a set of pointers and returns an array facet to access them. To change the value of the pointers use for example the method CArrayFacade.set(int, Object) of the pointer on the pointer.
        Parameters:
        blockCode - Usually ID_DATA for lists of pointers.
        typeList - type specification of the pointer.
        count - number of pointers to fit in block.
        blend - blender file to add block to.
        Throws:
        java.io.IOException
      • createStructDNA

        protected static StructDNA createStructDNA​(java.lang.String resourcePathTo_sdna_blend)
                                            throws java.io.IOException
        This method provides the StructDNA from a given sdna.blend image resource path. Every generated Java Blend data model has such an sdnaImage resource (to be found in "your/package/name/utils/resources/sdna.blend") which contains just the sdna meta data of the blender version the model was generated from.
        Parameters:
        resourcePathTo_sdna_blend - "your/package/name/utils/resources/sdna.blend"
        Throws:
        java.io.IOException