//Set the slider to the value of f public void changeOpacity(float f) { MeshMaterialControl moc = gameObjectToChangeOpacity.GetComponent <MeshMaterialControl> (); if (moc != null) { moc.changeOpactiyOfChildren(f); } }
void Update() { if (loadingEffectActive) { loadingAmount = loadingAmount + 0.5f * Time.deltaTime; foreach (GameObject o in loadedObjects) { MeshMaterialControl matControl = o.gameObject.transform.parent.GetComponent <MeshMaterialControl> (); if (matControl != null) { matControl.SetLoadingEffectAmount(loadingAmount); } } if (loadingAmount > 1) { loadingEffectActive = false; } } }
void setMeshOpacity(string name, float opacity) { // First, find the GameObject which holds the mesh given by "name" GameObject gameObjectToChangeOpacity = null; foreach (GameObject g in mMeshLoader.MeshGameObjectContainers) { if (g.name == name) { gameObjectToChangeOpacity = g; break; } } // If we found such a GameObject, then set the opacity for all it's children (the meshes): if (gameObjectToChangeOpacity != null) { MeshMaterialControl moc = gameObjectToChangeOpacity.GetComponent <MeshMaterialControl> (); if (moc != null) { moc.changeOpactiyOfChildren(opacity); } } }
/*! This methode creates the game object of new mesh and runs as coroutine. * The loaded meshs are splitted in little part. Only on part of a mesh will be process each frame */ private IEnumerator LoadFileExecute() { Bounds bounds = new Bounds(); bool boundsInitialized = false; // set to true when bounds is first set // meshNode // | - containerObject // | - actual mesh // | - actual mesh // | - actual mesh // | - ... // | - containerObject // | - actual mesh // | - actual mesh // | - actual mesh // | - ... // | ... foreach (List <UnityMesh> um in unityMeshes) { GameObject containerObject = new GameObject(um[0].Name); containerObject.layer = meshNode.layer; //Set same layer as parent containerObject.transform.SetParent(meshNode.transform, false); //containerObject.transform.localScale = new Vector3 (400.0f, 400.0f, 400.0f); containerObject.transform.localPosition = new Vector3(0, 0, 0); MeshMaterialControl matControl = containerObject.AddComponent <MeshMaterialControl> (); Color col = matColorForMeshName(um[0].Name); matControl.materialColor = col; MeshGameObjectContainers.Add(containerObject); //attach BlenderObject to containerObject foreach (BlenderObjectBlock b in blenderObjects) { if (b.uniqueIdentifier == um[0].UniqueIdentifier) { BlenderObject attachedObject = containerObject.AddComponent <BlenderObject>(); //TODO Remove... maybe attachedObject.objectName = b.objectName; attachedObject.location = b.location; attachedObject.rotation = b.rotation; //Convert to left-handed soordinate systems containerObject.transform.localPosition = new Vector3(b.location.x, b.location.y, -b.location.z); /* TODO * Quaternion rot = Quaternion.Inverse(b.rotation); * rot = new Quaternion(-rot.x, -rot.z, rot.y, -rot.w); * containerObject.transform.localRotation = rot; */ } } foreach (UnityMesh unityMesh in um) { //Spawn object GameObject objToSpawn = new GameObject(unityMesh.Name); objToSpawn.layer = meshNode.layer; //Set same layer as parent objToSpawn.transform.SetParent(containerObject.transform, false); //Add Components objToSpawn.AddComponent <MeshFilter>(); objToSpawn.AddComponent <MeshCollider>(); //TODO need to much time --> own thread?? Dont work in Unity!! objToSpawn.AddComponent <MeshRenderer>(); //Create Mesh Mesh mesh = new Mesh(); mesh.name = unityMesh.Name; mesh.vertices = unityMesh.VertexList; mesh.normals = unityMesh.NormalList; mesh.triangles = unityMesh.TriangleList; objToSpawn.GetComponent <MeshFilter>().mesh = mesh; objToSpawn.GetComponent <MeshCollider>().sharedMesh = mesh; //TODO Reduce mesh?? objToSpawn.transform.localPosition = new Vector3(0, 0, 0); unityMeshes = new List <List <UnityMesh> >(); loaded = false; Path = ""; // Increase the common bounding box to contain this object: // Calculate bounds in Bounds worldBounds = TransformUtil.TransformBounds(objToSpawn.transform.parent, mesh.bounds); Bounds localBounds = TransformUtil.InverseTransformBounds(containerObject.transform.parent, worldBounds); if (!boundsInitialized) { bounds = localBounds; boundsInitialized = true; } else { bounds.Encapsulate(localBounds); } // Let others know that a new mesh has been loaded: PatientEventSystem.triggerEvent(PatientEventSystem.Event.MESH_LoadedSingle, objToSpawn); // Make sure the color of the material is set correctly: matControl.changeOpactiyOfChildren(1f); // Deactivate for now, let someone else activate the mesh when needed: objToSpawn.SetActive(false); yield return(null); } } // Move the object by half the size of all of the meshes. // This makes sure the object will rotate around its actual center: //containerObject.transform.localPosition = -bounds.center; meshNode.GetComponent <ModelMover> ().targetPosition = Vector3.Scale(-bounds.center, meshNode.transform.localScale); triggerEvent = true; yield return(null); }