• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How to make a model change textures ingame

Level 7
Joined
Jan 28, 2012
Messages
266

1.0 Modeling

2.0 Using this in your map

3.0 Conclusion




1.0 Modeling
to do this I used Magos's Model Editor​

1.1 Overview
all you are going to do is add an alpha tile texture to your model, set its replaceable id to 31 then add as a material layer on top of materials that you want to change their texture, and making sure to set filter type to transparent
if this is enough information for you, edit a model and head onto 2.0 if not keep reading
Go To Index

1.2 Walkthrough

First off you will want to go to the texture manager window>Texture Manager

attachment.php


next import a alpha tile into the texture manager: RightClick>Import
i am using the alpha tile from De.Factos Tutorial

then edit the new texture: Right Click it>Edit

attachment.php


Then set its replacable id to 31

attachment.php


Go To Index

1.3 Editing Materials

First Go to the Material Manager: Window>Material Manager

attachment.php


then right click the first material edit it and then look at its material layers,if it is the main texture of the model

attachment.php

Create a new material: Right click> Create New

attachment.php

set its texture to your texture

attachment.php


set its filter mode to transparent, if you look at the model, when your done, and it is completely black you forgot to set its filter mode to transparent

attachment.php

Go To Index

2.0 Using This in your map
Have any of you evr noticed the mountain giants warclub ability? and how depending on what tree He picks up, he has a different looking club? This will require one ability + however many textures you intend on using.​
2.1 Making the Ability
first off, in the object editor create a new ability based on warclub, name it Texture Changer

attachment.php

then select it and set Data- maximum attacks to 0
attachment.php

then select disable attacks, press shift enter and set it to 3

attachment.php

do the same thing for Data - Enable Attack and then set the other purple data to the values i have set them(this is to make it almost instant)​
2.2 Making the Destructables
First off you are going to create a new destructible, base it off of a tree
attachment.php


Next set its Fly height to 0.00 this is to prevent it from modifying flying units heights for a brief instant.

attachment.php


set its replaceable texture to your textures path,

attachment.php


set its pathing to none this is to prevent it from pushing units around
attachment.php


Go To Index

2.3 Triggering it
Look at at which ever explanation you want, what you'll be doing is creating a destructible, adding Texture Changer(the ability you made early) to the unit, ordering it to cast, removing Texture Changer, and then waiting and removing the destructible(to prevent a build up of destructible's.
JASS:
function change texture takes unit u, integer dtype returns nothing
     local real a = GetUnitFacing(u)*bj_DEGTORAD//What i am doing here is converting the units facing   angle into radians, though why blizzard doesn't have them use a radians is beyond me
    local destructable d = CreateDestructible(dtype,GetUnitX(u) + 12*Cos(a),GetUnitY(u) + 12*Sin(a),0,.1,1)
    //this just creates a destructable in front of the unit, to make so
    // that the unit can insta cast
    // IMPORTANT remembber to make sure all destructables that you are
    // using have no pathing, otherwise they will move the unit backwards.

    call UnitAddAbility(u,TEXTURE_CHANGER)
    // adding the texture changing ability to the unit, WARNING
     // this could conflict with a unit  that has war club, if this could be a
    // concern add an if here that checks if the unit has the ability warclub
    call IssueTargetOrder(u,"warclub",d)
    //a better way to do this would be using IssueTargetOrderById,
    // but i am to lazy to look up  the order id:)
    call UnitRemoveAbility(u,TEXTURE_CHANGER)
    //what this does is cause warcraft 3 to instantly cast this spell
    // i wish i had a long complicated reason to give you, but i don't.
    call RemoveDestructable(d)
    // originally I put a wait between this and the remove ability but it isn't needed
