text:
register group of properties 2.8
I'm updating my addon to 2.80 and I'm stuck with the new register class system. I try to follow the answer here but I'm not good enough as a coder to understand the solution.
The problem comes to register my group properties of my UI panel, here is my code:
import bpy
from bpy.props import (StringProperty,
                   BoolProperty,
                   IntProperty,
                   FloatProperty,
                   EnumProperty,
                   PointerProperty
                   )
from bpy.types import (Panel,
                   Operator,
                   PropertyGroup
                   )

class MySettings(PropertyGroup):

    path : StringProperty(
        name="path",
        description="Path to Directory",
        default="",
        maxlen=1024,
        subtype='DIR_PATH')

    conform_threshold : FloatProperty(
        name="conform_threshold",
        description="A float property",
        default=0.1,
        min=-5,
        max=30.0)

    invert : BoolProperty(
        name="Enable or Disable",
        description="A simple bool property",
        default = False)

class UI_PT_LynchonPanel(bpy.types.Panel):
    """Las super herramientas de Juan"""
    bl_label = "Lynchon Tools"
    bl_space_type = 'VIEW_3D'
    bl_region_type = "UI"
    bl_category = "Lynchon Tools"

    def draw(self, context):
####################Y UP##################################
        layout = self.layout
        row = layout.row()
        row.operator("object.y_up")

         # Create two columns, by using a split layout.####################MET COMPILER##################################

        split = layout.split()
        # First column
        col = split.column()
        col.operator("texture.metal_compiler")

        scn = context.scene
        mytool = scn.my_tool
        col = split.column(align=True)
        col.prop(mytool, 'invert' ,text = "Invert")

        # Create two columns, by using a split layout. ####################LOW POLY VENUE##################################
        split = layout.split()

        # First column
        col = split.column()
        col.label(text="Import Venue")
        col.operator( "xml.lowpolygeneratorparticles")

        # Second column, aligned
        col = split.column(align=True)
        col.label(text="Conform Venue")
        col.operator( "xml.conform_lp_venue")

        # root for export
        scn = context.scene
        mytool = scn.my_tool
        col = layout.column(align=True)
        col.prop(mytool, "path", text="")

        # Create two columns, by using a split layout.  ####################CONFORM HEIGHT##################################
        split = layout.split()

        # First column
        col = split.column()
        col.operator("xml.conformheight")

        # Second column, aligned
        scn = context.scene
        mytool = scn.my_tool
        col = split.column(align=True)
        col.prop(mytool, "conform_threshold")

def register():
    bpy.utils.register_class(UI_PT_LynchonPanel)
    bpy.utils.register_class(MySettings)
    bpy.types.Scene.my_tool = PointerProperty(type=MySettings)

def unregister():
    bpy.utils.unregister_class(UI_PT_LynchonPanel)
    bpy.utils.unregister_class(MySettings)
    del bpy.types.Scene.my_tool

And the error I'm getting back is this one:
    location: <unknown location>:-1
Traceback (most recent call last):
  File "C:\Users\Juan\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\Lynchon_tools280\UI.py", line 63, in draw
    mytool = scn.my_tool
AttributeError: 'Scene' object has no attribute 'my_tool'

and if I'm not wrong the problem has to do with a register the classes, isn't it?
EDIT
Here my init file which registers all my scrits:
    import bpy

from . UI import UI_PT_LynchonPanel, MySettings
from . xml_parse_conformHeight import XML_OT_conformheight
from . xml_parse_particles import XML_OT_conformLpVenue, XML_OT_lowPolyGeneratorParticles
from . y_up import LynchOperator
from . metal_compiler import metal_compiler

classes = (UI_PT_LynchonPanel, MySettings, XML_OT_conformheight, XML_OT_conformLpVenue, XML_OT_lowPolyGeneratorParticles, LynchOperator, metal_compiler)

register, unregister = bpy.utils.register_classes_factory(classes)

Your code didn't run the register() at all, that's the problem

@Hikariztw it will depend on how it was run. The error implies it has been registered as it is failing in the panel code. Notice It is in the addon path, the register method of an addon  module is called when enabled.  Quite likely the OP needs to run bpy.ops.script.reload() to update changed addons. (this had the shortcut F8 in 2.7x and before).  Or restart blender.  Adding the main thread if at bottom is standard and good practice since it will register the addon in text editor.  Quite often not so useful in an __init__.py where relative imports will fail.

yes sorry about that, already edited the code

What IMO you want to do is from . import UI and in __init__.py register method  call UI.register() otherwise your custom property will not be registered. (hence the issue)

That did work, properties were registered correctly but operators got messed up, I'm getting this error for each operator: C:\Users\Juan\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\Lynchon_tools280\UI.py:83 rna_uiItemO: operator missing srna 'object.y_up'

It is the UI equivalent of  bpy.ops.object.y_up() could not be found in py console.  Not Registered.... Put a register method in your y_up module and do same.

That is what confuses me, all my operators are registered in their own scripts like this:
classes = (LynchOperator,) register, unregister = bpy.utils.register_classes_factory(classes)   I thius case LynchOperator  is the class whith "object.y_up" idname

.. and that method needs to be called when registered my addon module, same as the way mentioned with UI.  The factory creates the method, it still needs to be called. Related and possible duplicate https://blender.stackexchange.com/questions/128824/how-to-register-a-property-group-in-blender-2-8  As mentioned ditch the factory and add custom register method to each module IMO makes things much simpler.

Did you register it?
EDIT re __init__.py
What IMO you want to do is from . import UI and in __init__.py register method  call UI.register() otherwise your custom property will not be registered. (hence the issue seen) Also IMO Ditch using the register factory, it's not that helpful
from . import UI

def register():
    UI.register()

This will call the register method of the UI module.
Former answer below.
Grabbed your code to format it for question edit, added the if __name__ == "__main__" bit to make it register if run in main thread (eg text editor) and ran it and it works fine (apart from not having your custom operators hence the missing buttons in image below)

Edited code.
import bpy
from bpy.props import (StringProperty,
                   BoolProperty,
                   IntProperty,
                   FloatProperty,
                   EnumProperty,
                   PointerProperty
                   )
from bpy.types import (Panel,
                   Operator,
                   PropertyGroup
                   )

class MySettings(PropertyGroup):

    path : StringProperty(
        name="path",
        description="Path to Directory",
        default="",
        maxlen=1024,
        subtype='DIR_PATH')

    conform_threshold : FloatProperty(
        name="conform_threshold",
        description="A float property",
        default=0.1,
        min=-5,
        max=30.0)

    invert : BoolProperty(
        name="Enable or Disable",
        description="A simple bool property",
        default = False)

class UI_PT_LynchonPanel(bpy.types.Panel):
    """Las super herramientas de Juan"""
    bl_label = "Lynchon Tools"
    bl_space_type = 'VIEW_3D'
    bl_region_type = "UI"
    bl_category = "Lynchon Tools"

    def draw(self, context):
        layout = self.layout

        scn = context.scene
        mytool = scn.my_tool
        row = layout.row()
        row.operator("object.y_up")

        split = layout.split()
        # First column
        col = split.column()
        col.operator("texture.metal_compiler")

        col = split.column(align=True)
        col.prop(mytool, 'invert' ,text = "Invert")

        split = layout.split()

        # First column
        col = split.column()
        col.label(text="Import Venue")
        col.operator( "xml.lowpolygeneratorparticles")

        # Second column, aligned
        col = split.column(align=True)
        col.label(text="Conform Venue")
        col.operator( "xml.conform_lp_venue")

        # root for export
        col = layout.column(align=True)
        col.prop(mytool, "path", text="")

        # Create two columns, by using a split layout.
        split = layout.split()

        # First column
        col = split.column()
        col.operator("xml.conformheight")

        # Second column, aligned
        col = split.column(align=True)
        col.prop(mytool, "conform_threshold")

def register():
    bpy.utils.register_class(UI_PT_LynchonPanel)
    bpy.utils.register_class(MySettings)
    bpy.types.Scene.my_tool = PointerProperty(type=MySettings)

def unregister():
    bpy.utils.unregister_class(UI_PT_LynchonPanel)
    bpy.utils.unregister_class(MySettings)
    del bpy.types.Scene.my_tool

if __name__ == "__main__":
    register()

Note I do not use the blender development addon for vscode from Jaques Lucke,

You are right, it does run from the text editor, that means is a problem from my _init_ file?, please check my edit in the original question.

lol please see my comment under question.

I'm using the blender development addon for vscode from Jaques Lucke, it should update the addon just by saving

I'm sorry to keep bothering you with this issue, but I cant manage to make it right. As you stated adding the def register(): in my __init__ does the job but not from the start, I need to move it after and before my classes register factory then reupdate the addon in order to get everything registered correctly.  I know it doesn't make much sense.


text:
create gaps between spline points with animation nodes
Following this answer  curve intersection with volume in animation nodes, I've managed to create a spline which i use to distribute objects inside a volume.
Here is how:

But I still need to avoid having distributed objects along the spline when this one gets outside the volume along the gap
:
How can it be done? I've tried substracting those points (outside volume) from the ones that are generating the spline that is used to distribute the objects but as it now look obvious the spline will still be generated. So my second option is to do it inside the distribution objects loop but don't know how, any ideas?

EDIT
AS @Omar Ahmad proposes finding inside points is straight forward using BVHTREE but this way we cant control the distance between the volume faces and the points.
EDIT 2
@Omar Ahmad solution does the job but putting the tool to some tricky situations give inconsistent results like this ones:

I'll be trying the other solution proposed, far more complex, which I'm already struggling to replicate.

Do you plan to animate either curve or volume, and if yes, how should the points behave then? E.g. If the gap increases, would the drawn points move closer together or would some of them suddenly disappear? And would the number of intersections stay constant or is it variable?

