playMaker

Author Topic: fsmTexture to Texture2D for Lightmaps  (Read 5635 times)

adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
fsmTexture to Texture2D for Lightmaps
« on: October 24, 2013, 09:08:53 AM »
Hi guys, I have spent all day trying to make a script that I can use outside of Playmaker, but interact with Global variables etc I am not great with scripts, which is why I love Playmaker! What I am trying to do is create a new lightmap array to contain two light maps. i would then like to use a texture, that is loaded to a global variable in playmaker, that I have downloaded and loaded from an assetbundle. I think I have the array being created correctly, but now I need to load the texture into the array. Before I get that far, I am struggling to get the fmsTexture part of the scrip to work. The texture will need to be a Texture2D in order for the script to compile. I have posted my script below, please note i have removed my attempts at converting the texture to a Texture2D and have put it back to an earlier revision but it still doesn't compile because I cannot convert type to Texture this way either. Any help would be much appreciated

Code: [Select]
using UnityEngine;
using System.Collections;
using HutongGames.PlayMaker;



public class Lightmaps : MonoBehaviour
{

private FsmTexture getlightmapFsmTex;
private Texture Lightmap;

void Start( )
{
getlightmapFsmTex = FsmVariables.GlobalVariables.GetFsmTexture("Lightmap");
Lightmap = getlightmapFsmTex;
}

private void LightMapArray ()
{
LightmapData[] lightmapData = new LightmapData[2];
 
    for(int i = 0 ; i < 2 ; i++ )
        lightmapData[i] = new LightmapData();
 
    for( int i = 0 ; i < 2 ; i++ )
    {                     
        lightmapData[i].lightmapFar = Lightmap;
    }
    LightmapSettings.lightmaps = lightmapData;
}
}

adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
Re: fsmTexture to Texture2D for Lightmaps
« Reply #1 on: October 25, 2013, 06:06:56 AM »
anybody got any ideas? Still pretty stuck on this

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: fsmTexture to Texture2D for Lightmaps
« Reply #2 on: October 26, 2013, 03:15:58 AM »
Hi,

 In order to access the Texture2d stored in a FsmTexture, use .Value like so:

Code: [Select]
Lightmap = getlightmapFsmTex.Value;


Bye,

 Jean

adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
Re: fsmTexture to Texture2D for Lightmaps
« Reply #3 on: October 26, 2013, 05:51:35 AM »
cheers jean, that definitely gets rid of the fsm conversion error. Now i get a texture/texture2D error

 Cannot implicitly convert type `UnityEngine.Texture' to `UnityEngine.Texture2D'. An explicit conversion exists (are you missing a cast?)

This seems to be coming from me trying to apply the texture into the lightmap array, and it needs to be a texture2D. Confused!