endfunction
  • Actions
    • Set TempPoint = (Position of (Triggering unit))
    • -------- ---------- ------------ --------- --------
    • -------- Setting the position of the unit to a --------
    • -------- point in order to prevent leaks --------
    • -------- using xy coords is better but that --------
    • -------- requires some jass knowledge --------
    • -------- ---------- ------------ --------- --------
    • Set TempPoint2 = (TempPoint offset by 12.00 towards (Facing of (Triggering unit)) degrees)
    • -------- ---------- ------------ --------- --------
    • -------- same as above, but this time we are --------
    • -------- putting the point in front of the unit, --------
    • -------- so it doesn't have to turn to cast --------
    • -------- ---------- ------------ --------- --------
    • Destructible - Create a Alpha at TempPoint facing 0.00 with scale 0.01 and variation 0
    • -------- ---------- ------------ --------- --------
    • -------- Creating a destructable, remember --------
    • -------- make sure the destructable you are --------
    • -------- using does not have any pathing --------
    • -------- ---------- ------------ --------- --------
    • Unit - Add TextureChanger to (Triggering unit)
    • -------- ---------- ------------ --------- --------
    • -------- Add the ability to the unit, so it can cast --------
    • -------- it --------
    • -------- ---------- ------------ --------- --------
    • Unit - Order (Triggering unit) to Night Elf Mountain Giant - War Club (Last created destructible)
    • -------- ---------- ------------ --------- --------
    • -------- pretty basic, just ordering the unit to --------
    • -------- cast the ability WARNING this can --------
    • -------- conflict with the warclub ability --------
    • -------- so i recomend that you don't use --------
    • -------- units that have the warclub ability --------
    • -------- ---------- ------------ --------- --------
    • Unit - Remove TextureChanger from (Triggering unit)
    • -------- ---------- ------------ --------- --------
    • -------- removing an ability after you order a unit --------
    • -------- to cast it causes the unit to instant --------
    • -------- cast that ability, provided that the --------
    • -------- unit doesn't have to turn to face the --------
    • -------- target --------
    • -------- ---------- ------------ --------- --------
    • Destructible - Remove (Last created destructible)
    • -------- ---------- ------------ --------- --------
    • -------- Removing the destructible to prevent --------
    • -------- a build up of dead destructables --------
    • -------- ---------- ------------ --------- --------
    • Custom script: call RemoveLocation(udg_TempPoint)
    • Custom script: call RemoveLocation(udg_TempPoint2)
    • Custom script: set udg_TempPoint = null
    • Custom script: set udg_TempPoint2 = null
    • -------- ---------- ------------ --------- --------
    • -------- Removing location leaks --------
    • -------- ---------- ------------ --------- --------
    • Custom script: set bj_lastCreatedDestructable = null
    • -------- ---------- ------------ --------- --------
    • -------- this is to prevent the destructable from --------
    • -------- creating a minute leak which all --------
    • -------- Handles will do if you don't null --------
    • -------- variables that you set to them --------
    • -------- ---------- ------------ --------- --------
you will also need to use a method to make units who enter the map change their texture to the alpha tile(I use bribes unit indexer), because for some reason the units appear white(anyone who figures out a solution for this problem please tell me)
Go To Index

3.0 Conclusion
I hoped you learned from this tutorial, please comment and give suggestions for improvment

Go To Index


3.1 View attachment Complicated Texture Switcher.w3x

 

Attachments

  • Texture Manager.jpg
    Texture Manager.jpg
    16.4 KB · Views: 4,841
  • Material Manager.jpg
    Material Manager.jpg
    16.3 KB · Views: 4,680
  • EditTexture2.jpg
    EditTexture2.jpg
    26.6 KB · Views: 4,715
  • EditTexture.jpg
    EditTexture.jpg
    5 KB · Views: 4,650
  • CreateNew Material Layer.jpg
    CreateNew Material Layer.jpg
    4 KB · Views: 4,596
  • MaterialEditLoksLike.jpg
    MaterialEditLoksLike.jpg
    24.8 KB · Views: 4,707
  • Selecting Filter Mode.jpg
    Selecting Filter Mode.jpg
    5.2 KB · Views: 4,633
  • Selecting texture.jpg
    Selecting texture.jpg
    39 KB · Views: 4,726
  • Object Editor WarClub.jpg
    Object Editor WarClub.jpg
    42.8 KB · Views: 4,750
  • ObjectEditor DeisableAttack.jpg
    ObjectEditor DeisableAttack.jpg
    65.6 KB · Views: 4,648
  • ObjectEditor Max Attacks.jpg
    ObjectEditor Max Attacks.jpg
    64.6 KB · Views: 4,648
  • Destruct  Make Your Destructable.jpg
    Destruct Make Your Destructable.jpg
    38.7 KB · Views: 4,649
  • Destruct FlyHeight.jpg
    Destruct FlyHeight.jpg
    83.1 KB · Views: 4,707
  • Destruct Pathing.jpg
    Destruct Pathing.jpg
    128.1 KB · Views: 4,666
  • Destruct Replace Texture.jpg
    Destruct Replace Texture.jpg
    136.9 KB · Views: 4,824