Neither curve o volume are going to be animated but as I'm building this a tool for "parametric object placing" everything should be updated anytime something changes. The tool should work like this:  from a list of objects I need to distribute them along an spline EVENLY only through the segments which are inside a given volume. All objects in this list (which can vary in length) have to be distributed and cannot be just hidden. Please ask if I'm not being clear.

This answer will be using the technique described in my answer here. After getting the parameters of the intersections, we prepend it with zero and append it with 1 representing the start and end of the spline respectively. The prepended list represents the starting parameters of the sub-splines between intersection points while the appended list represents the ending parameters. We can generate those sub-splines by trimming as follows:

We can then loop over the sub-splines, evaluate a point in the middle and see if it is inside the object or not, if yes, we append the spline:

And that is it, you now have the interior splines which you can evaluate to get what you want. For instance:

the problem with this method is that I don't have control over the distances between the intersection of the spline with the volume and the points.

@JuanManuelLynch Edited the answer, is this what you are looking for?

Sorry for the delay, I've been busy. Your solution does the job but after putting it into some stress situations I get inconsistent results. Check my edit. I'm going to try @binweg approach.

@JuanManuelLynch There might be a better simpler approach to all this, but it may not be as straightforward as the method we have been using. Will write an answer soon.

Oh that would be great, this solutions may not be perfect but just taking the time to reproduce and understand them is giving me so much knowledge, thanks. I´ll try my own approach also

@JuanManuelLynch May we know what is not perfect about this new solution?

my apologies, I was answering your first comment(from 20h ago). I'm reading your new answer right now

due to some problems with your original method (which I answered he link I'm not able to reproduce your solution

@JuanManuelLynch Did you manage to make it work? Do you want me to upload a file for you to inspect?

Well that is just perfect, the question has been answered. The file is not necessary I prefer to reproduce it myself so I can at least try to understand what I'm doing.  But may ask one more thing? Right now each interior spline is distributing the same amount of points in between, is it posible to give a fixed number of points to be shared between those splines? so given a distance factor if there is not enough space for a certain number of points it jumps to the next one

@JuanManuelLynch Sure, compute the length of each sub-spline $L_i$ and add them to get a total length $L_t$, lets say you want to distribute $N$ points in total, so you write a ratio to compute the number of points to distribute on each sub-spline $n$:
$$
\frac{L_i}{L_t} = \frac{n}{N}
$$
Giving you the equation $n = \frac{L_i \cdot N}{L_t}$ where $n$ is the number of points for each sub-spline, $L_i$ is the length of the sub-spline and $L_t$ the total length of all sub-splines.

Thanks! I'll try it myself. Don`t know what I would have done without your help

Its been a while since I implemented this method into my workflow and new issues have emerged using this solution. Everything works as expected right now just as it was  explained but only if the intersecting Spline is made up of two control points. Right now I'm building the splines from mesh objects so they are filled up with control points, this produces weird artifacts, is there a way around to solve this issue?

My attempt at this problem is quite similar to Omar Ahmad's answer in that I calculate the spline parameter of the intersections – i.e. their positions along the spline's length in the range of zero to one – and use this value for the placement.

(Visible hollow copy only for demonstration purposes. Origial filled box used for calculations is hidden)
As a first step, I modify the Raycast loop of the node tree for the intersections to return the parameter and a boolean that gives information about the angle of normal and segment, and through that, whether the intersection is an entry into or an exit from the volume. In my setup, False means entry and True means exit.
The additional parameter spline length comes from a Get Spline Length node of the spline.

With an expression node list(zip(x, y)) I convert the two lists into one list of pairs, one for each intersection. For example
[(False, 0.2),
 (True,  0.5),
 (False, 0.6),
 (True,  0.9)]

To handle the spline's ends, I check for the first and the last point on the spline whether they are in the volume (BVH Tree > Is Inside Volume) and add a expression that will later interpret these points as additional entries or exits.
If there is always at least one intersection, one could invert the first and last boolean of the list, but checking Is Inside Volume also works when there is no intersection.

This will end up as something like this:
[(True,  0),
 (False, 0.2),
 (True,  0.5),
 (False, 0.6),
 (True,  0.9)
 (False, 1)]

Similarly to the two slices vectors[:-1] and vectors[1:] in the tree to find the intersections, I create two slices tuples[:-1] and tuples[1:] and feed them into another loop.

The Create Splines loop checks whether each segment is inside of the volume based on the supplied boolean values, adjust the parameters of start and end by a given value to “prevent” (in some cases) the objects to appear directly at the wall or even clip into it, and check whether the adjusted segment is even long enough to hold any object.

While Omar Ahmad at this point continues to work with the parameters, I return a trimmed copy of the original spline (iff the spline is inside the volume and the segment is long enough).
The list of splines is fed into a final loop sample splines, along with a float number to set the average number of items to place per unit. From the loop's Evaluate Spline node we can extract location, tangents for the rotation etc.

Using the segments' length and the ceiling function gives a rather regular distribution of objects, but it complicates things if you want a fixed number of objects. Maybe algorithms commonly used to assign seats to politicians after elections like the Sainte-Laguë method can be used, considering the lengths of the segments. Or you simply tweak the average until you're happy with the total. :P
The number of placed objects depends on the length of the segments:

The distance of the first objects from each wall, or the average number of objects per unit can be adjusted, though the distance from a wall is calculated along the spline and might be misleading (a.k.a. wrong) for shallow angles:

As mentioned above, the node tree should work for no intersections as well. For splines completely enclosed in the volume (with objects) or splines completely outside (no objects):

Unfortunately, it won't work for cyclic splines.
N.B.: By default, the resolution of the Evaluate Spline nodes, which can be set in the advanced node settings in the properties panel of the node, is quite low. This resulted in an uneven distribution for me. Increasing the resolution solved this problem.
My .blend file for Animation Nodes v2.1:

this is huge! Ok I'm trying to replicate your solution, I even updated to v2.1, but as some of the nodes are collapsed  is taking me a wile. For instance the "create pairs node" is self explicatory but somehow I cant find any vector list operation with two outputs.

My fault, sorry. Create Pairs is a group of the two list slices [:-1] and [1:] that also appeared in the find intersections node tree. I initially grouped them as I intended to reuse the group on the right. But that didn't look as good as originally thought as there was a type mismatch (Vector List vs Generic List) that would have required additional Convert Type nodes. I forgot to get rid of the node group.

I noticed your two additional test cases and might add, that this answer also doesn't work for zero-width gaps, or more than one intersection per original segment. For the second test case, this might also have to to with the resolution of the Evaluate Spline nodes that I mentioned. Failing the first test case might be avoidable by not using Ray Cast but instead checking whether start and/or end of the segment are inside the volume (which could be done for both Omar Ahmad's solution as well as mine).

even if this one was not the perfect solution it did what it was asked and  also shares a big amount of knowledge, Im will also accept it as an answer.

Thanks, but apart from the variable number of objects in my answer, which is also implementable in the other answer, I too think that Omar Ahmad's answer is the superior one and I wouldn't mind if you accepted that answer. Props when it's due :)

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Sub Surf and triangles
Some of you might have seen my earlier question about how to make an edge in the hood of my car. I have now got that looking nice but with one exception: the edges of where the crease merges with the car have to be triangles as far as i am aware, which is causing subsurf to do some weird calculations. I have tried deleting and reentering the faces but that has not seemed to help.

Actually, Cole, they may not have to be triangles, only have to look like triangles. What I would do (I think), is to recast the triangles as quads where two of the vertices of the quad exactly co-incide, giving four vertices, and four edges, even though one of the edges has a length of zero.
Though not in this exact circumstance, this is a trick I have used in the past to good effect, though I've not tested it exhaustively, and it may not work, or may work with unanticipated side effects, in some cases.

Generally, when modelling with the intention to use subdivisions later, it's advisable to stick to quads as much as possible, as @brasshat has suggested, since quads produce predictable subdivisions, whereas tris, as you have experienced do not.
In your instance, it's a bit difficult to decipher what your intended result is.
If you would like to remove some faces, you could have an extra loop cut. If you have two loop cuts close to one another in the center and then remove the intended faces. For further control you can play with edge crease settings.

Initial quad mesh

Removing the desired faces

Subdivided mesh
If you would like to create a sharp edge, you could play with the edge crease settings, and creating loop cuts that are very close together.

Quad mesh with extra loops cuts and crease settings changed

(FYI, As @David has mentioned, any comments related to a specific answer should go as a comment below the answer which you would like to discuss. This makes it easier to build an accurate reference catalogue of questions and answers that others can reference later)

Thank you for your reply. I decided rather than doing that just to mask the problem by putting a loop cut either side which while it does not fix it hides it pretty well. If any one has any other suggestions that would be appreciated but for now this seems to be a quick fix.

this is better suited as a comment. Why did you delete it and then switch to an answer?

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

authors: Андрей Мосеенков


text:
Baked normal map from high poly bad corners
I'm trying to bake a normal map from a high polygon model to a low polygon one.
It's a very simple domino shape. When I use the normal on the blender render, I get this strange shape at the border of the shape

I'm not really sure what I'm doing wrong. Is the low poly shape not detailed enough? Is it too big or too small?
Here is the link to the .blend.

Edit:
OK, after Mr Zak's answer I managed to understand why the baking was not creating a normal in the correct size. It was because both objects didn't have the same scale. I've applied the scale for both objects and now the normal and diffuse bake seemingly correctly.
Unfortunately, I still have the issue with the result not being as I expected

As you can see, it goes all the way to the borders now, but it has a weird shape.
For the record, this is my high poly

