Esempio n. 1
0
    def process(self):

        count_socket = self.inputs['Count']
        seed_socket = self.inputs['Seed']
        scale_socket = self.inputs['Scale']
        random_socket = self.outputs['Random']

        # inputs
        Coun = count_socket.sv_get(deepcopy=False)[0]
        Seed = seed_socket.sv_get(deepcopy=False)[0]
        Scale = scale_socket.sv_get(deepcopy=False, default=[])[0]

        # outputs
        if random_socket.is_linked:
            Random = []
            param = match_long_repeat([Coun, Seed, Scale])
            # set seed, protect against float input
            # seed = 0 is special value for blender which unsets the seed value
            # and starts to use system time making the random values unrepeatable.
            # So when seed = 0 we use a random value far from 0, generated used random.org
            for c, s, sc in zip(*param):
                int_seed = int(round(s))
                if int_seed:
                    seed_set(int_seed)
                else:
                    seed_set(140230)

                Random.append([(random_unit_vector()*sc).to_tuple() for i in range(int(max(1, c)))])

            random_socket.sv_set(Random)
Esempio n. 2
0
def get_offset(seed):
    if seed == 0:
        offset = [0.0, 0.0, 0.0]
    else:
        noise.seed_set(seed)
        offset = noise.random_unit_vector() * 10.0
    return offset
Esempio n. 3
0
    def process(self):
        inputs, outputs = self.inputs, self.outputs

        if not outputs[0].is_linked:
            return
        
        out = []
        verts = inputs['Vertices'].sv_get()
        seeds = inputs['Seed'].sv_get()[0]
        _noise_type = noise_dict[self.noise_type]
        noise_function = noise_f[self.out_mode]

        
        for idx, (seed, obj) in enumerate(zip(*match_long_repeat([seeds, verts]))):
            # multi-pass, make sure seed_val is a number and it isn't 0.
            # 0 unsets the seed and generates unreproducable output based on system time
            # We force the seed to a non 0 value. 
            # See https://github.com/nortikin/sverchok/issues/1095#issuecomment-271261600
            seed_val = seed if isinstance(seed, (int, float)) else 0
            seed_val = int(round(seed_val)) or 140230

            noise.seed_set(seed_val)
            out.append([noise_function(v, _noise_type) for v in obj])

        if 'Noise V' in outputs:
            outputs['Noise V'].sv_set(Vector_degenerate(out))
        else:
            outputs['Noise S'].sv_set(out)
Esempio n. 4
0
def main(context):
    
    for o in bpy.data.objects:
        if o.name.startswith('generator') or o.name.startswith('Ico') or o.name.startswith('instance'):
            o.user_clear()
            bpy.context.scene.objects.unlink(o)
            bpy.data.objects.remove(o)
    
#    guide = bpy.data.objects['Chemin']
#    ground = bpy.data.objects['Sol']
    guide = bpy.data.objects[bpy.context.scene.ant_guide]
    ground = bpy.data.objects[bpy.context.scene.ant_ground]
    number_ants = bpy.context.scene.ant_number
    start_frame = bpy.context.scene.ant_start_frame
    end_frame = bpy.context.scene.ant_end_frame
    scale = bpy.context.scene.ant_scale
#    ground = bpy.context.selected_objects[-1]
    a_ps = Particle_system(guide, ground, scale)
    a_ps.add_particles(number_ants)
    
    print('\n---')
    start = time()
    seed(0)
    noise.seed_set(0)
    for f in range(start_frame, end_frame+1):
#        a_ps.add_particles(1)
        if f%10 == 0:
            print('frame: {:04}'.format(f))
        a_ps.step()
    print('Simulated in {:05.5f} seconds'.format(time() - start))
