Coder Social home page Coder Social logo

com.unity.palette-switch's Introduction

Palette Switch

A selection group is a collection of gameobjects.

We want to change material properties for all materials being used in a selection group, using a timeline clip which contains a collection of target materials with modifications by the user.

To enable this, we add a MaterialPropertyGroup component to the Runtime.SelectionGroup gameobject in the scene.

The MaterialPropertyGroup component stores a reference to all the sharedMaterials used by the selection group, then creates a copy of all those materials into an array called 'originalMaterials'. This component has methods for restoring the original material properties, and lerping the array of sharedMaterials towards an array of target materials.

The timeline needs to have a PaletteSwitchTrack. A MaterialProperyGroup component is assigned into the property slot on the track.

When a PaletteSwitchClip is added to the track, the ClipEditor for the track creates copies of the originalMaterials from the MaterialPropertyGroup component, and assigns those copies to the clip, and adds them as assets to the clip using AssetDatabase.AddObjectToAsset.

When the user selects the clip, the inspector shows the list of all materials on the clip, which can then be adjusted by the user. When the clip is played, the MaterialPropertyGroup.LerpTowards method is used to lerp the sharedMaterials towards the target materials on the clip. Note, this will change the material values for the selection group on disk. To reset the sharedMaterials to the original values, scrub to an empty area of the timeline, or right click the MaterialPropertyGroup component and choose 'Restore Original Materials'.

Unity does not support texture interpolation in Material.Lerp, however we could add this feature manually in MaterialPropertyGroup.LerpTowards if required in our use-cases.

Known Issues:

  • Any objects that are not part of the selection group that use the same shared materials from the selection group, will also be changed. To mitigate this problem, each selection group should not use shared materials with other groups. This could probably be enforced or made easier to configure using code, however this would introduce a new batch for each selection group, which may not be desirable.
  • If a material is updated, or a model changes materials, the MaterialPropertyGroup will no longer reflect the intended 'originalMaterial' and will need to be reset, as well as any PaletteSwitchClips and Tracks which use that MaterialPropertyGroup.

com.unity.palette-switch's People

Contributors

sindharta avatar smnwttbr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.