As you can see, the UVs are well inside the normal map, and for the diffuse it's a simple blue diffuse.

I really don't understand what I'm doing wrong with the way I bake the high poly to the low poly. could it be that my low poly is too low poly?
Here's an updated .blend.

Let's start with vertext normals of smooth and solid shaded mesh:

Now see this diagram how baking works and projects the high-poly to lowpoly:

In each corner of your domino piece you see 3 corners baked, because of Repeated details. You can fix this by making the lowpoly domino shade smooth - that way there will be only 1 vertex normal in each corner, so you won't get overlaps and multiple projections:

If you want your domino silhouette to look better, you will have to add mode polygons. See: How can a Normal Map affect the look of a model?
There is also very comprehensive wiki about normals which might help: Polycount Normal map (the pictures are from there).

Excellent answer, and some very pretty diagrams!

Putting the shading to smooth does indeed fix the issue. And with your excellent answer I know understand the reason why it was not working as I expected. Thanks.

You can actually extend this answer quite a bit - in other workflows, you might well need to split those edges instead; the most important thing is that your target mesh when you're projecting the bake, has the same vertex normals as your final low poly that you're displaying the normal map on. here are some useful links:
http://polycount.com/discussion/81154/understanding-averaged-normals-and-ray-projection-who-put-waviness-in-my-normal-map/p1
http://oldwiki.polycount.com/NormalMap
http://polycount.com/discussion/147227/skew-you-buddy-making-sense-of-skewed-normal-map-details/p1

That red border is red material assigned to model and seen through diffuse map.
If you look closely at the "Diffuse" texture when UV map selected, you can notice that there are regions where UV map is larger than the texture:

These areas will be visible on the model:

And because of alpha-transparency presented in image, the black areas, marked on the screenshot, will be transparent, revealing everything underneath. So you'll see the material (which has red color as diffuse):

Note that deleting alpha-transparency won't help: those areas will become simply black.

Possible solutions might be to create (or edit this) image which should be a little larger so to have several pixels border around UV map.

Thanks for the help, it was definitely part of the problem, but not all. I now have another issue. I've edited my question with where I am now with the issue. Thanks for your help.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
How to add a working navigation mesh and path finding to a maze in blender game engine?
I have generated a maze:
Top view in wireframe:

Solid view:

For a game I'm making, I need the enemy to follow the player around the maze, but when I try to generate a navigation mesh, nothing happens. (It says theres a Navmesh, but it doesn't seem to be made.

share the blend file through http://www.pasteall.org/blend/

@Lev Ok: http://www.pasteall.org/blend/36502

Your mesh is not recognized by blender.It pops an error.
It seems like it was corrupted.
I tried changing it by deleting all the top vertices(there are also 4 vertices I think a bit missplaced) but even with the basic scaled plane, the same error pops.
I created a new plane in your file and it worked just fine. I don't know if it is fixable without remaking it from scratch though.
This guy here disagrees: same error

Could it be corrupted because I generated it with a python script? @Lev

I haven't done this to know. But in the blender artist's archive a guy mention the use of an add-on might cause this. And add-ons are like scripts so it could be possible that a script has messed it some how. Start a new blend file, run the script again. Try to generate the mesh. If it fails again, then it could be it.


text:
Custom Menu for bpy.context
I am working on making a custom menu that would allow access to things like Cycle Render, Blender Render, changing file formats for render outputs, etc.
I understand how to make menus using operators like
layout.operator("rigidbody.objects_add", text="Add as Active"). type = 'ACTIVE'
Is the process for creating menus for bpy.context.scene similar or am I missing some basic understanding of python and how Blender works?
UPDATE....
In the info panel I am trying to execute this.
 bpy.context.scene.render.engine = 'CYCLES'

I am using this template from cgcookie.
EXAMPLE
import bpy

# Creates a menu for global 3D View
class customMenu(bpy.types.Menu):
    bl_label = "Sub"
    bl_idname = "view3D.sub"

    # Set the menu operators and draw functions
    def draw(self, context):
        layout = self.layout

        layout.operator("rigidbody.objects_add", text="A Add Active").type = 'ACTIVE'
        layout.operator("rigidbody.objects_add", text="B Add Passive").type = 'PASSIVE'
      # here is were I would like to add a menu item to change to cycles.

def register():
    bpy.utils.register_class(customMenu)
    bpy.ops.wm.call_menu(name=customMenu.bl_idname)

def unregister():
    bpy.utils.unregister_class(customMenu)

if __name__ == "__main__":
    register()

care to show a mock-up it's difficult to be confident about what the question is, or the desired result.

You want to have a look at the ops.wm.context_... family of operators, which are 'generic' operators that can be used to define a value (or cycle through a set of values) of any compatible property accessible through context. This avoid the need to define a custom operator.
E.g. for an enum property like context.scene.render.engine:
import bpy

# Creates a menu for global 3D View
class customMenu(bpy.types.Menu):
    bl_label = "Sub"
    bl_idname = "view3D.sub"

    # Set the menu operators and draw functions
    def draw(self, context):
        layout = self.layout

        layout.operator("rigidbody.objects_add", text="A Add Active").type = 'ACTIVE'
        layout.operator("rigidbody.objects_add", text="B Add Passive").type = 'PASSIVE'
        op = layout.operator("wm.context_set_enum", text="Set Cycles Renderer")
        op.data_path = "scene.render.engine"
        op.value = 'CYCLES'

def register():
    bpy.utils.register_class(customMenu)
    bpy.ops.wm.call_menu(name=customMenu.bl_idname)

def unregister():
    bpy.utils.unregister_class(customMenu)

if __name__ == "__main__":
    register()

Note that you can also use layout.prop() and the like, just like in a regular panel - but beware, most of our widgets are not really designed nor tested in menus… Afaik in 'official' UI we only do that for some boolean properties (giving small toggle boxes in the menus). Seems to work rather well with enums, though, producing a sub-menu:
import bpy

# Creates a menu for global 3D View
class customMenu(bpy.types.Menu):
    bl_label = "Sub"
    bl_idname = "view3D.sub"

    # Set the menu operators and draw functions
    def draw(self, context):
        layout = self.layout

        layout.operator("rigidbody.objects_add", text="A Add Active").type = 'ACTIVE'
        layout.operator("rigidbody.objects_add", text="B Add Passive").type = 'PASSIVE'
        layout.prop(context.scene.render, "engine")

def register():
    bpy.utils.register_class(customMenu)
    bpy.ops.wm.call_menu(name=customMenu.bl_idname)

def unregister():
    bpy.utils.unregister_class(customMenu)

if __name__ == "__main__":
    register()

In the info panel I am trying to execute this.  "bpy.context.scene.render.engine = 'CYCLES'
import bpy
class customMenu(bpy.types.Menu):
bl_label = "Sub"
bl_idname = "view3D.sub"
def draw(self, context):
    layout = self.layout

layout.operator("rigidbody.objects_add", text="A Add Active").type = 'ACTIVE'
layout.operator("rigidbody.objects_add", text="B Add Passive").type = 'PASSIVE'
layout.operator("rigidbody.objects_remove", text="C Remove from Rigid")
# add this
layout.context("scene.render").engine = 'CYCLES'

@Mark Please edit your question rather than adding precisions in comments, this is not even readable. Also, assuming you are doing this in draw code, you will not be allowed to change anything (any data) in such part of the code…


text:
How to non-destructively bevel and extrude a mesh intersection?
In Blender 2.93/2.92, I am looking for ways to more easily create hard surface structures with doorways/archways that are extruded above the surface, in a non-destructive way that allows for quick prototyping.
When trying to use the bevel modifier on a boolean object, the bevel profile only cuts in to the surface.  Is there a way to use modifiers to get the beveled edges to extrude above the base surface, using the boolean modifier?
Reference screenshots.

A cube with some extra lines cut into a face. Faces inset where hole is desired.
Extruded the boundary face-loop above the original surface. Extruded the inset faces below the original surface
Unsuccessful attempt at creating this non-destructively. Bevel after boolean difference only cuts "in" to the surface, does not create any geometry "above" the surface

I still don't understand exactly what you're trying to do, or failing to do. Maybe instead of providing a pair of distant, goal-based, before-and-after shots, you could provide a sequence of close-up, procedure-based, step-by-step shots.

I've updated the original post with some more screenshots.Hopefully they better illustrate the problem I am trying to solve.

