Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by alex_1302 · Oct 06, 2019 at 09:23 PM · animationhierarchylod

lod with animted hierarchy,question about lod implementation on animated hierarchy with animator

Hi. i was searching for some assets to make lod on animated characters, but i could not find any thing working on unity 2018.2. so i was thinking on write my own custom script to do that. the idea is basically replace every meshfilter mesh with the corresponding on other hierarchy (from the current lod level). i post the code so if somebody can tell me if this is a good idea or not.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class LOD_alex : MonoBehaviour
 {
 
     [System.Serializable]  // sin esto el array objetos no aparecerá en el inspector
     public struct _datosObjeto
     {
         public GameObject Plantillalod;
         [HideInInspector]
         public GameObject instantiatedLod;
         [Tooltip("no asignar. se asigna dinamicamente")]
         public float distancia;
     }
 
     public _datosObjeto[] lods;
 
     [System.Serializable]  // sin esto el array correspondencias no aparecerá en el inspector
     public struct _datosGizmos
     {
         public GameObject original;
         public int index;
     }
 
     public _datosGizmos[] correspondencias;
 
 
     public manager m;  // manager is a global class storing particular game data, such as the player camera
 
     private void Awake()
     {
         m = Object.FindObjectOfType<manager>();  // through the manager we access the players camera (see update method below)
 
         // DEBEMOS INSTANCIAR CADA PLANTILLALOD Y PONERLA EN INSTANTIATEDLOD PARA USARLA DESPUES Y O ESTAR CREANDO INSTANCIAS A CADA MOMENTO
         for (int i=0;i<lods.Length; i++)
         {
             if (lods[i].Plantillalod != null)
                 lods[i].instantiatedLod = Instantiate(lods[i].Plantillalod);
         }
     }
 
     // Use this for initialization
     void Start ()
     {
         
     }
 
     float timeRemaining=0;
     public float timeInterval=0.5f;
     int indiceLodActual = 0;
     
     // Update is called once per frame
     void Update ()
     {
         timeRemaining -= Time.deltaTime;
         if (timeRemaining > 0)
             return;
 
         timeRemaining = timeInterval;    
 
         // here calculates the distance from the players camera to this animated object
         float sqrDist=(m.cameraFPC.transform.position- transform.position).sqrMagnitude;
 
         for (int i=lods.Length-1;i>=0;i--) // traverse the lods on iverse order to determine the correct lod to select
         {
             if (sqrDist >= lods[i].distancia * lods[i].distancia && indiceLodActual!=i) // if the current lod is not the same that the lod to use, we change it
             {
                 // este es el lod que necesitamos colocar
                 reemplazarMeshLod(i);
                 indiceLodActual = i;
 
             }
         }
     }
 
     void reemplazarMeshLod(int indLod)
     {
         MeshFilter meshFilt=null;
         MeshFilter meshFilt2=null;
         for (int i=0;i<correspondencias.Length;i++)
         {
             meshFilt = correspondencias[i].original.GetComponentInChildren<MeshFilter>();
             if (i < lods[indLod].instantiatedLod.transform.childCount)
                 meshFilt2 = lods[indLod].instantiatedLod.transform.GetChild(i).GetComponent<MeshFilter>();
                 //meshFilt2=lods[indLod].instantiatedLod.transform.GetChild(i).GetComponentInChildren<MeshFilter>();
 
             if (meshFilt!=null && meshFilt2!=null)
             {
                 meshFilt.mesh = meshFilt2.mesh;
             }
         }
     }
 
 }


Thanks in advance.

,Hi. i was searching for some assets to make lod on animated characters, but i could not find any thing working on unity 2018.2. so i was thinking on write my own custom script to do that. the idea is basically replace every meshfilter mesh with the corresponding on other hierarchy (from the current lod level). i post the code so if somebody can tell me if this is a good idea or not.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class LOD_alex : MonoBehaviour
 {
 
     [System.Serializable]  // sin esto el array objetos no aparecerá en el inspector
     public struct _datosObjeto
     {
         public GameObject Plantillalod;
         [HideInInspector]
         public GameObject instantiatedLod;
         [Tooltip("no asignar. se asigna dinamicamente")]
         public float distancia;
     }
 
     public _datosObjeto[] lods;
 
     [System.Serializable]  // sin esto el array correspondencias no aparecerá en el inspector
     public struct _datosGizmos
     {
         public GameObject original;
         public int index;
     }
 
     public _datosGizmos[] correspondencias;
 
 
     public manager m;  // manager is a global class storing particular game data, such as the player camera
 
     private void Awake()
     {
         m = Object.FindObjectOfType<manager>();  // through the manager we access the players camera (see update method below)
 
         // DEBEMOS INSTANCIAR CADA PLANTILLALOD Y PONERLA EN INSTANTIATEDLOD PARA USARLA DESPUES Y O ESTAR CREANDO INSTANCIAS A CADA MOMENTO
         for (int i=0;i<lods.Length; i++)
         {
             if (lods[i].Plantillalod != null)
                 lods[i].instantiatedLod = Instantiate(lods[i].Plantillalod);
         }
     }
 
     // Use this for initialization
     void Start ()
     {
         
     }
 
     float timeRemaining=0;
     public float timeInterval=0.5f;
     int indiceLodActual = 0;
     
     // Update is called once per frame
     void Update ()
     {
         timeRemaining -= Time.deltaTime;
         if (timeRemaining > 0)
             return;
 
         timeRemaining = timeInterval;    
 
         // here calculates the distance from the players camera to this animated object
         float sqrDist=(m.cameraFPC.transform.position- transform.position).sqrMagnitude;
 
         for (int i=lods.Length-1;i>=0;i--) // traverse the lods on iverse order to determine the correct lod to select
         {
             if (sqrDist >= lods[i].distancia * lods[i].distancia && indiceLodActual!=i) // if the current lod is not the same that the lod to use, we change it
             {
                 // este es el lod que necesitamos colocar
                 reemplazarMeshLod(i);
                 indiceLodActual = i;
 
             }
         }
     }
 
     void reemplazarMeshLod(int indLod)
     {
         MeshFilter meshFilt=null;
         MeshFilter meshFilt2=null;
         for (int i=0;i<correspondencias.Length;i++)
         {
             meshFilt = correspondencias[i].original.GetComponentInChildren<MeshFilter>();
             if (i < lods[indLod].instantiatedLod.transform.childCount)
                 meshFilt2 = lods[indLod].instantiatedLod.transform.GetChild(i).GetComponent<MeshFilter>();
                 //meshFilt2=lods[indLod].instantiatedLod.transform.GetChild(i).GetComponentInChildren<MeshFilter>();
 
             if (meshFilt!=null && meshFilt2!=null)
             {
                 meshFilt.mesh = meshFilt2.mesh;
             }
         }
     }
 
 }
 


Thanks in advance and every suggestion will be very good received.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

359 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I remove this 'shadow' from my LOD?? 0 Answers

Wrong root node from separated anmation fbx model. 0 Answers

Dont destroy on load results in new scene with all deleted objects c# 1 Answer

Ragdoll Collider problem 0 Answers

Checking a gameObject active in hierarchy not working. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges