<commit_before>"""Loader module: contains the Loader class"""

from PandaModules import *
from DirectNotifyGlobal import *

# You can specify a phaseChecker callback to check
# a modelPath to see if it is being loaded in the correct
# phase
phaseChecker = None

class Loader:

    """Loader class: contains method to load models, sounds and code"""

    notify = directNotify.newCategory("Loader")
    #notify.setDebug(1)
    modelCount = 0
    
    # special methods
    def __init__(self, base):
        """__init__(self)
        Loader constructor"""
        self.base = base
        self.loader = PandaLoader()
        
    # model loading funcs
    def loadModel(self, modelPath, fMakeNodeNamesUnique = 0):
        """loadModel(self, string)
        Attempt to load a model from given file path, return
        a nodepath to the model if successful or None otherwise."""
        Loader.notify.debug("Loading model: %s" % (modelPath) )
        if phaseChecker:
            phaseChecker(modelPath)
        node = self.loader.loadSync(Filename(modelPath))
        if (node != None):
            nodePath = NodePath(node)
            if fMakeNodeNamesUnique:
                self.makeNodeNamesUnique(nodePath, 0)
        else:
            nodePath = None
        return nodePath

    def loadModelOnce(self, modelPath):
        """loadModelOnce(self, string)
        Attempt to load a model from modelPool, if not present
        then attempt to load it from disk. Return a nodepath to
        the model if successful or None otherwise"""
        Loader.notify.debug("Loading model once: %s" % (modelPath))
        if phaseChecker:
            phaseChecker(modelPath)
        node = ModelPool.loadModel(modelPath)
        if (node != None):
            nodePath = NodePath(node)
        else:
            nodePath = None
        return nodePath

    def loadModelOnceUnder(self, modelPath, underNode):
        """loadModelOnceUnder(self, string, string | node | NodePath)
        Behaves like loadModelOnce, but also implicitly creates a new
        node to attach the model under, which helps to differentiate
        different instances.

        underNode may be either a node name, or a NodePath or a Node
        to an already-existing node.

        This is useful when you want to load a model once several
        times before parenting each instance somewhere, or when you
        want to load a model and immediately set a transform on it.
        But also consider loadModelCopy().
        
        """

        Loader.notify.debug("Loading model once: %s under %s" % (modelPath, underNode))
        if phaseChecker:<commit_msg>fix loadModelOnce() to work if the model has been instanced previously<commit_after>"""Loader module: contains the Loader class"""

from PandaModules import *
from DirectNotifyGlobal import *

# You can specify a phaseChecker callback to check
# a modelPath to see if it is being loaded in the correct
# phase
phaseChecker = None

class Loader:

    """Loader class: contains method to load models, sounds and code"""

    notify = directNotify.newCategory("Loader")
    #notify.setDebug(1)
    modelCount = 0
    
    # special methods
    def __init__(self, base):
        """__init__(self)
        Loader constructor"""
        self.base = base
        self.loader = PandaLoader()
        
    # model loading funcs
    def loadModel(self, modelPath, fMakeNodeNamesUnique = 0):
        """loadModel(self, string)
        Attempt to load a model from given file path, return
        a nodepath to the model if successful or None otherwise."""
        Loader.notify.debug("Loading model: %s" % (modelPath) )
        if phaseChecker:
            phaseChecker(modelPath)
        node = self.loader.loadSync(Filename(modelPath))
        if (node != None):
            nodePath = NodePath(node)
            if fMakeNodeNamesUnique:
                self.makeNodeNamesUnique(nodePath, 0)
        else:
            nodePath = None
        return nodePath

    def loadModelOnce(self, modelPath):
        """loadModelOnce(self, string)
        Attempt to load a model from modelPool, if not present
        then attempt to load it from disk. Return a nodepath to
        the model if successful or None otherwise"""
        Loader.notify.debug("Loading model once: %s" % (modelPath))
        if phaseChecker:
            phaseChecker(modelPath)
        node = ModelPool.loadModel(modelPath)
        if (node != None):
            nodePath = NodePath.anyPath(node)
        else:
            nodePath = None
        return nodePath

    def loadModelOnceUnder(self, modelPath, underNode):
        """loadModelOnceUnder(self, string, string | node | NodePath)
        Behaves like loadModelOnce, but also implicitly creates a new
        node to attach the model under, which helps to differentiate
        different instances.

        underNode may be either a node name, or a NodePath or a Node
        to an already-existing node.

        This is useful when you want to load a model once several
        times before parenting each instance somewhere, or when you
        want to load a model and immediately set a transform on it.
        But also consider loadModelCopy().
        
        """

        Loader.notify.debug("Loading model once: %s under %s" % (modelPath, underNode))
        if phaseChecker:
{'fraction_non_alphanumeric': 0.07315247895229186, 'fraction_numerical': 0.0014967259120673526, 'mean_word_length': 2.431322207958922, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6411887', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1359, 'n_words': 537}