If I understand your problem correctly, you should be able to solve this by using the bevel modifier limited to a vertex group.
First, go to the Object Data tab in the properties pane (the green one, can't miss it) and open Vertex Groups.  Hit the "+" button to create one.

Then, select the vertices you want to bevel in Edit mode.  While the group you just created is selected, click the "Assign" button underneath the vertex group list.

Third, go to the Modifiers tab (the one with the wrench) and add a Bevel modifier.  In the "Limit Method" drop-down, select Vertex Group.

Finally, select the vertex group you created earlier.  Play with the numbers a bit, and you should be good!

I appreciate the information, but the question isn't really about the basics of the bevel modifier, its about a specific use case - making the new geometry come out both above and below the plane of the specified edges, and doing it based on the intersection between two meshes, instead of manually modeling the the base shape.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Plot graphs and play animation with bpy or bge
I want to capture emg signals and through a dll plot a graph in  blender and run animations in a virtual arm(based on certain values dll). Should I use Blender Game Engine (using bge) or just run a script in Blender Render? Any idea how can I do this?

What you use will depend on what result you want to have.
You would most likely use the game engine if you want to watch your animation in real-time as the data is collected.
You would use a render engine (whether that is BI, Cycles, Luxrender...) if you want to capture the data then render the animation and watch the video you made hours or days after you captured the data. You can also do this in two stages, capture the data to file and then use that data to create the animation in blender. This options also gives you the flexibility to clean up or enhance the animation before you render the final video.
It is also possible to combine real-time viewing with an after the fact video. To do this you would have your script moving items in the 3dview as it is recording the animation for later rendering. Note that recording the animation for later adds some overhead that may slow down your "live" playback depending on the scene complexity.
This answer provides an example of collecting data from an external process without blocking blender. I expect it can be adapted for use in either scenario.


text:
Shading problem only when normal map is applied
I have a very odd problem. My model looks perfectly fine with diffuse map on it and in Substance Painter too, but when I put my normal map on it it shows dark polys. The normals are in the right direction and I also tried to change the smoothing settings. But nothing worked. This never happened at my other models, only at the cars. (There are two more, where this issue is happening).
This dark patches also are shown in our own engine. I suspect there is something wrong with the tangent space, but I don't know much about this stuff. I tried to export it as FBX with Tangent Space checked on, but this doesn't helped either.
How you can see, the normal map is also fine. The place where the door sits is flat and shadeless blue.
Please can anybody help? This is very important for my work.

can you add a pic with the normal map + your uv map on it ? that could help.

sure, here it is (see above)

I just noticed that the shading problem is on the mesh even when the normal map is off. But way more weaker. It is only visible in certain angles and lighting.

So you may share some screen captures of you material ?

what do you mean?

I mean that if it is not directly or only due to the normal map, that can be or due to the material, or the mesh itself (but for the mesh you said you had checked the normals)

The material is the standard blender material with lesser hardness. Unsmooth shading occurs often at seams, but here it is only at the door and the front. I tried to cut the door out and make it to a new single object, but this didn't help either. It is still darker than the rest.

I think this is not due to the door, you can notice a difference also at the front and the back of the car (at the bottom). Is it the same if you render it ? Can you share your file here http://blend-exchange.giantcowfilms.com/ ?

I am not allowed to give files away. I know that it isn't only at the door, it was an example. cause i think it is really strange that the problem doesn't disappear when the door becomes a new object. Especially cause the door is only a plane. I want to try another programm like max, maybe it is a blender issue.
And yes it is the same if i render it. In Blender render and in Cycles.


text:
v2.77a - Textured object not updating when manually changing UV coordinates
I am experimanting with texturing simple objects. My idea is to use very small textures. So I manually resized and moved the UV coordinates to be inside the pixels. You can see on the screenshot I have uploaded.

Unfortunately they do not seem to update. I have zero idea why, any hints or tips will be appreciated.
[Edit]: I have put all obj faces that should be red over the red in the texture (neatly arranged without overlapping). I have moved all the faces that should be black on the top (this time I did not arrange them as it did not help with the red).
I expect all front and back of the cross to become red and the sides to be black.

It's difficult to tell what you're seeing, that you don't expect to see. If you can try to provide more information about what you see that is unexpected, that'd be helpful. I'll type up a quick answer about the most common reason.

Which Blender version are you using ? (I don't have the exact same buttons on the bottom of the image texture part, and all is moving perfectly fine for me)

Generally, white color on mesh in textured mode in Blender Internal means there's no texture on it (or no UV map mapping it to the texture). So check that white faces were unwrapped and that they were applied to UV map you set up (not another one).

How do I check "they were applied to UV map you set up (not another one" ?

Here is how to do it with Cycles:
http://blender.stackexchange.com/questions/8697/how-do-i-put-an-image-texture-on-a-material-in-cycles

The easiest and fastest way would be to unwrap once more. I meant that faces marked as white could be added / extruded after UV map was made or they were unwrapped into another map. Check UV maps you have and islands presented there.

If you're using Cycles, you will also have to have the image mapped to a material node (like a diffuse or something) before it will show up properly in the Viewport.
Try setting up the material nodes the way they should be, and see if the texture updates better.
The other thing that might be causing this is if your texture is set to repeat. If it's repeating, then when you move a UV island outside the red area, it will still be red. It might be updating... you just can't tell.

I am using normal blender engine just to avoid dealing with shader nodes.

I want to say that BI does something similar, where you have to actually set up the material before it'll display properly... but it's been so long since I've used BI...

Am I not supposed to use Blender Enginge? I am bit confused.

There's nothing wrong with using Blender Internal. It's still supported, and I think it's still being developed, too. I much prefer Cycles, so I use it exclusively.


text:
Video Editing - Send a strip to another scene same project file

I am trying to do some video editing and I want to send a metastrip or strip from one scene to another scene. But copy and paste doesn't work because it do not copy the curve animations, just the strips and all the fade in and out are gone. Is there another way to send a video strip from one scene to another scene?
Attached image: from the scene in red "logo" to the scene in blue "Scene_01".

I already found it! Well, I'll leave it here if someone else has the same issue:
In SEQUENCER just click on ADD> SCENE> Choose your scene. In the right panel on the "STRIP" tab go to SCENE and change the INPUT to SEQUENCER insted of camera. Done.


text:
Applying Two Different Materials on 2 Sides of a Face
I have to apply two different materials on the two different sides of a face. I know how to use double sided materials (with two different pricipled bsdf shaders and a geometry node connected to a mix node), but in this case I will have a single material behaving differently on the 2 sides. I need 2 different materials on the two sides of the face to import the model in substance painter.
Is there any chance to apply the two different materials on the two sides or the only chance is to produce a double sided single material?

No, every face has exactly one material. Can you use two faces right on top of each other instead?

Use two different UV maps and assign the material coordinates so that each material is mapped with a unique UV map


text:
Animation nodes vector animation interpolation
Im moving a large quantity of objects from point A - B by animating their vectors in a loop with animation nodes. I have everything setup how I want it to be. But instead of going from point A to B in a linear path, I want to interpolate the Z axis to add some up and down curvature to the stream of objects path as they move towards point B. This seems like a fairly simple task but I have been stumped for quite some time. All I've been able to do is alter the timing as they continue linearly. Thanks to anyone who can help!
(Apologies for the terrible illustration I only have access to my phone at the moment and can't stop wracking my brain on how to solve the issue)

EDIT: I was able to accomplish this on an older version of animation nodes by separating z from the vector, feeding it through a map range node with the interpolation I want, recombining it, and then using it as my start in an animate vector node, but since updating I have not been able to achieve the effect this way. Any similar or alternative methods are appreciated!

I'm not using Animation Nodes, but the basic principle is simple: whatever weight w controls how close you're to A, and how far you're to B, result = A*w + B*(1-w), can be passed to some kind of a function like sine to output the Z position: z = sin(w*pi)*max_z.
Below a geometry nodes setup, where I'm using Vector curves for a more arbitrary control than a mathematical function:

Here the aliases for w are % and Fac on the Mix node (that node effectively does the lerping described in the first formula in this post). However, instead of interpolating calculating Z based on %, I'm lerping between Z = -1 and Z = +1, because that's the default Curves horizontal (input) range. This is then translated to a curve with outputs in range [0; 1], and then I multiply the Z component of the vector by 4 to make the effect more visible (range becomes [0; 4]).


text:
animation nodes sorting object list by XYZ
I have a 3x3x3 grid of objects in a collection (intended to be used with non-duplicate objects), I want to sort them by x y and z and have them fed into a loop and animate transformations. I previously did this with index id keys and 3 sort list nodes; one for each axis fed through each other. but the sort list node has since been removed hence why I'm stuck.
I've tried separating the list vectors, running them each through an expression node with sorted(e) but but I'm stuck at how to take X list and sort it by Y, and then Y by Z. any solution or help is greatly appreciated :)
Download my .blend
this is all working except it lacks the control im looking for as to what axis and direction the process begins with

rather than it going from left to right, I want the control to set it so the order is back to front, and then upwards
EDIT: after many hours of tweaking i finally came to a solution using the expressions given to me by gorgious and some extra tweaks:

I used gorgious's method nearly exactly but before feeding the object list into the expression nodes, I created 3 sets of id keys for each axis, input them with object id key nodes, combined them into a vector list and output them into an object transforms output node. the result is full control over direction of animation.

I think you almost got it. I initially started designing loop subprograms but the sorted method and the expression nodes are your friends.
Remember you can chain expression nodes. Add an input of type "Object List"
The 3 expression nodes you should write are like so :

The 3 lines of code:
sorted(objs,key=lambda obj:obj.location[0])
sorted(objs,key=lambda obj:obj.location[1])
sorted(objs,key=lambda obj:obj.location[2])

To visualize it, create a loop subprogram to change the viewport color of the object depending on their order in the new, sorted list.

Add the subprogram at the end of your expression nodes :

Result :

Additionally, as a stand-alone python script :
import bpy

objs = bpy.data.objects; # Replace by relevant objects or collection
for axis in (0, 1, 2):
    objs = sorted(objs, key=lambda obj: obj.location[axis])

objs_len = len(objs)
for i, obj in enumerate(objs):
    fac = i / objs_len
    obj.color = (fac, 1 - fac, 0, 1)

Edit after comment asking for another way to sort the list (right to left, back to front, bottom to top)
You just have to add a slice operator at the end of the 2 first expression nodes to reverse the list : [::-1] See this doc for example (example 2)
So the expressions become :
sorted(objs,key=lambda obj:obj.location[0])[::-1]
sorted(objs,key=lambda obj:obj.location[1])[::-1]
sorted(objs,key=lambda obj:obj.location[2])

Result :

is there any way to use this method but with more control over what direction the sorting starts with? ie starting with +y +x and -z (bottom of structure) then building along the x axis, completing a row then progressing down the y axis, once theres no objects left along Z then moving up a slice if that makes sense

See my edit at the end of the answer, you can use [::-1] to reverse a list. I did not fully understand the order in which you want things to appear but also know that you can rearrange the expression nodes to rearrange the sorting. With these informations you should be able to do it

AN have Sort Numbers node.You can use that to sort any number list, for example sort x list of vectors by its y list.


text:
Random vertex selection
When ever I make selections in Blender to select some vertices it select some random vertices with it which is not even close.
I am not able to edit any vertex without looking at wire frame mode I edit after making sure that none other vertex are selected
Which is very time taking and frustrating and even create lots of misplacement I just use box select and this thing happen

I tried to restart pc
Tried to save as another blend file
Tried to disable anti aliasing from preference>viewport

hello, could you please show a screenshot or even an animated gif of what's happening?

Hi and welcome :) Would you please add at least an image or two or a gif showing the problem? This will help make your question a bit clearer for other users to understand. Thanks :) I've also taken the liberty of making a small edit to your post, to make it a little easier to read. Feel free to roll it back if you disagree with the change :)