Esempio n. 5
0
    def process(self):
        # inputs
        if 'Count' in self.inputs and self.inputs['Count'].links and \
           type(self.inputs['Count'].links[0].from_socket) == bpy.types.StringsSocket:
            Coun = SvGetSocketAnyType(self, self.inputs['Count'])[0]
        else:
            Coun = [self.count_inner]

        if 'Seed' in self.inputs and self.inputs['Seed'].links and \
           type(self.inputs['Seed'].links[0].from_socket) == bpy.types.StringsSocket:
            Seed = SvGetSocketAnyType(self, self.inputs['Seed'])[0]
        else:
            Seed = [self.seed]

        # outputs
        if 'Random' in self.outputs and self.outputs['Random'].links:
            Random = []
            param = match_long_repeat([Coun, Seed])
            # set seed, protect against float input
            # seed = 0 is special value for blender which unsets the seed value
            # and starts to use system time making the random values unrepeatable.
            # So when seed = 0 we use a random value far from 0, generated used random.org
            for c, s in zip(*param):
                int_seed = int(round(s))
                if int_seed:
                    seed_set(int_seed)
                else:
                    seed_set(140230)

                Random.append([random_unit_vector().to_tuple() for i in range(int(max(1, c)))])

            SvSetSocketAnyType(self, 'Random', Random)
def grow_branch(context, branchidx, ivy, bvh=None):
    '''
    Should have two branches maybe.
    Test if only the next coordinate is missing:
        if yes only calculate that one.
        Reduce computation per frame update

        if not recalc spline points from start
        as is done now
    '''
    opt = ivy.ivy
    seed_val = opt.seed + branchidx + 1
    seed(seed_val)
    noise.seed_set(seed_val)

    # GET BRANCH-NUMSTEPS FOR THIS FRAME
    if opt.animated:
        # this is fixed steps along animation range
        anim_frames_total = opt.end - opt.start
        anim_frame_current = context.scene.frame_current - opt.start
        numsteps = int((anim_frame_current / anim_frames_total) * opt.fixed_steps)
    else:
        numsteps = opt.fixed_steps

    # CUTOFF NUMSTEPS
    cutoff = random()
    if opt.steps_random_cutoff <= cutoff:
        # cut this one off
        cutoffamount = (1 - cutoff) * opt.cutoffamount
        cutoff += cutoffamount
        numsteps = int(cutoff * numsteps)

    uvec = noise.random_unit_vector()
    start_co = Vector((uvec.x * opt.root_area.x,
                       uvec.y * opt.root_area.y,
                       uvec.z * opt.root_area.z))
    coords = [start_co]
    #free = [True]

    def recalc_all():
        freefloatinglength = 0
        for step in range(numsteps):
            last_co = coords[-1]
            vec_grow = growvec(opt, coords, bvh, freefloatinglength)
            next_co = last_co + vec_grow
            if opt.has_collider:
                next_co, is_free = collision(opt, last_co, next_co, bvh)
                if is_free:
                    freefloatinglength += (last_co - next_co).length
                else:
                    freefloatinglength = 0
            else:
                freefloatinglength += (last_co - next_co).length

            coords.append(next_co)

    recalc_all()

    return coords
def setup_self(self, context):
    '''
    Setup:
    Set needed Values and prepare and store some data.
    '''
    self.curve = context.active_object
    groups = bpy.data.groups
    names = [n.strip() for n in self.leafgroupname.split(',')]
    self.dupli_groups = [groups[n] for n in names
                         if n in groups]

    #printd(self.dupli_groups)
    seed(self.seed)
    noise.seed_set(self.seed)

    #this is only if the scripts are not together in a moduke
    #if 'curve_ivy_animated' in context.user_preferences.addons.keys():
    self.ivy_loaded = True
    #printd('Animated Ivy Addon loaded ok', self.ivy_loaded)
    self.ivyopt = self.curve.ivy
    #else:
    #self.ivy_loaded = False

    ### CHECK FOR COLLIDER
    selected = context.selected_objects
    if len(selected) == 2:
        collider = [ob for ob in selected if ob != self.curve][-1]
        collider.select = False
        if collider.type == 'MESH':
            bm = bmesh.new()
            bm.from_object(collider, context.scene)
            bm.transform(collider.matrix_world)
            bm.transform(self.curve.matrix_world.inverted())
            bvh = BVHTree()
            bvh = bvh.FromBMesh(bm)
            self.bvh = bvh
    else:
        self.bvh = None

    ### TAKE ANIMATION FROM GROWING IVY IF AVAILABLE
    if self.ivy_loaded:
        if self.ivyopt.added_as_ivy: #was indeed intended as growing ivy
            if self.ivyopt.animated:
                print('taking animation from ivy')
                self.animated = self.ivyopt.animated
                self.start = self.ivyopt.start
                self.end = self.ivyopt.end

    #if no leafgroup found create simple leaf
    if not self.dupli_groups:
        pass
