[CODE]ModelDrawer Texture Selection

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
squimball
Posts: 7
Joined: Sat May 07, 2011 9:25 pm

[CODE]ModelDrawer Texture Selection

Post by squimball »

Hello. I just thought I would post this while I was thinking about it if anyone is interested.

Basically, I got tired of the random entity colors so I added this overloaded function for the ModelDrawer.cs code file. Once you add this, you can use something like ModelDrawer.Add(myEntity, 4) to specify the entity's color/texture. Currently, there are 8 (0-7) colors/textures built into the ModelDrawer and this overload does not check to see if you went over the max index. It will just error out. You can still use random colors too - just leave off the ", 4" part when adding an entity to the ModelDrawer.

File: BEPUphysicsDrawer/Models/ModelDrawer.cs

Change this part...

Code: Select all

        /// <summary>
        /// Attempts to add an object to the ModelDrawer.
        /// </summary>
        /// <param name="objectToDisplay">Object to be added to the model drawer.</param>
        /// <returns>ModelDisplayObject created for the object.  Null if it couldn't be added.</returns>
        public ModelDisplayObjectBase Add(object objectToDisplay)
        {
            ModelDisplayObjectBase displayObject = GetDisplayObject(objectToDisplay);
            if (displayObject != null)
            {
                Add(displayObject);
                displayObjects.Add(objectToDisplay, displayObject);
                return displayObject;
            }
            return null; //Couldn't add it.
        }
To this...

Code: Select all

        /// <summary>
        /// Attempts to add an object to the ModelDrawer.
        /// </summary>
        /// <param name="objectToDisplay">Object to be added to the model drawer.</param>
        /// <returns>ModelDisplayObject created for the object.  Null if it couldn't be added.</returns>
        public ModelDisplayObjectBase Add(object objectToDisplay)
        {
            ModelDisplayObjectBase displayObject = GetDisplayObject(objectToDisplay);
            if (displayObject != null)
            {
                Add(displayObject);
                displayObjects.Add(objectToDisplay, displayObject);
                return displayObject;
            }
            return null; //Couldn't add it.
        }

        /// <summary>
        /// Attempts to add an object to the ModelDrawer with a specified texture index.
        /// </summary>
        /// <param name="objectToDisplay">Object to be added to the model drawer.</param>
        /// <param name="textureIndex">Integer index (0-7) of the model drawer texture to use</param>
        /// <returns>ModelDisplayObject created for the object.  Null if it couldn't be added.</returns>
        public ModelDisplayObjectBase Add(object objectToDisplay, int textureIndex)
        {
            ModelDisplayObjectBase displayObject = GetDisplayObject(objectToDisplay);
            if (displayObject != null)
            {                
                displayObject.TextureIndex = textureIndex;
                Add(displayObject);
                displayObjects.Add(objectToDisplay, displayObject);
                return displayObject;
            }
            return null; //Couldn't add it.
        }
It is probably best that you back up the ModelDrawer.cs file before changing it just in case you mess it up. :wink:

Hope someone finds this useful. I sure did. :)
Post Reply