Try to turn off antialiasing in the preferences (this is in viewport tab, quality section).


text:
Smooth Step Function with Math Nodes
i've recently hit a wall trying to create a smooth stepped function.
Here is what i'm trying to replicate:

Where the rising line would represent a single float output.
I've found something on Math.stackexchange that i think could suit my needs, but my math knowledge is far too limited to try and convert what i've found there into a simple function that i can replicate with math nodes.
I've got a regular stepped function working, but the "switching" is a hard cut atm.
I'm trying to divide a color ramp in equal spacings, where the output color would be "clamped" to an increment, but not like "constant", it should blend to the next color so to say. The output would be remapped to fit the input value for the ramp.
It obviously would be possible to do it manually, but i need it a bit more automated.
Hope what i'm trying to do is understandable.
Has anyone got an idea :)?
Thanks in advance.

The basic idea is to use
$$\mathrm{floor}(x) + \mathrm{smooth}(\mathrm{fract}(x))$$
where

floor(x) is the floor, an unsmoothed step function
fract(x) is the fractional part of x
smooth(x) is the smoothing function of your choice, defined on the interval [0,1]. For continuity, we require smooth(1) = smooth(0) + 1.

or as nodes

where I used a Float Curve node to supply the smoothing function. This produces the following output.

As you can see, this is just a bunch of shifted copies of the smoothing function stuck together.
You can modify this by

Replacing the smoothing function to change the "shape" of the steps.
Scaling and shifting the input to change the width of the steps and the locations of the "jumps".
Scaling and shifting the output to change the height of the steps and the offset of the graph.

Thank you! Thats amazing, i was hoping i could use a visual way to change the "curve" :) Its far simpler then i thought!

@scurest Hello! Would you mind sharing the Mathematical intuition behind your Smoothed Floor function? Why did you add Floor and Smoothed out version of Fraction (for example, SmoothStep Interpolated version of Fraction)? -------- For me, it looks like you made the Floor first, then you found a way of Smoothing out the sharp transitions of Floor by adding a small value (close to zero) to the sharp edges and add 1 to both the values on the left (e.g. 1) and right (e.g. 2) of those sharp edges...

@IanAmbrose That's about right. By definition x = floor(x) + fract(x), eg. 2.3 = 2 + 0.3. Applying a function to the fractional part changes the shape of the graph as it goes from 0.0 to 1.0.

@scurest ...The point of adding values close to zero to the sharp edges seem to be keeping the values there to be close to 2 (i.e. the value on the left of the sharp edge: 1 after adding 1 from the SmoothStep Interpolated values) to have a smooth transition between the left and right side of the sharp edge, smooth transition from 2 (left of sharp edge) to 3 (right of sharp edge).

@scurest Oh wow, didn't expect you to reply this quickly. Thank you!


text:
How do you change the materials of linked instances stored in another blend file?
I'm creating roughly 15 product models with several color variation as well as product sets.
I am having a problem as one product can be used to sell in a set with other products for example, or one product can have up to 8 color variations.  As we've continued our work, I'm asked to make a tweak to the model itself, or perhaps the color is a little off and I need to tweak the color, now I have a nightmare of a problem because I have to go and locate every single product model, and update several models, and several materials across multiple blend files!!
So I'm learning about creating instances and linking to the product models and materials stored in other files.  So for example, I now have each product model, stored in it's own blend file.  I also have a separate blend file which stores all the materials.  I'll go to File>Link, locate the product blend file and link the collection from that file that make up the model.
I do the same for the materials, File>Link, locate the materials blend file and select all the Materials in the Materials folder.
Now I have another problem.  I have no way to change the materials of the linked models!  In fact!  There is no material panel at all!
I do also see the materials available if I create a sphere for example, and I can change the material to one of the linked materials.  So I know they have imported and still remain linked.
I can also go into the master blend files and make changes to the model and materials and they update!
So I'm half way there.  I've figured out how to import the linked models and materials.  But I cannot figure out how to change the linked model's material.
So to clarify, I need to know, how do I "unlink" the material from the linked model only, and change it to one of the link materials I've imported instead?  All while being able to make tweaks to the model and material master blend files and have them update properly?

If you just want to change the color and not the actual surface appearance, consider rendering to OpenEXR and setup some cryptomattes, this way you only have to render one time and can color each part of the model in Fusion, Nuke or Natron or whatever. Otherwise there are new override features: https://www.blender.org/download/releases/2-91/#paragraph-plus-block_5fbb97dea33ad Have you tried 2.91 yet?

Thank you @brockmann  The override feature was exactly what I was looking for! For anyone needing clarification, in object mode, you select the object, then Object>Relations>Make Library Override.  I'm trying to figure out how to mark your comment as the answer, but do not see the way.

This is what worked for me.
I have two master blend files.  One containing the materials, which are specific to the product.  And another one of the product model.
When I create a new blend file to create a scene with the product using the materials, I need to be able to update the master files and see them update in the new blend file. For example, when I show the final scene to the client and they want you to make a tweak to one of the materials, or a tweak to the product model, I would be able to go to the master blend files, make the tweaks and any other blend file that is linked will automatically update.

This is how I set it up:
First I need to create a link to the model or material

Then I navigate to the master blend file for that model and import it.  Here I have the product saved as a collection, so I select the collection the model contains:

I repeat the same steps to import the materials, except this time I navigate to the materials folder inside the blend file and select all the materials I want to link:

Next I make sure the model is selected and while in Object Model I go to Object>Relations>Make Library Override and confirm:

Now I can access the materials panel, but in order to update the material to one of the linked materials I have to switch it from Data to Object:

Now if I click the icon to change the material, I now have access to my linked materials and can update the models material in the scene:

Now if I need to make a tweak to the material or model, I can open either of those master blend files, make the tweaks and save.  If I'm working with the current scene and master files and have two instances of Blender open, I can force an update by doing the following:
First I change the outliner from View Layer to Blend File:

I scroll the outliner to the bottom until I see the two linked files, indicated by the link chain icon.  I right click one of those and select reload.  Then it updates the scene to reveal the latest tweaks!


text:
blender file screen got cut in half
My Blender file opens in this weird way, it's with this file, the only i can do with that top screen, is slide the side windows to it, but when i slide those back it creates this trippy stuff it only happens with this one file, what should i do about it?

https://blender.stackexchange.com/a/207626/110840  https://blender.stackexchange.com/a/165915/110840

https://blender.stackexchange.com/questions/8384/how-can-i-reset-my-menus

Try this:

Open new scene File → New → General

File → Open and in the file browser open side panel using gear icon in the right top corner:

Uncheck Load UI

Now choose the file and open it. The data should be loaded, keeping interface untouched.


text:
Can i bake Toon shader (Shader to RBG) to a texture?
i made a cartoon model and now i need to create the textures to import to another game, but as you seen in the title, it's using Shader to RGB.
I tried to bake it with emission and emit in cycles but everything comes up black.

You cannot bake shader-to-RGB, because it is unsupported by Cycles.  There are compositing tricks you can do, but they're not going to help you here, because a toon shader is going to be either view or lighting dependent or both.  Baking it will not give you anything that is view or lighting dependent.  If you're trying to import to a game engine or a game with shader modding support, you should be looking at recreating your toon material in that game's shaders.  If you're trying to import to an existing game with limited modding support, you're kind of out luck.

Aw, that's sad, well, thank you for replying anyways!


text:
Fire-Animation export to gltf (Domain visible)
I have created a fire animation which I can also render.
Unfortunately when exporting to gltf the domain solid is visible.
Is there any way to export this fire animation to gltf / glb to use it e.g. in three.js ?
I attach my export settings as a screenshot.
[

You mention domain, i guess you mean you made a fire simulation? I don't think gltf supports that. That would be the job of VDB.

try selecting the fire first with its baked animation and on export, click on "selected objects" under "limit to"


text:
Cell fracture issue (missing pieces)
As you can see in the link, my cell fracture isn't working correctly. The bust sculpt had a lot of subdivisions so i started to add an decimate modifier. But when i added the cell fracture it is missing pieces. I also tried to ad a solidify modifier first but that also doesn't work. In the pictures you can also see the settings of the cell fracture. if you know to solve this with the right settings let me know :)
https://i.sstatic.net/Yd0b2.jpg