Thanks so much for your help

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: fsmTexture to Texture2D for Lightmaps
« Reply #4 on: October 26, 2013, 08:25:50 AM »
Hi,

 Simply cast it as required ( it's frequent with textures)

Code: [Select]
Lightmap = (Texture2D) getlightmapFsmTex.Value;
or

Code: [Select]
Lightmap = getlightmapFsmTex.Value as Texture2D;
Bye,

 Jean
Bye,

 Jean

adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
Re: fsmTexture to Texture2D for Lightmaps
« Reply #5 on: October 26, 2013, 11:35:42 AM »
That seems to be getting me somewhere. No errors anymore! The texture isn't being applied to the new lightmap array though, I have seen a warning that the variable has been found but not assigned. I cant see how it isn't being applied! The texture in the variable is named as it was before, lightmapFar-0, and I have removed all other lightmaps from the scene so that everything is being created from scratch.

Code: [Select]
using UnityEngine;
using System.Collections;
using HutongGames.PlayMaker;



public class Lightmaps : MonoBehaviour
{

private FsmTexture getlightmapFsmTex;
private Texture2D Lightmap;

void Start ()
{
getlightmapFsmTex = FsmVariables.GlobalVariables.GetFsmTexture("LightMap");
Lightmap = getlightmapFsmTex.Value as Texture2D;
}

private void LightMapArray ()
{
LightmapData[] lightmapData = new LightmapData[2];// LightmapSettings.lightmaps;
       
for(int i = 0 ; i < 2 ; i++ )
{
        lightmapData[i] = new LightmapData();
}
for( int i = 0 ; i < 2 ; i++ )

    {                     
        lightmapData[i].lightmapFar = Lightmap;
}
        LightmapSettings.lightmaps = lightmapData;
}
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: fsmTexture to Texture2D for Lightmaps
« Reply #6 on: October 27, 2013, 03:36:09 AM »
Hi,

 Never actually tried to modifiy lightmap texture this way, are you sure you are well documented on how to edit lightmapping? it could be something you overlooked as to the actual process itself ( be it done with or without playmaker)

bye,

 Jean

adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
Re: fsmTexture to Texture2D for Lightmaps
« Reply #7 on: October 27, 2013, 05:36:37 AM »
I've read everything I could possibly find before posting. Forums, documentation etc it seems to be a very under discussed process, which is a nightmare for a non programmer like me!lol just trying to find someone who may have done it before or can spot something in my script that is a basic mistake or something

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: fsmTexture to Texture2D for Lightmaps
« Reply #8 on: October 28, 2013, 01:39:39 AM »
Hi,

 Ok, good luck with this, If you are going nowhere, get back to me next week or something, I'll see if I can allocate some time to look into this.

bye,

 Jean

adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
Re: fsmTexture to Texture2D for Lightmaps
« Reply #9 on: October 28, 2013, 03:49:55 AM »
Thanks Jean. I will drop a post in here if I get it working at some point :-)

adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
Re: fsmTexture to Texture2D for Lightmaps
« Reply #10 on: October 30, 2013, 01:25:55 PM »
We managed to get this working, I have included the script below. It gets the lightmap from a global variable and creates a lightmap array. I need to get this to work with multiple lightmaps now and assign them to specific locations in the array. This allows me to store lightmaps with models in assetbundles and load different lightmaps for different scene models. If you ever add some lightmap stuff into playmaker, I think being able to create a lightmap array and assign textures to it at runtime would be great. Thanks for your help Jean

Code: [Select]
using UnityEngine;
using System.Collections;
using HutongGames.PlayMaker;



public class Lightmaps : MonoBehaviour
{

public FsmTexture getlightmapFsmTex;
public Texture2D Lightmap;
LightmapData[] lightmapData;
bool isLoad = false;

void Start ()
{
}

void Update()
{
if(!isLoad)
{
getlightmapFsmTex = FsmVariables.GlobalVariables.GetFsmTexture("LightMap");

if(getlightmapFsmTex == null) return;

Lightmap = getlightmapFsmTex.Value as Texture2D;

if(Lightmap != null) isLoad= true;
}
}

private void LightMapArray ()
{
lightmapData = new LightmapData[2];// LightmapSettings.lightmaps;
       
for(int i = 0 ; i < 2 ; i++ )
{
        lightmapData[i] = new LightmapData();
}
for( int i = 0 ; i < 2 ; i++ )

    {                     
        lightmapData[i].lightmapFar = Lightmap;
}
        LightmapSettings.lightmaps = lightmapData;
}
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: fsmTexture to Texture2D for Lightmaps
« Reply #11 on: October 31, 2013, 03:45:16 AM »
Hi,

 have you played with ArrayMaker yet?

bye,

 Jean

adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
Re: fsmTexture to Texture2D for Lightmaps
« Reply #12 on: October 31, 2013, 07:48:57 AM »
I have started with another part of the project, I wouldnt know where to start in creating the lightmap array with it though. I would have to get it to over ride the lightmapData array that is automatically created within Unity. It would certainly make my life easier if I could do that that script is doing within Playmaker and Arraymaker though for sure

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: fsmTexture to Texture2D for Lightmaps
« Reply #13 on: October 31, 2013, 08:13:02 AM »
Hi,

 LightMap data is too complex for ArrayMaker to handle by default, but storing some kind of reference to what you need to change is possible already using a hashtable and some convention you setup for the occasion.

bye,

 Jean

adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
Re: fsmTexture to Texture2D for Lightmaps
« Reply #14 on: October 31, 2013, 08:14:32 AM »
Ok, so I could store the lightmap textures in a hashtable for instance?