Last edited by a moderator:

Kazeon

Hosted Project: EC
Level 33
Joined
Oct 12, 2011
Messages
3,449
no comment?

Is this a safe way to change texture in-game? bcs I want to implement this to FSI so user could change inventory theme anytime and to evade uselessly recreating destructables for icons. By using unit as UI and button I can also initialy preload them and add SetInventoryPosition functionality maybe..

a very useful tutorial.. thanks..
 
no comment?

Is this a safe way to change texture in-game? bcs I want to implement this to FSI so user could change inventory theme anytime and to evade uselessly recreating destructables for icons. By using unit as UI and button I can also initialy preload them and add SetInventoryPosition functionality maybe..

a very useful tutorial.. thanks..

It is indeed a safe way, but you still have to make object data for the different textures.

This is useful for dynamically changing unit textures, though.
 

Kazeon

Hosted Project: EC
Level 33
Joined
Oct 12, 2011
Messages
3,449
It is indeed a safe way, but you still have to make object data for the different textures.
yup, that's right.. but we got many advantages by only changing the texture, especially for dragging feature ;) and also we can preload the button units first..

so is this still working if the unit is building? I want to set the button unit to a building so facing angle is not changed when casting the spell..

I got a basic question, is that building/structure unit has collision after we add locust to it?
 

Kazeon

Hosted Project: EC
Level 33
Joined
Oct 12, 2011
Messages
3,449
Here is a correction to the jass code:
JASS:
function change_texture takes unit u, integer dtype returns nothing
    local real a = GetUnitFacing(u)*bj_DEGTORAD//What i am doing here is converting the units facing   angle into radians, though why blizzard doesn't have them use a radians is beyond me 
    local destructable d = CreateDestructible(dtype,GetUnitX(u) + 12*Cos(a),GetUnitY(u) + 12*Sin(a),0,.1,1)
    //this just creates a destructable in front of the unit, to make so
    // that the unit can insta cast
    // IMPORTANT remembber to make sure all destructables that you are
    // using have no pathing, otherwise they will move the unit backwards.

    call UnitAddAbility(u,TEXTURE_CHANGER)
    // adding the texture changing ability to the unit, WARNING
     // this could conflict with a unit  that has war club, if this could be a
    // concern add an if here that checks if the unit has the ability warclub
    call IssueTargetOrderById(whichUnit, 852511, d)
    //a better way to do this would be using IssueTargetOrderById,
    // but i am to lazy to look up  the order id:)
    call UnitRemoveAbility(u,TEXTURE_CHANGER)
    //what this does is cause warcraft 3 to instantly cast this spell
    // i wish i had a long complicated reason to give you, but i don't.
    call RemoveDestructable(d)
    // originally I put a wait between this and the remove ability but it isn't needed
    set d = null
endfunction
 
Level 23
Joined
Jan 1, 2011
Messages
1,504
Bit of a necro but it is important. You can create the texture changing destructables on init and move units directly on top of them and cast the ability. Then you revive the destructable and you effectively have infinite uses from the texture changing destructables. This is (probably) faster than creating a destructable with polar projection (which also has issues for units out of bounds). I also read somewhere that creating and removing destructables causes leaks over time so this also helps with that.

JASS:
    function SetUnitTexture takes unit u, destructable d returns nothing
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        call SetUnitX(u,0)
        call SetUnitY(u,0)
        call DestructableRestoreLife(d,5,false)
        call UnitAddAbility(u,Texture_Abil)
        call IssueTargetOrder(u,"grabtree",d)
        call UnitRemoveAbility(u,Texture_Abil)
        call SetUnitX(u,x)
        call SetUnitY(u,y)
    endfunction
 
Top