Esempio n. 8
0
    def process(self):
        # inputs
        if (
            "Count" in self.inputs
            and self.inputs["Count"].links
            and type(self.inputs["Count"].links[0].from_socket) == bpy.types.StringsSocket
        ):
            Coun = SvGetSocketAnyType(self, self.inputs["Count"])[0]
        else:
            Coun = [self.count_inner]

        if (
            "Seed" in self.inputs
            and self.inputs["Seed"].links
            and type(self.inputs["Seed"].links[0].from_socket) == bpy.types.StringsSocket
        ):
            Seed = SvGetSocketAnyType(self, self.inputs["Seed"])[0]
        else:
            Seed = [self.seed]
        if (
            "Scale" in self.inputs
            and self.inputs["Scale"].links
            and type(self.inputs["Scale"].links[0].from_socket) == bpy.types.StringsSocket
        ):
            Scale = self.inputs["Scale"].sv_get(deepcopy=False, default=[])[0]
        else:
            Scale = [self.scale]
        # outputs
        if "Random" in self.outputs and self.outputs["Random"].links:
            Random = []
            param = match_long_repeat([Coun, Seed, Scale])
            # set seed, protect against float input
            # seed = 0 is special value for blender which unsets the seed value
            # and starts to use system time making the random values unrepeatable.
            # So when seed = 0 we use a random value far from 0, generated used random.org
            for c, s, sc in zip(*param):
                int_seed = int(round(s))
                if int_seed:
                    seed_set(int_seed)
                else:
                    seed_set(140230)

                Random.append([(random_unit_vector() * sc).to_tuple() for i in range(int(max(1, c)))])

            SvSetSocketAnyType(self, "Random", Random)
def randnum(low=0.0, high=1.0, seed=0):
    """
randnum( low=0.0, high=1.0, seed=0 )
Create random number
Parameters:
low - lower range
(type=float)
high - higher range
(type=float)
seed - the random seed number, if seed is 0, the current time will be used instead
(type=int)
Returns:
a random number
(type=float)
"""

    Noise.seed_set(seed)
    rnum = Noise.random()
    rnum = rnum*(high-low)
    rnum = rnum+low
    return rnum
Esempio n. 10
0
 def update(self):
     # inputs
     if 'Count' in self.inputs and len(self.inputs['Count'].links)>0 and \
         type(self.inputs['Count'].links[0].from_socket) == bpy.types.StringsSocket:
         if not self.inputs['Count'].node.socket_value_update:
             self.inputs['Count'].node.update()
         Coun = eval(self.inputs['Count'].links[0].from_socket.StringsProperty)
     else:
         Coun = [[self.count_inner]]
         
     if 'Seed' in self.inputs and len(self.inputs['Seed'].links)>0 and \
          type(self.inputs['Seed'].links[0].from_socket) == bpy.types.StringsSocket:
         if not self.inputs['Seed'].node.socket_value_update:
             self.inputs['Seed'].node.update()
         
         Seed = eval(self.inputs['Seed'].links[0].from_socket.StringsProperty)[0][0]
     else:
         Seed = self.seed
   
     
     # outputs 
     if 'Random' in self.outputs and len(self.outputs['Random'].links)>0:
         Random = []          
         # set seed, protect against float input
         # seed = 0 is special value for blender which unsets the seed value
         # and starts to use system time making the random values unrepeatable.
         # So when seed = 0 we use a random value far from 0, generated used random.org
         int_seed = int(round(Seed))
         if int_seed:
             seed_set(int_seed)
         else:
             seed_set(140230)  
             
         # Coun[0], only takes first list
         for number in Coun[0]:
             if number > 0:
                 Random.append( [random_unit_vector().to_tuple() \
                                     for i in range(int(number))])
         SvSetSocketAnyType(self,'Random',Random)