You can reduce the number of segments by reducing the "Source Limit" value in the CF panel. (in earlier versions that's just under the "Own Vertices" button at top left)  As far as coping with missing bits and extruding extras, you can conceal these by substituting the CF'd segments with a copy of the original, scaled up a little.  (switch the CF'd version to invisible until the fracturing is to take place.  When it does, visually switch back to the CF'd model.

PS to the above...  The 1st video clip at the link below uses the original model to hide the Cell Fractured one until the impact point.
Link -
https://blender.stackexchange.com/questions/226766/how-do-i-pin-a-ball-to-a-cloth-sim-rope-to-create-wrecking-ball/227382#227382


text:
Blender rendering at 2x speed
I hard cut a video into two segments and deleted the middle. Then I put in a fade to black and rendered out the video. Playing back the rendered file is fine up until the fade to black. After which it doubles the speed of the remainder of the video and has a bunch of black frames appended to the end.
I have not added any speed modifiers and have even tried re-doing the edit with both soft and hard cuts. Scrubbing through the video in the editor does not have this same problem. Everything works fine in the preview just not in the output.

Could you provide a sample blend file with this strange effect?

One way is to change the render settings to be 2x your source - so if your source is 30fps change the render to 60fps.  This will read all the frames but display at 2x the rate.


text:
How to make arrayed objects have independent rotation
How should I go about making an array (Modifier) of objects have independent rotation? The base has a "Locked Track" constraint to an empty, but if I move the empty (to move rotate the base) it only changes the direction of the array. This is the setup:

You will have to construct the array differently. You can do this with Sverchok or Animation nodes.

I don't think you can do that, what about create your object, then add your Constraint, then link duplicate your object with alt D, and shift R to repeat your duplication


text:
How to make grooves without editing geometry
I'm trying to cut grooves onto a curved surface without directly editing the geometry.
This is my desired end result that I achieved by Ctrl+B to bevel and E to extrude down (Exactly what I don't want to do).

Is there a way I can do this with modifiers or something like that?
I will occasionally need to edit the fine details of the mesh and I can't do it whilst these grooves are physically preset, and I need them there for reference. I also can't bake a normal map for it because the materials are geometry defined and my change too.
Thanks in advance.

You can add a groove using a boolean modifier.
My process would be as follows:
Duplicate some faces from your original, then separate them into another object.

Scale them down, and extrude out some thickness to get the inverse of the groove you want:

Add a boolean modifier on the first object set to difference, and select the new object as the target:

Then, just hide the second object to see the groove:

You could make your extrusion mechanically, as you have, but to 0 height, make a vertex group from the extruded vertices, and aim a Displace modifier at it, followed by a Weld to disappear it when you set the displacement to 0.

Advantages over the Boolean given by @person ? Not many.. unless the Boolean is playing up because of necessarily coincident faces
Disadvantages .. you can only edit the unmodified mesh, which contains doubled vertices.

So probably, the Boolean is better.


text:
Render large 3D graphs (Millions of vertices & edges)
I need to somehow render several large 3D graphs where each vertex has a position in 3D as well as edges between some of these vertices. I have an XML file with the graph structure (a list of vertices with corresponding id and position as well as a list of edges given as two vertex ids each) and wrote a script to import vertices as spheres and edges as cylinders. This is working fine for up to 100k vertices & edges but importing millions takes way too long (several days).
I am already using low-level operations, creating one sphere (with minimal segment and ring count) and copying that sphere for each vertex in the list. Only afterwards I update the scene:
# Example data:
node_dic = {0: (0,0,0), 1: (0,1,1), 2: (0,1,0), 3: (1,0,0), 4: (1,1,1)}

# Generate base sphere:
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.mesh.primitive_uv_sphere_add(location=(0,0,0), segments=3, ring_count=3)
ob = bpy.context.object
ob.scale = [0.003, 0.003, 0.003]

# Copy object for each item in the dictionary:
for node_id, node_pos in node_dic.items():
    copy = ob.copy()
    copy.data = ob.data.copy()
    loc = np.array(node_pos)
    copy.name = 'node-' + str(node_id)
    generated_nodes[node_id] = copy

# Create vertex group:
group_name = "vertices"
groups = bpy.data.groups
vertex_group = groups.get(group_name, groups.new(group_name))

# Link vertices to group
for ob in list(generated_nodes.values()):
   if ob.name not in vertex_group.objects:
        vertex_group.objects.link(ob)

# Update scene with group instance:
scene = bpy.context.scene
group = bpy.data.groups[group_name]
instance = bpy.data.objects.new(group_name, None)
instance.dupli_type = 'GROUP'
instance.dupli_group = group
scene.objects.link(instance)
scene.update()

I am doing the same for the cylinders representing the edges of the graph with the additional complication that they have to be rotated properly. As mentioned before this doesn't scale.
Thus my question, is there a better way to achieve something like this? A completely different approach maybe or some optimization I am not aware of?

I guess you could lump many pieces into one object to improve performance. Another idea: create your data as one subdivided plane, and then use modifiers to display it with your spheres & cylinders.

From what I understand, dupliverts and particles are more efficient than instances for really large numbers of repeats. Might want to give these a try.

I thought about dupliverts too and I can see that working for the vertices but as far as I understand getting the cylinders in the right orientation is not straight forward with dupliverts is it? @HENDRIX The lumping might work, but right now it's so slow that I suspect it will not help much. I don't really understand your second suggestion, could you elaborate?

It's basically the dupliverts idea. Just write your data into one mesh grid, and then visualize it with blender tools. I think there was a modifier for this as well, not sure...

@HENDRIX is there a benefit to using a plane+displacement, rather than adding all of the nodes as vertices in one mesh, already at their 'final' locations?

The plane was just metaphorical - indeed, better create the verts from your data directly

Okay, thanks everybody! What I ended up doing:

From the vertex & edge lists create a mesh via python api:
# Create mesh & object
mesh = bpy.data.meshes.new("mesh")
obj = bpy.data.objects.new("graph", mesh)

scene = bpy.context.scene
scene.objects.link(obj)
scene.objects.active = obj
obj.select = True

mesh = bpy.context.object.data
bm = bmesh.new()

# Example data - replace with parser
node_dic = {0: (1,0,0), 1: (0,1,0), 2: (0,0,1), 3: (1, 1, 0)}
edge_list =[(0,1), (1,2), (2,3), (3,0)]
index_map = {}

# Add vertices to object:
for node_id, node_pos in node_dic.items():
    pos = np.array(node_pos)
    v = bm.verts.new(pos)
    index_map[node_id] = v

# Add edges to object:
for edge in edge_list:
    bm.edges.new((index_map[edge[0]], index_map[edge[1]]))

bm.to_mesh(mesh)
bm.free()

This allows for very fast import of rather large graphs (several million vertices and edges). Now for visualizing the vertices as spheres or anything else use dupliverts (https://docs.blender.org/manual/en/dev/editors/3dview/object/properties/duplication/dupliverts.html) on that object.
Visualize the edges between nodes by adding a material to the object.

Could you add a screenshot of what the result looks like?

You could possibly speed it up with mesh.from_pydata(verts, edges, faces), instead of repeatedly adding a vertex via bmesh API.


text:
How to sum up point value within associated geometry?
I've got two faces raycasting from theirs points against cube's geometry.
If there is a hit, then a whole face should inherit hit status, so left face with one point inside cube should return "1" (in Viewer output it is "1" for a point and "0" for a face in yellow framed area).
In order to do it, I should calculate total amount of hits on each casting face or mesh island.
With no luck I tried Transfer Attribute node and Attribute Statistics.

@quellenform, question was about accumulating points' "hit status" on a source polygon. So, Accumulate Field node solved this issue.

Accumulate Field allows to collect data within specified geometry groups input - Group Index.
I want to get total amount of ray hits on each source face, so have to get proper indices first (Capture Attribute with face option) or Mesh Island ID for a whole separated geometry and plug it to Group Index.
You can accumulate not only points, but edges and faces as well, just make sure Group Index is valid.


text:
How To Model Ornamental Grass Procedurally
I am trying to model an ornamental grass procedurally (Miscanthus sinensis 'Gracillimus'). I want to be able to do this procedurally (not combing for example) because, unlike normal grass, it has a lot of strands with a specific form and I still want to be able to adjust it quickly to make variations or similar plants.
As shown in the screenshot, I tried using hair dynamics, which approaches the result I want. But despite that I just can't get it right using this method.
My knowledge of hair dynamics and physics isn't yet adequate enough. Maybe someone knows the best practices to accomplish the creation of this plant?

Not sure reading your question about what could be good or bad in the hair model? Is that kind of thing you are looking for? https://i.sstatic.net/PqFnD.jpg

Sorry for not being clear. Yes indeed, the outer ones of your image are the thing I'm looking for. In my model the strands flare out almost inmediatally which prevents the right form. Meanwhile I'm making progress and it is going the right way. I wasn't using the Pin Goal Strength which was the main reason it did not work well. But I can still use the help. How did you do it?

I've used keyed (see in physics) particles (not hair but emitter) with path rendering. The idea is to propagate the particles from a shape to another (in the image I've upload 3 shapes per plant). So particles will start at the first then go to the 2nd and finally reach the third. As each step is "the mesh you want" you can control nearly all rapidly.

Seems like a good method. You mean like this: https://www.youtube.com/watch?v=UgmJsLcLXUI but then with path rendering?

Yes, same principal but with path. The one I did in the image is based on a disk for the first, an half sphere for the second and a half sphere opened at the top for the third. From that, just move them, rotate, scale, deform them as you want to make variations.

Great! I have to do some research because I've never used particle emitters before, could you point me in the good direction with an excisting tutorial or some explanation?

I would recommend something like Blender Guru's Fur tutorial. It covers most of the hair settings, and it might work well for your grass: https://www.youtube.com/watch?v=EVj1fETtuN8

@Lemon, it would be great if you could make an answer to explain in detail, thanks!  ;)

@moonboots, was thinking about it. but this one should be a long one and not compatible with other things for the moment. If you have time, feel free to do it: https://blend-exchange.giantcowfilms.com/b/6316/ (2.8, bad lines are due to a bug I think... reenter edit mode for each key object to make it disappear). Also I wanted to find a good and short way to go to curves (model on the left and right) but for now nothing very good I think.

ok, if you ever have time then  ;)

Thanks for the upload, I will look into it when I have the time. I think I now know how to make it work with hair particles also. When I have had the time to make it work I will post it as an answer. @Lemon if you have the time to post an detailed answer it would be very welcome. I don't want to rush you.

Thanks for the hint, I will look into it.

@Vince, FYI, made few other tests in between and path orders are hard to manage between key objects. I'll try to see why, but if you have a good solution keep it and don't waste too much time on mine (I'll work on it... later... can't now)

@lemon, I see, I will work on it when I find the time. No problem, I appreciate the help.


text:
Can blender export vector images?
Can you export a blender curve into a vector image? Is there perhaps an addon that can do that?

The freestyle-svg-exporter can do that.
Try this:

In Object Mode, select the object.
Go to Object > Convert > Grease Pencil
Go to File > Export > Grease Pencil as SVG
Save the vector file where desired.


text:
I accidentically made a super small mesh or something?
I downloaded blender an hour ago, and I am doing the donut tutorial from Blender Guru.
The problem is, that I accidentally pressed something and I made a super small grid thing.
I couldn't undo it with ⌃ Ctrl + Z.

Is there a subdivision modifier used in the tutorial? If so you might have applied it.

I can see two solutions
The first and most likely solution is that you have accidentally changed the scale of the donut. You can check this by pressing N on the keyboard and navigating to the item panel. From there, check that the scale is set to 1.0

The other solution might be to re-check the viewport overlay to check that the scale is set to 1.0


text:
When using subdivision modifier on my car model,faint lines appear which I believe are unaligned rows of vertices
I have tried to align the rows of vertices manually but to no avail.I have also put a wireframe image if you need one

Hello, maybe show a screenshot or even share your file (just the part with the problem): https://blend-exchange.com/

We can't tell where the problem is just from the wireframe. Add another image showing the actual problem.

I want make the faint lines in the windscreen and near the left tyre  dissapear


text:
How to connect the ear to the rest of the head cleanly?
I've done some googling and I think I've seen some stuff about using the boolean modifier? However there is space between the edges so I'm unsure how well it would work. There are also faces that overlap and intersect each other.

Hello and welcome. Rather than take photos of your monitor post actual screenshots instead, see How to take a screenshot. Photos are harder to read because we have to look past external interferences (like reflections, smudges or Moiré patterns) and guess if we are looking at hardware issues such as a malfunctioning display or connections, a software level issue like driver malfunction or glitch, or actual artifacts or issues with the model itself.

is this a sculpt?

I think we would really need to see the topology (wireframe) of your head and ear to get a better idea.


text:
Export Volume Cube to vdb format
Is it possible to export a volume cube output in a geometry node setup to a VDB file (ideally as a sequence)? I know that it is possible to export fluid simulations and also saw that there exists a unofficial plugin that exports shader volumes to VDB but that's only for shaders.


text:
Merge by distance doesn't work-0 vertices removed message
I'm using Blender 3.0 and whenever I try to merge vertices that are stacked right on top of each other, nothing happens. I get a message that says "0 vertices removed". Increasing the distance does nothing until it gets to a high number and starts merging the wrong vertices.
Help! Not a serious problem but it's important since I'm using lots of loop cuts and I want proper geometry.

The vertices all have to exist in the same object for a merge to work.  Is this the case in your sample file?  You can [edit] your question and paste in a screenshot to provide more info.

I figured it out. I need to be selecting all the vertices when I do the merge. I was trying to just select the object itself and merge because I thought it would be easier.

As you said in the comments, you figured out your problem: it was that those vertices were not selected and you had to do this to merge them - but not necessarily:
As most Blender tools, the Merge tool shows an options box at the bottom left of the viewport, which you can open by clicking on it.
If you open it, there is an option Unselected which is disabled by default (so that you won't merge vertices accidentally which you didn't intend to merge). But when you enable it, all vertices within the Merge Distance will be merged, no matter if you selected them or not.


text:
Render in cycle The object disappears and only a shadow remains
When I want to render an image so that the floor is transparent and the object with the shadow is visible, only the shadow remains. I used to do that and it worked, but now it doesn't. I had to kick something, I just can't find the reason. Can anyone help? Link https://drive.google.com/file/d/1KAt7kp4YY-LYHSBLgi1GEBDAU9rxzPfw/view?usp=sharing[2]][2]

In the file you provided:

The Render Engine was set to EEVEE.  I changed that to Cycles and enabled GPU compute.
Render Properties → Film → Transparent was not enabled.  I enabled that.
The plane did not have Object Properties → Visibility → Shadow Catcher enabled.  I enabled that.

and the biggest problem was:

The Cube did not have Object Properties → Visibility → Ray Visibility → Camera set.  I enabled that.

The last was the reason why the object wasn't showing up in the Cycles Render
with those changes, I get this render:

Is that what you are looking for?

Thank you very much, everything works. I did not think too well and hence the error.

@Janusz you are very welcome.  Blender's render engines have a lot of settings and sometimes it just takes a bit of work to make sure you have them all set properly.


text:
"render image" no colors, although you can see them through the camera
At the outset, I would like to write that I searched the internet, but did not find the answer.
The problem is that when I look through the camera I see colors, but when I want to "render image" (F12) the colors are gone.
Sorry, but I'm using google translator.

hello, maybe you have hidden object in preview mode? please share your file

https://drive.google.com/file/d/1NDPnezzzBmL1lMEB1Y66JTFHslmANCNW/view?usp=sharing

I can't see any color, whether I'm in camera view or in the final render, maybe in the Image Editor check the image textures you use?

all your images included in your uploaded file are just....white

and additionally no object has any material at all...

yes that's weird because their thumbnails are colored...

yes. saw that too...don't know what he did

but yeah, the objects in camera view have a material....but the textures are just white

Thank you very much for your willingness to help and for quick response: D.

Save all your images before rendering in Cycles.

Oh no .... How could I forget about it ... I watched the Keidy's tutorial and it was there, but I forgot after a long break. Thank you very much for your help !!!


text:
Transparent line appear in the top of rendered image/animation while the viewport is clean
this transparent line appeared out of nowhere, I have tried different cameras, it's the same issue, the camera shakify addon is enabled here as well as the motion blur

Could you attach your .blend file: https://blend-exchange.com

@YousufChaudhry https://fex.net/s/93xz6tx sorry blend exchange wasn't working

It has to be a bug since it doesn't appear on my side. Report it.
However, there is a culprit that can destroy your render:

Disable this, and it should probably go away. If not, try switching your blender version to the latest or previous version, and then give it a render.


text:
Different look of material with Mix Shader vs Mix RGB
I am mixing colors and roughness of a Glossy shader through Layer weight node.
Material:

Mix Shader:

Mix RGB:

Why do the same properties used in two similar approaches give a very different renders? Colors more or less equal, but roughness difference is quite visible.

Mix shader use a very simple method to combine two shader output. It doesn't guarantee any real material based on physic light reproduce. You are actually using alpha compositing rather than reevaluate a BSDF shader. See the example below.

On the left we use Mix Shader to mix the Roughness between 1.0 and 0.0. Right we use real 0.5 value for a single Glossy BSDF.
You can see that the Glossy 100% reflection just blend into the rough one without any transition. This is totally impossible in real world unless a clear-coat is presented.
So if a single BSDF shader can do the job, don't try to mix other shader, just let it do the calculation and connect it to the output directly.

Great explanation! I always prefered mixing RGB's rather than shaders due to hypothetical performance, but now I see real reason here.

@SergeL There is the performance difference. Double any BSDF shader is actually almost double the calculation of a surface. They are expensive shader compare to mix shader and mix RGB node.

@SergeL if you're interested at taking a look at the implementation of Mix RGB and Mix Shader as GLSL shader. The closure_mix is implemented in bsdf_common_lib.glsl.

The OSL shader implementation for Cycles can be found here.

@RobertGützkow So the mix shader is a linear interpolation of two shader closure output? And the closure contain absorption scatter emission anisotropy properties, and there is no roughness property left for an accurate glossy BSDF?

@Hikariztw Looks like that's the case for GLSL, but I'm not familiar with the implementation so there might be something that I've missed.


text:
How do i select an object that is separated from other objects
I was watching a tutorial on texturing. There was shown a way to separate the glass part of the windows so you won't keep on clicking on them while you're texturing which I admit made things a lot easier.
Now I want to work on texturing my windows but I have no idea on how to select them. They aren't on a different layer. If there is a clip board option on here I haven't found it yet.

It's a bit hard to understand the problem you're facing. Please provide a link to the tutorial (point out the moment you're stuck on) and preferably add some screenshots with your current scene demonstrating problem. If you mean you have 2 separated objects and you'd like to edit the other one exit Edit mode of current one with Tab, select desired object and Tab to enter Edit mode for that one.

Possibly related - http://blender.stackexchange.com/questions/38881/get-out-of-orange-selection-mode

Perhaps you're looking for Face selection mode? http://i.imgur.com/XjYTJI9.png

Because you mention the object is separate from other objects, I am thinking that selection may have been disabled on the object you can't select.
In order to enable/ disable selection on an object you can click on the arrow next to the objects name in the outliner.


text:
How do I skip animation between 2 keyframes?
I want to skip the animation between keyframes 100 - 200. So once playback reaches keyframe 100 it jumps straight to keyframe 200.

One simple way is to select keyframes in between keyframes 100 - 200, delete them, select those where you'd like playback to jump to and grab them towards the beginning. Note that original keyframes 100-200 will be lost

You can install a handler for frame_change_pre that alters the current frame if the frame is within a range. This will make playback in the 3DView always skip frames 101-199
import bpy

def my_frameskipper(scene):
    if scene.frame_current > 100 and scene.frame_current < 200:
        scene.frame_set(200)

bpy.app.handlers.frame_change_pre.append(my_frameskipper)

# remove the handler with -
# bpy.app.handlers.frame_change_pre.remove(my_frameskipper)

While that is fine for 3DView playback it breaks rendering an animation. To render a range of frames you can use -
import bpy

scn = bpy.context.scene
basepath = '//renders/'

for f in range(scn.frame_start, scn.frame_end+1):
    if f <= 100 or f >= 200:
        scn.frame_set(f)
        scn.render.filepath = basepath + str(f)
        bpy.ops.render.render(write_still=True)

If you're just making a video, add the scene of the animation into the blender VSE and cut out the 101-199 frame range of that animation strip. This will allow you to preview and render your animation without those frames. Additionally, the keyframes will not be affected. If you eventually wish to go back and include the frames again, they will still exist.
Alternatively, you could do as Mr Zak suggested and move all the keyframes from the 200th frame and onward back 99 frames. This would make animation appear as though it is skipping all the frames in the 101-199 range.
To do that, go to drop down menu of blender layouts found in the top left and select the animation layout.

In the dope sheet editor found in the top left, check to see if there are any keyframes in the 101-199 frame range. If there are any, delete them. The range should be made empty.
After the frame range is clear,

Set the vertical bar at the 200th frame and press ] to select all the keyframes to the right of the vertical bar.
Press G to grab your selection, type -99 to move the keyframes back 99 frames and press enter.

The keyframes that were at the 200th frame mark should now be at the 101th frame. Now when you cycle from the 100th frame to the next frame, it should act as though you were cycling straight to the 200th frame.

I would also like to emphasize that you should put the VSE strips in a new scene separate from the 3D animation.  See section 2 of http://web.purplefrog.com/~thoth/blender/python-cookbook/render-to-pngs.html


text:
Seams visible after baking normal map

Can anyone give a solution how to bake normal map properly?
On this picture cubes are shown located next to each other, but they are in the same position when I bake them.
The main problem is with hard edges. I tried to use UVs in T shape, tried to place islands together and separately but the problem persists.
I tried several diferent methods in Blender and Substance Desiger but I realy don't know what I'm doing wrong. Please help.
If it's possible please post step by step instructions.
Thanks

Related - http://blender.stackexchange.com/questions/41184/baked-normal-map-from-high-poly-bad-corners ? It could be that low-poly has too low polycount. Also from the normal map it seems that low-poly doesn't have normals split that can cause shading artifacts.

any precise instuctions?!

Your low-poly object has shading mode set to smooth, but it seems to have bad shading because of absence of Edge Split modifier or Autosmooth option. Also make low-poly to be wrapped around high-poly, so their surfaces should be close. You might want to look at baking normal maps in BI


text:
Dyntopo workflow + Dyntopo vs. Multires?
I've checked the Dyntopo option on sculpt mode and now my mesh is with triangles. Is there any way to revert a mesh to the way it was before clicking on Dyntopo?
Is it better to sculpt with Dyntopo or with Multires? Which of the two gives better higher quality results?
There's a great tutorial on youtube where the person first demonstrates the dyntopo sculpting, then does the retopology, and then adds an multi-resolution modifier on the retopology in order to give it a more detailed sculpt. Now is it necessary to have this workflow? Or is it more convenient to first have your high detailed sculpt, then retopology and after that, bake normals from high to low poly?
Link to the video
https://www.youtube.com/watch?v=k9NAv_q_wfU

Related: https://blender.stackexchange.com/questions/98565/sculpting-a-photorealistic-human-face-for-animation-use-the-multiresolution-mod/98566#98566

Something to be aware of with workflows is there isn't necessarily an objectively 'better' or 'worse' workflow. There are a number of ways to get to the same (or at least very similar) end result, so the workflow you use should be the one that fits you best, and lets you work in a way you like while giving you the best results in the least amount of time.
Now to answer your questions, there is no way to revert back to your mesh once you have started to sculpt with Dyntopo. That's known as a destructive process, as it permanently changes the structure of your mesh. However, if you have just clicked the button and haven't actually started sculpting, you may be able to use the tris to quads tool in edit mode. Select all of your faces, then press Alt+J and it will try and join the triangles into quads. Depending on your mesh this may have varying levels of success.
Dyntopo vs. Multiresolution is a subjective question. There are uses for each tool, and situations where one is better than the other. I discussed this in another question here.
To answer your final question (and just for future reference you should try to limit your questions per post to just one), the workflow used on the video isn't 'necessary' but may be the best way to achieve the best results. As for convenience, if it works better for you, then do it that way. Part of creating digital art is having fun and being able to express yourself, so you don't want to have a workflow where you're constantly fighting with your tools. Find what works best and stick with it.

Brenticus, I highly appreciate your response. Thanks for letting me know and answering my questions.


text:
whats the maximum poly count for character models in video games?
So I have a 3d human model that I made in blender and it has almost 14,000 vertices, almost 14,000 faces, and tris are at almost 28 thousand. Will it be okay for me to use this model with out the need of retopology and baking normals and ambient occlusion. Even though you cant see the model I've made, all I can say is that it looks somewhat high poly-ish(with-out subsurface modifier). I modeled the mesh from my own character reference and pretty much feel great about the outcome. Though, certain parts of the mesh I had to sculpt, but with out the "Dynamic Topology" tool option in the Blender sculpting section.
I've heard poly count depends on your project's gameplay style. But The gameplay mechanic i'm going for will be no more than 3 characters in the gameplay.
Let me know what you think, thanks.

Imho in the end it depends also on the expected processing power of your game's target devices. And you could also privide different level details as an option...

Keep it low as possible and maintain the silhouette of the character. The stressing should be on texturing and normal mapping. Depends upon your target devices, even process heavy games are mostly heavy because of the texture sizes and shadow quality.


text:
Subdivision Surface modifier works badly
I try to follow instruction from an old video tutorial of creating a clock. This is what I wanna achieve (I mean smooth edges only):

And this is my work without SubSurf:

This is what I get with Subdivision Surface modifier:

How can I rid of ugly rim / hollow on the left side of screenshot? It looks terrible after rendering! I tried to use different subdivisions numbers and replace it with bevel, but nothing helps.
This is my work from other side without the modifier:

And why did I get this problem if I tried to follow all the steps and proportions of the tutorial?
Update
I highlighted the problem here:

After reading the question I am still unsure what you actually want. Maybe removing doubles will work for you?

@JaroslavJerrynoNovotny I've added a representative screenshot. And yes, I solved the problem, it was because of plenty double vertices  So many problems because of them...

You can try to do Ctrl + R to add a loop cut, click before the sharp vertices you want, and just slide it to the left to sharp the angle
Otherwise you can select the vertices and in the Tool box on the right (with N) click on a thing with crease in the name, or I think you can do Shift + E

Thanks, I tried your advices, but it turned out that the problem was because of silly double vertices...


text:
Cycles nodes: is there a way to find coordinates change, derivative, direction?
I want to get a unique random value for every face using direction of mesh coordinates. Like a derivative, position change, a unit vector based on current face's vertices. (I guess, something similar to dFdx() in OpenGL.)
I tried to find the answer on Google, but got no results, though as a software developer I think this function isn't difficult to create. Maybe some Blender experts here know the solution?

Bake world position to a texture image, then do a two lookups on that texture, one at a UV offset, to get ddx(UV)/ddx(worldpos).

Not strictly an answer to your question, but..
To get a random value per face to be read by Cycles, you could use an adaptation
of Chebhou's answer to this question.
Run this script on the active object:
import bpy
import random

obj = bpy.context.object
obj_data = obj.data
group_name = 'face_ID'

#check for existing group with the same name
if None == obj_data.vertex_colors.get(group_name):
    obj_data.vertex_colors.new(name=group_name)
color_map =  obj_data.vertex_colors[group_name]

for poly in obj_data.polygons:
    rnd=random.random()
    color = (rnd, rnd, rnd,0)
    for loop_ind in poly.loop_indices:
        color_map.data[loop_ind].color = color

and then use the Cycles 'Attribute' node to retrieve the generated vertex color layer by name:

result of this example on a subdivided plane:

I've moved the randomization into the script - I was having trouble getting a good pseudo-random number out of  a 0.0-1.0 input range using nodes. If nobody points out something obvious in a comment, I'll post that as another question.

I haven't yet worked with Python scripts in Blender, but will start it with your code :) But my answer (use normals) is closer to geometry, and I will use it if won't find an answer to my other question. And thanks for your reply!

I just realised that I can use normal to achieve almost the same behaviour – it is perpendicular to the direction of a face, so, it is an almost isomorphic value that gives some unique value for a face. But I will appreciate any better answer.


text:
Particles keep going are appearing on the bottom side of the model!
I have been using Grasswald (Even without it this happens with normal particles as well) to create grass on this rocky field but for some reason portions of the particles appear underneath it, facing to the bottom.
I have tried weight painting it and assigning the group in particles settings, then I used a solidify modifier to add a lot of thickness and tried weight paint once again but no luck.
I then ALSO tried a subdivision surface with the thickness and without, that did not work either. The closest I got was adding a 1 to the Z in Veclocity selection of the particle settings that makes the button ones face the right side but for some reason the ones that were already on the right side get bigger in size and slightly denser. Please help me. I'm on the 3rd day of trying to fix this I'm out of options at this point.

Here are pictures to show what is going on.

Please use the built in tools to add images to your posts instead of adding links to external sites. If those links ever break the information will be lost for future visitors with the same question.

please provide blend file so we can check it out

Most likely your normals are inverted so it grows in the wrong direction