Search Unity

One draw call for each shader, with dynamic meshes : The Bob script.

Discussion in 'Made With Unity' started by Ippokratis, May 9, 2011.

  1. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Edit 26 October 2011
    I am developing an enhanced commercial version, aiming at improving static batching for unity free and Pro. Details here.

    Edit 19 May 2011

    Un updated version of the Bob script ( v 0.2 ) is available at my blog, http://ippomed.com It handles better user errors.


    Edit 17 May 2011
    The following workflow also needs to set the blend weights of the bones to one. Unless you do this, you will slow down the program, instead of speeding it up.
    Sorry for the inconvenience, I found myself gazing at the results in a new project, until it came up. I modified the steps below to include this step.
    Now, to clear things out : The Bob script speeds up the app considerably, once you follow the updated steps :)



    This is a workflow for minimizing the draw calls in a scene. This technique speeds up the rendering considerably.
    Suppose you have a scene with 30 gameObjects that move independently. For example's shake we will create a scene with 30 cubes. If you press now the Stats buttton on the Game view you will see that this scene has 30 drawcalls. Create 3 materials with diffuse shader and 1 texture per material. Assign 1 material per 10 objects. Still 30 drawcalls.
    Now the method I suggest will merge those objects in a single mesh using a single material, resulting in 1 draw call.
    1. Go to the menu. Select Edit -> Project Settings -> Quality. Set the Blend Weights to one.
    2. Create a new gameObject, name it root and place all cubes in it.
    3. Go to the texture import settings and turn the texture's type to advanced. Check the read/write enabled property.
    4. Add the following script, View attachment $TexturePacker.cs to the root, (created by Phantom and slightly modified by me).
    5. You will get some error messages. Hit clear in the console. Now, look at the materials of the gameObjects : The textures appear modified. This is because the above script overwriten their texture with a new one, containing their combined textures. Also it modified their uv's accordingly, so they map each cube's coordinates to the right texture coordinates. Now remove the script TexturePacker.cs from the root.
    6. Add the following script, called Bob.js to the root.

    Code (csharp):
    1.  
    2.  
    3. //Copyright 2011  by Bournellis Ippokratis
    4. //
    5. //Permission is hereby granted, free of charge, to any person obtaining a copy
    6. //of this software and associated documentation files (the "Software"), to deal
    7. //in the Software without restriction, including without limitation the rights
    8. //to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    9. //copies of the Software, and to permit persons to whom the Software is
    10. //furnished to do so, subject to the following conditions:
    11. //
    12. //The above copyright notice and this permission notice shall be included in
    13. //all copies or substantial portions of the Software.
    14.  
    15. //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    16. //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    17. //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    18. //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    19. //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    20. //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    21. //THE SOFTWARE.
    22.  
    23. #pragma strict
    24.  
    25. import System.Collections.Generic;
    26. @script ExecuteInEditMode()
    27. private var gameObjects:List.<GameObject>;
    28. var  _add : boolean; var  combine : boolean;
    29. private var partMat: Material;
    30. private var mesh : Mesh;
    31. private var newMesh: Mesh;    
    32. var goMat:GameObject;
    33. private var _renderer : SkinnedMeshRenderer;
    34. private var triangles:List.<int>;
    35. private var vertices:List.<Vector3>;
    36. private var uv: List.<Vector2>;
    37. private var weights:List.<BoneWeight>;
    38. private var bones:List.<Transform>;
    39. private var bindposes : List.<Matrix4x4>;
    40. private var meshes:List.<Mesh>;
    41. var transforms:List.<Transform>;
    42.  
    43. function Start ()
    44. {
    45.     gameObjects = new List.<GameObject>();
    46.     gameObject.AddComponent.<SkinnedMeshRenderer>();
    47.     _renderer  = GetComponent.<SkinnedMeshRenderer>();
    48.     bones = new List.<Transform>();
    49.     mesh = new Mesh ();
    50.     _renderer.material  = partMat;
    51.     _renderer.sharedMesh = mesh;
    52.     newMesh = new Mesh();
    53.     meshes = new List.<Mesh>();
    54. }
    55.  
    56. function AddGameObject()
    57. {
    58.  
    59.     partMat = goMat.renderer.sharedMaterial ;
    60.     var skin:MeshFilter[]  = GetComponentsInChildren.<MeshFilter>();
    61.     for (var item : MeshFilter in skin)
    62.     {
    63.         meshes.Add(item.sharedMesh);
    64.         transforms.Add(item.transform);
    65.         var myGo :GameObject = new GameObject (item.gameObject.name);
    66.         gameObjects.Add(myGo);
    67.         item.gameObject.active = false;
    68.     }
    69. }
    70.  
    71. function CombineMeshes()
    72. {    
    73.     //Create new lists for everything but the bones
    74.     triangles = new List.<int>();
    75.     vertices = new List.<Vector3>();
    76.     uv = new List.<Vector2>();    
    77.     weights = new List.<BoneWeight>();
    78.     bindposes = new List.<Matrix4x4>();
    79.    
    80.     //Add the gameObject's mesh to the mesh list
    81.     var vertIdx:int = 0;
    82.     var idx:int = 0;
    83.     var __weights : BoneWeight[] = new BoneWeight[vertIdx];
    84.     //Rebuild the combined mesh from the array of the meshes
    85.     newMesh = new Mesh();
    86.     var trianglesIdx:int = 0;
    87.     var _bonesIdx:int = 0;
    88.     var bonesA : Transform[] = new Transform[gameObjects.Count];
    89.     var bindPosesA : Matrix4x4[] = new Matrix4x4[gameObjects.Count];
    90.     var _meshes : Mesh[];
    91.     _meshes = meshes.ToArray();
    92.    
    93.       for (var item:Mesh in _meshes )
    94.       {
    95.         for(var _item: Vector3 in item.vertices)
    96.         {    
    97.             vertices.Add(_item);
    98.         }
    99.         for(var _item: Vector2 in item.uv)
    100.         {    
    101.             uv.Add(_item);
    102.         }
    103.         for(var _item: int in item.triangles)
    104.         {    
    105.             triangles.Add(_item + trianglesIdx);
    106.         }
    107.  
    108.         vertIdx = item.vertices.Length;
    109.         idx = 0;
    110.         __weights  = new BoneWeight[vertIdx];
    111.        
    112.         for ( idx = 0; idx<vertIdx; ++idx )
    113.         {    
    114.             __weights[idx].boneIndex0 = _bonesIdx;
    115.             __weights[idx].weight0 = 1.0;
    116.             weights.Add(__weights[idx]);
    117.         }
    118.  
    119.         newMesh.vertices = vertices.ToArray();
    120.         newMesh.uv = uv.ToArray();
    121.         trianglesIdx = vertices.Count;
    122.        
    123.         //gameObjects[_bonesIdx].transform.localPosition = transforms[_bonesIdx].localPosition;
    124.         bonesA[_bonesIdx] = gameObjects[_bonesIdx].transform;
    125.         bonesA[_bonesIdx].parent = transform;
    126.         bonesA[_bonesIdx].localRotation = Quaternion.identity;
    127.         bonesA[_bonesIdx].localPosition = Vector3.zero;
    128.         bindPosesA[_bonesIdx] = bonesA[_bonesIdx].worldToLocalMatrix * transform.localToWorldMatrix;
    129.         //
    130.         gameObjects[_bonesIdx].transform.localPosition = transforms[_bonesIdx].localPosition;
    131.         gameObjects[_bonesIdx].transform.localRotation = transforms[_bonesIdx].localRotation;
    132.         gameObjects[_bonesIdx].transform.localScale = transforms[_bonesIdx].localScale;
    133.         ++_bonesIdx;
    134.       }
    135.  
    136.     newMesh.triangles = triangles.ToArray();
    137.     newMesh.RecalculateNormals();
    138.     newMesh.boneWeights = weights.ToArray();
    139.     newMesh.bindposes = bindPosesA;
    140.     newMesh.RecalculateBounds();    
    141.     newMesh.Optimize();
    142.  
    143.     mesh.Clear();
    144.     mesh = newMesh;
    145.       _renderer.bones = bonesA;
    146.       _renderer.material  = partMat;
    147.     _renderer.sharedMesh = mesh;
    148.    
    149.    
    150. }
    151. function Update()
    152. {
    153.     if(_add)
    154.     {
    155.         AddGameObject();
    156.         _add=false;
    157.     }
    158.     if(combine)
    159.     {
    160.         CombineMeshes();
    161.         combine=false;
    162.     }
    163. }
    164.  
    7. Drag one cube on the goMat slot in the Bob script. Check once Add. It will not appear checked, do not worry for this. Hit once Combine. Now check the draw calls.

    8. Remove Bob script from the root. Delete the inactive gameObjects. Now you have 30 cubes to move around independently , costing only one draw call. Enjoy :)

    The above procedure should be followed per shader, some shaders might need further modifications. You should work them out :) It creates one skinned mesh from the meshes you added to it, with one bone per gameObject. It will not work in its current form with nested hierarchies (eg gameObjects in other gameObjects). It works for my current needs and I do not plan on supporting it, thus I provide the source code for you to play with. Since it is provided with a MIT license, you can modify it, distribute it, sell it at will.
    I decided to release this code for free, as a thanks to the unity community, especially the irc channel members who have tolerated my engrish and my strange questions for sooo long. Thanks again Mike, Neil et all :)
     
    Last edited: Oct 26, 2011
  2. huangyous

    huangyous

    Joined:
    Jun 27, 2010
    Posts:
    55
    I‘ve tried the same method before,combine some objects into a skinnedmesh.But the SkinnedMeshRenderer in Unity is very very slow.In my case the framerate is even lower than separate objects.Have you compared the framerate before and after?
     
  3. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Unity has both Static and Dynamic batching ability to reduce drawcalls on objects that share same materials. Why would you not use those?
     
  4. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    @huangyous: Sample scene with 140 cubes on my mac mini 2.0gh 4gb.

    Vanilla : 2.01 msec per frame, 495 fps.
    This method : 0.55msec per frame, 1790.8 fps.
    In iphone especially, msecs are crucial. This method allows more moving objects -> richer games.
    Bob's approach is not magical. It is just a potential tool in your toolchain and requires some effort from your part. I find it easier than merging the geometry in a 3d program. It is up to you to decide if you wanna use it.

    @Seon: You may find this an interesting read.
    Some limitations of dynamic batching:
    I think Bob overcomes those limitations. As of static batching, this script is a very good replacement for iphone devs without advanced version.
    I think that unity method has a different approach and serves different needs.
     
  5. huangyous

    huangyous

    Joined:
    Jun 27, 2010
    Posts:
    55
    Really!? I'm gonna try it!
     
  6. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Interesting...I might try this...I build my levels on grid inside Unity n use one material, so I expect one draw call...nope, because Unity's dynamic batching has a limit which Unity Team could never explain to me why when I bug reported...
     
  7. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    You too may find this an interesting read, regarding dynamic batching.
     
  8. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    This is something I wanted for my own particle systems on iOS - being able to just move things around and so on without the worry of the dynamic batching breaking if I scale one of them.
     
  9. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    As said before, you should work it out for your needs. As far as I can imagine, it can be the base for a gui, a particle system, a better solution than pools for enemies and bullets etc. I would like to see what you make with it, if you wish too (no obligations :) ).
     
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Thank you for sharing this, it is very decent of you :)
     
  11. KITT

    KITT

    Joined:
    Jul 17, 2009
    Posts:
    221
    Bookmarked.
     
  12. Vert

    Vert

    Joined:
    Mar 23, 2010
    Posts:
    1,099
    So, this script automatically generates texture atlases? That seems to be the process you are describing with combining multiple textures into one map. You end up having one shader with a texture map and each object has its UV's offset to the proper place on the texture atlas which all use the same material.

    Very interesting! It would save people a lot of work if they didn't design objects to be atlases. This also seems like it should be possible at run time? If so, it would allow the developer to generate different atlases per level with whatever objects they want? If so that is pretty amazing.
     
  13. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    TexturePacker.cs in its original form generates a static mesh (ie you cannot move each children indepedently) with a submesh and a texture atlas per shader. It exists on the forums since 2007. It allows the use you described and can be found in this thread.
    I find it more convenient to create texture atlases and meshes in Editor since this approach saves time from game load as well as processing power.
    Bob script does something different. It creates a skinned mesh with children that can be moved independently. To do so, the TexturePacker.cs is used as described in the first post to create the material, ie a texture atlas with a shader and to modify the uv's of each child's mesh, so they correspond to the texture atlas coordinates.
    Exactly. More than that, it can be used to achieve the approach @MikaMobile suggested in this post, without resorting to external tools, aka you do not need Maya to make the bones and the atlas: You just create the gameobjects you want in the scene and connect them with TexturePacker and Bob, after you group them per shader.
     
  14. huangyous

    huangyous

    Joined:
    Jun 27, 2010
    Posts:
    55
    myGo.AddComponent.<SkinnedSubmesh>();

    Assets/Bob.js.js(64,28): BCE0018: The name 'SkinnedSubmesh' does not denote a valid type ('not found').
     
  15. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Thanks for the report. I updated the script at the first post to resolve this, just copy it again. It should work now.
    Also, as a side note : This script reduces drawcalls, which represent one of the possible bottlenecks.
     
    Last edited: May 10, 2011
  16. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Internal compiler error. See the console log for more information. output was:BCE0011: An error occurred during the execution of the step 'Boo.Lang.Compiler.Steps.EmitAssembly': 'Object reference not set to an instance of an object'.

    What to do?
     
  17. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    I'm not on currently on a computer with Unity to test this, but it sounds interesting.

    So with this could I for instance create a bunch of primitive shapes like cubes and cylinders with different materials to make a room prefab of sorts... then combine it all into a single mesh and material?
     
  18. fghajhe

    fghajhe

    Joined:
    Jan 6, 2009
    Posts:
    145
    Very useful thanks!
     
    Last edited: May 10, 2011
  19. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    @jrricky: Thanks for the report. I was unable to reproduce the error. The following steps will help you:
    1. Restart your computer.
    2. Start a fresh unity project.
    3. Follow the steps in the first post precisely. Step order is crucial and there are no optional steps.
    If the problem persists or you have other problems, please report.

    @legend411:
    1. You can combine any GameObject object with a MeshFilter, not just primitives.
    2. You can use it for creating static or dynamic meshes, ie gameobjects that move are dynamic. If you want static objects, look for the original TexturePacker.cs script (a couple of posts above).
    One material per shader. Ie if you have 4 cubes with 4 shaders, you will have 1 mesh with 4 materials, aka 4 drawcalls. If you have 4 cubes with 4 materials that all use 1 shader -> 1 mesh, 1 material, 1 drawcall.
     
  20. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Thanks... so I just follow the steps in your OP, except instead of using your TexturePacker, use the original that you linked to a few posts ago... and I can do all this in the editor?
     
  21. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    @legend411:
    Well, to create a static mesh you can try the following:
    1. Download View attachment $TexturePackerStatic.cs made by Phantom and slightly modified by me and place it in your Project view.
    2. Create a new gameObject, call it root.
    3. Add other gameobjects containing MeshFilters that you wish to combine to the root. Make sure their texture type is advanced and read/write property is checked.
    4. Add TexturePackerStatic.cs to the root.
    5. Some error messages will appear. Clean them from the console.
    6. Remove TexturePackerStatic.cs from the root.
    :) Done !
     
    Last edited: May 16, 2011
  22. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Hmm... doesn't work for me, the resulting material's diffuse texture is a solid blackish gray.
     
  23. fghajhe

    fghajhe

    Joined:
    Jan 6, 2009
    Posts:
    145
    @legend411

    Make sure the textures have been set to read and write. That is probably why.
     
  24. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Thanks for the correction fghalhe, I forgot to point this out. It is now in the steps.
    @legend411 : Does it works now ?
    Well, perhaps this happens because a diffuse shader without a light results in greyish textures?
     
    Last edited: May 17, 2011
  25. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    The above workflow also needs to set the blend weights of the bones to one. Unless you do this, you will slow down the program, instead of speeding it up.
    Sorry for the inconvenience, I found myself gazing at the results in a new project, until it came up. I modified the steps below to include this step.
    Once you follow the updated steps, the app speeds up considerably :)
     
    Last edited: May 18, 2011
  26. fghajhe

    fghajhe

    Joined:
    Jan 6, 2009
    Posts:
    145
    Okay. Does the c# texture atlasing script slow down the game at all/ more so than if just using an already laid out atlas made in photoshop etc.
     
  27. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Thanks for the support. I tried today a new version of the script and I was petrified when I discovered that in many different settings, the above method slows down the program instead of speeding it up.
    It happened before I forgot to set the Blend Weights to one in the quality settings. I realized that I forgot to mention this in the steps as well, so now I corrected them too.
    Sorry for the inconvenience. The Bob script speeds up the app considerably by following the updated steps !

    @fgajhe: Afortunately I cannot make comparisons since I do not have an already laid out atlas made in photoshop. If you happen to have one, why don't you try it and post the findings ?
     
    Last edited: May 18, 2011
  28. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    None of this applies to the static version you outlined for me, right? Because it seems to be working like a charm for me :)
     
  29. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    @legend411 : Nothing applies to Bob script too ! Read the updates :) I feel good (in a James Brown way) that you found the outline useful.
     
  30. Hakimo

    Hakimo

    Joined:
    Apr 29, 2010
    Posts:
    316
    Thanks very much for sharing this :)
     
  31. fghajhe

    fghajhe

    Joined:
    Jan 6, 2009
    Posts:
    145
    After using the texturepacker.cs, the object has duplicate's of its materials, resulting in the same number of drawcalls. Using the GoMat feature in the bob.js fixes this but also turns the object into a skinnedMesh. I would like to use the texturepacker.cs for a static enviroment that has many different materials with different textures but the same shader, and I would like the shader created by texturepacker.cs to be assigned once to the object, not multiple times. Is there an easy way to do this?
     
  32. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
  33. fghajhe

    fghajhe

    Joined:
    Jan 6, 2009
    Posts:
    145
    Ah, thanks so much, I was not using the static version!
     
  34. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
  35. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    What troubles me is that this code could be the base for many things, yet nobody mentions it.
    I hope that people at least use it.
    I suggest that you save the textures as read only after you create them and removed the
    Bob script. If this doesn't works, let me know.
     
  36. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    this is such a useful script, thank you for sharing. Anything that can help get meshes with rigs/bones/skinrenderers working more efficiently on mobile is MOST WELCOME. Has anyone tested this with iOS or Android yet?
     
  37. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Works fine on IOS, remember to follow all steps ( especially set the Blend Weights to one ).
     
  38. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    does this also combine draw calls for multiple meshes that are rigged(have a skeleton/rig/armature)? or only "static" non-rigged meshes?
     
  39. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    I am not so sure that combining characters with many bones would be beneficial.
    It is possible via the Add function.
    Have a look at the script, do some tests and tell me if you get stuck somewhere.
     
  40. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Thanks for this knowledge, In my Orthello 2D framework I am working on a SpriteBatch object that does a lot of things the same, except for the bones part. The object monitors underlying object (sprites) changes and modifies the vertices, UV and triangle arrays (and submeshes) accordingly (CPU).

    Bones will probably speed things up. Animating images (UV animation) will still be applied on the mesh.uv array at runtime but I will see if this works ..

    :)

    thanks and Regards.
     
  41. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Good to know it helps. It is a not - so - user friendly script but it works.
    Indeed,
    is a job best suited to bones.
     
  42. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    I will probably not use your script but use the knowledge to adjust the current system.
    Thanks for sharing.
     
  43. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Sure, np. This is why I posted in the first place :)
    The bones example in the documentation is a very good source to get you started.
    Also, there are some 2d skeletal ( bone ) systems to see as inspiration, I especially admire Moho - now known as anime studio.
     
  44. qholmes

    qholmes

    Joined:
    Sep 17, 2010
    Posts:
    162
    I just found this post... looks great!

    I have a fairly complex mechanical model that currently uses around 1600 draw calls.... I did not optimize it in Max as i thought that i would be able to do it in Unity.. My first project in Unity so i did not know...

    The built in draw call batching does not seem to do anything for me.. Not sure why. I was assuming that if i made sure i shared materials then i would be ok but i dont think that is the case. Do i need to have the IOS package? I am going to buy it but just havent yet.

    If i use this set of scripts do i lose my existing objects or just create a new one that is a combined object? And then i turn off the individual ones? It does not read that way.. If i want to adjust the materials? Can i still do that?

    Some of the cases for me will be static situations but some will be dynamic so i expect i would use both the old script and the one you modified.

    Your blog link does not seem to work.. I did not see anything about these scripts when i went there.

    Thanks for this!!!

    Q
     
  45. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Some parts are static and some dynamic ? The number is huge if you wanna do all of them dynamic ( my guess is that no ).
    Try to make one empty game object (GO) as parent, one empty GO as child and put there all the static parts, another one for the dynamic parts.
    But, 1600 parts sound a lot ! I am curious to know how that works out.
    Too many parts / triangles perhaps.
    You will find them deactivated in a folder, you can delete them.
    It is possible, but you should work it out if you choose other than diffuse.
    When I posted the address of my blog it was pretty empty. Thanks for bringing this to my attention, I changed the link in the first post too.
    It is here http://ippomed.com/wordpress/one-dr...th-dynamic-meshes-in-unity-3d-the-bob-script/
    The script does what it says. Try to figure out how to fit it to your needs. I can provide some ( unpaid = limited ) help, if you have problems using it.
     
  46. qholmes

    qholmes

    Joined:
    Sep 17, 2010
    Posts:
    162
    Cool thanks!

    I dont have 1600 parts... but i do have multiple lights.. probably a big no no as well... My first project so i am still learning.. this project is first on pc/mac / web then maybe iPad.... so i will have to go through the whole learning curve for all the platforms i guess..

    I wonder how many parts i have?

    You are correct most of my objects are static.. Some either have to move out of the way or fade out.. not sure what will be better draw call wise. I dont count those as animated even though they do move.. But there are probably 30 or so parts that actually do animate to show things..

    Not sure what you mean by working it out if i dont choose diffuse.. But maybe you just mean you are not sure and i will have to see if it works myself.

    If i get stuck i dont mind paying for help so will get in touch if that is the case i guess.. What is the best way to get in touch with you privately?

    Q
     
  47. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Diffuse is a shader. There are many shaders out there, some work out of the box with this solution, others needs adjustments.
    I.e a shader that looks up 3 textures and receives 2 floats and 2 colors might need to adjust the script in order to handle the settings for each material. As a simple example of this say you use a transparent cutout shader. The Bob script right now knows how to pack the texture but does not know how to pack the individual settings for cutout ( a float value ) per material. Suppose you need to use this shader, you should make an array of floats that contains the individual settings for each material. It is a little involved and should be created as one solution per shader. Shaders that contain a texture only are handled ok, the rest needs adjustments.
    I mean that depending on the shaders you choose, a different approach is needed ( see above ).
    If this is your first project and you are learning Unity, I suggest you take your time and try to find out as much as you can before you start paying people to do stuff. Perhaps you find out that you pay money to someone for doing trivial things, once you have a better view of Unity. Static and dynamic mesh creation is not so trivial but unless you have sorted other things out ( user interaction, right choosing of shaders and materials, script optimization ) it will not help your project.
    I would love to see the project you make and to provide some help. I can offer suggestions for free and solutions for a small fee, but only after I have a better view of your requirements.
    If you need to contact me in private, click my name and in the next screen under my name there is the "send private message": option.
     
    Last edited: Jul 13, 2011
  48. qholmes

    qholmes

    Joined:
    Sep 17, 2010
    Posts:
    162
    Ok, Yes i know the basics of Shaders. I figured from what you wrote that i would have to adjust the script based on the shaders i chose.. Good to know. Might be something i could use some help with..

    I did a couple small projects in Quest3D before coming to Unity.. i am still new to the industry but know the basics and have managed to write quite a few small scripts for this and that..

    I dont mind paying for simple things if i can learn from them... sometimes you dont know you need to go in a direction until someone points you that way.. And sometimes you have to pay for those little pokes in the right direction.. But neither am i made of money.. I am just a small consultant who is actually going to loose money on this project.. but i am also not a sponge who wants everything for free..

    Its people like you that make the Forum work!!!

    Will send you a PM and describe my project if you like.

    Q
     
  49. Mark-Sweeney

    Mark-Sweeney

    Joined:
    Feb 21, 2010
    Posts:
    172
    I've been trying to use this, but the Bob script .2 gives me compile errors.

    As soon as I add it to the project folder, I get "Internal compiler error. See the console log for more information. output was:BCE0011: An error occurred during the execution of the step 'Boo.Lang.Compiler.Steps.EmitAssembly': 'Object reference not set to an instance of an object'."

    I can't attach it to the root because I get the "Script Bob has not finished compilation yet. Please wait until compilation of the script has finished and try again." message, so I can't get anywhere with it.

    Any ideas? I'm on Unity 3.0 for iOS basic.
     
  50. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Try to start in a fresh project ?