Esempio n. 11
0
def noise_gen(coords, props):

    terrain_name = props[0]
    cursor = props[1]
    smooth = props[2]
    triface = props[3]
    sphere = props[4]
    land_mat = props[5]
    water_mat = props[6]
    texture_name = props[7]
    subd_x = props[8]
    subd_y = props[9]
    meshsize_x = props[10]
    meshsize_y = props[11]
    meshsize = props[12]
    rseed = props[13]
    x_offset = props[14]
    y_offset = props[15]
    z_offset = props[16]
    size_x = props[17]
    size_y = props[18]
    size_z = props[19]
    nsize = props[20]
    ntype = props[21]
    nbasis = int(props[22])
    vlbasis = int(props[23])
    distortion = props[24]
    hardnoise = int(props[25])
    depth = props[26]
    amp = props[27]
    freq = props[28]
    dimension = props[29]
    lacunarity = props[30]
    offset = props[31]
    gain = props[32]
    marblebias = int(props[33])
    marblesharpnes = int(props[34])
    marbleshape = int(props[35])
    height = props[36]
    height_invert = props[37]
    height_offset = props[38]
    maximum = props[39]
    minimum = props[40]
    falloff = int(props[41])
    edge_level = props[42]
    falloffsize_x = props[43]
    falloffsize_y = props[44]
    stratatype = props[45]
    strata = props[46]
    addwater = props[47]
    waterlevel = props[48]
    vert_group = props[49]
    remove_double = props[50]
    fx_mixfactor = props[51]
    fx_mix_mode = props[52]
    fx_type = props[53]
    fx_bias = props[54]
    fx_turb = props[55]
    fx_depth = props[56]
    fx_frequency = props[57]
    fx_amplitude = props[58]
    fx_size = props[59]
    fx_loc_x = props[60]
    fx_loc_y = props[61]
    fx_height = props[62]
    fx_offset = props[63]
    fx_invert = props[64]

    x, y, z = coords

    # Origin
    if rseed is 0:
        origin = x_offset, y_offset, z_offset
        origin_x = x_offset
        origin_y = y_offset
        origin_z = z_offset
        o_range = 1.0
    else:
        # Randomise origin
        o_range = 10000.0
        seed_set(rseed)
        origin = random_unit_vector()
        ox = (origin[0] * o_range)
        oy = (origin[1] * o_range)
        oz = (origin[2] * o_range)
        origin_x = (ox - (ox / 2)) + x_offset
        origin_y = (oy - (oy / 2)) + y_offset
        origin_z = (oz - (oz / 2)) + z_offset

    ncoords = (x / (nsize * size_x) + origin_x, y / (nsize * size_y) + origin_y, z / (nsize * size_z) + origin_z)

    # Noise basis type's
    if nbasis == 9:
        nbasis = 14  # Cellnoise
    if vlbasis == 9:
        vlbasis = 14

    # Noise type's
    if ntype in [0, 'multi_fractal']:
        value = multi_fractal(ncoords, dimension, lacunarity, depth, nbasis) * 0.5

    elif ntype in [1, 'ridged_multi_fractal']:
        value = ridged_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis) * 0.5

    elif ntype in [2, 'hybrid_multi_fractal']:
        value = hybrid_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis) * 0.5

    elif ntype in [3, 'hetero_terrain']:
        value = hetero_terrain(ncoords, dimension, lacunarity, depth, offset, nbasis) * 0.25

    elif ntype in [4, 'fractal']:
        value = fractal(ncoords, dimension, lacunarity, depth, nbasis)

    elif ntype in [5, 'turbulence_vector']:
        value = turbulence_vector(ncoords, depth, hardnoise, nbasis, amp, freq)[0]

    elif ntype in [6, 'variable_lacunarity']:
        value = variable_lacunarity(ncoords, distortion, nbasis, vlbasis)

    elif ntype in [7, 'marble_noise']:
        value = marble_noise(
                        (ncoords[0] - origin_x + x_offset),
                        (ncoords[1] - origin_y + y_offset),
                        (ncoords[2] - origin_z + z_offset),
                        (origin[0] + x_offset, origin[1] + y_offset, origin[2] + z_offset), nsize,
                        marbleshape, marblebias, marblesharpnes,
                        distortion, depth, hardnoise, nbasis, amp, freq
                        )
    elif ntype in [8, 'shattered_hterrain']:
        value = shattered_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis)

    elif ntype in [9, 'strata_hterrain']:
        value = strata_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis)

    elif ntype in [10, 'ant_turbulence']:
        value = ant_turbulence(ncoords, depth, hardnoise, nbasis, amp, freq, distortion)

    elif ntype in [11, 'vl_noise_turbulence']:
        value = vl_noise_turbulence(ncoords, distortion, depth, nbasis, vlbasis, hardnoise, amp, freq)

    elif ntype in [12, 'vl_hTerrain']:
        value = vl_hTerrain(ncoords, dimension, lacunarity, depth, offset, nbasis, vlbasis, distortion)

    elif ntype in [13, 'distorted_heteroTerrain']:
        value = distorted_heteroTerrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis, vlbasis)

    elif ntype in [14, 'double_multiFractal']:
        value = double_multiFractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis, vlbasis)

    elif ntype in [15, 'rocks_noise']:
        value = rocks_noise(ncoords, depth, hardnoise, nbasis, distortion)

    elif ntype in [16, 'slick_rock']:
        value = slick_rock(ncoords,dimension, lacunarity, depth, offset, gain, distortion, nbasis, vlbasis)

    elif ntype in [17, 'planet_noise']:
        value = planet_noise(ncoords, depth, hardnoise, nbasis)[2] * 0.5 + 0.5

    elif ntype in [18, 'blender_texture']:
        if texture_name != "" and texture_name in bpy.data.textures:
            value = bpy.data.textures[texture_name].evaluate(ncoords)[3]
        else:
            value = 0.0
    else:
        value = 0.5

    # Effect mix
    val = value
    if fx_type in [0,"0"]:
        fx_mixfactor = -1.0
        fxval = val
    else:
        fxcoords = Trans_Effect((x, y, z), fx_size, (fx_loc_x, fx_loc_y))
        effect = Effect_Function(fxcoords, fx_type, fx_bias, fx_turb, fx_depth, fx_frequency, fx_amplitude)
        effect = Height_Scale(effect, fx_height, fx_offset, fx_invert)
        fxval = Mix_Modes(val, effect, fx_mixfactor, fx_mix_mode)
    value = fxval

    # Adjust height
    value = Height_Scale(value, height, height_offset, height_invert)

    # Edge falloff:
    if not sphere:
        if falloff:
            ratio_x, ratio_y = abs(x) * 2 / meshsize_x, abs(y) * 2 / meshsize_y
            fallofftypes = [0,
                            sqrt(ratio_y**falloffsize_y),
                            sqrt(ratio_x**falloffsize_x),
                            sqrt(ratio_x**falloffsize_x + ratio_y**falloffsize_y)
                           ]
            dist = fallofftypes[falloff]
            value -= edge_level
            if(dist < 1.0):
                dist = (dist * dist * (3 - 2 * dist))
                value = (value - value * dist) + edge_level
            else:
                value = edge_level

    # Strata / terrace / layers
    if stratatype not in [0, "0"]:
        if stratatype in [1, "1"]:
            strata = strata / height
            strata *= 2
            steps = (sin(value * strata * pi) * (0.1 / strata * pi))
            value = (value * 0.5 + steps * 0.5) * 2.0

        elif stratatype in [2, "2"]:
            strata = strata / height
            steps = -abs(sin(value * strata * pi) * (0.1 / strata * pi))
            value = (value * 0.5 + steps * 0.5) * 2.0

        elif stratatype in [3, "3"]:
            strata = strata / height
            steps = abs(sin(value * strata * pi) * (0.1 / strata * pi))
            value = (value * 0.5 + steps * 0.5) * 2.0

        elif stratatype in [4, "4"]:
            strata = strata / height
            value = int( value * strata ) * 1.0 / strata

        elif stratatype in [5, "5"]:
            strata = strata / height
            steps = (int( value * strata ) * 1.0 / strata)
            value = (value * (1.0 - 0.5) + steps * 0.5)

    # Clamp height min max
    if (value < minimum):
        value = minimum
    if (value > maximum):
        value = maximum

    return value
Esempio n. 12
0
def generate_random_unitvectors():
    # may need many more directions to increase accuracy
    # generate up to 6 directions, filter later
    seed_set(140230)
    return [random_unit_vector() for i in range(6)]