Beispiel #1
0
    public void StartMorphingModel(int _ChunkIndex, MODELTYPE _ModelType)
    {
        if (false == m_MorphingData.ContainsKey(_ChunkIndex))
        {
            m_MorphingData.Add(_ChunkIndex, new MorphingStruct());
        }

        MorphingStruct morphData = null;

        morphData = m_MorphingData[_ChunkIndex];
        morphData.isInMorphing = true;


        string modelstr = GenerateModelStringFromTemplateSetting(_ChunkIndex, _ModelType);

        Mesh_VoxelChunk Mesh = m_ShareMeshData as Mesh_VoxelChunk;

        if (null != Mesh)
        {
            string chunkKey = GenerateChunkKeyFromIndex(_ChunkIndex);
            Mesh.StartMorphingModel(chunkKey, modelstr, morphData);
        }
    }
Beispiel #2
0
	public void StartMorphingModel(string chunkKey 
		, string newModelStr 
		, MorphingStruct _MorphingData )
	{
		// Debug.Log("MoveChunkModel chunk=" + chunkKey + " model=" + newModelStr );
		
		Chunk attachedChunkData = null ;
		if ( false == m_ChunkMap.TryGetValue(chunkKey, out attachedChunkData))
		{
			Debug.LogError("StartMorphingModel() false == m_ChunkMap.TryGetValue chunkKey=" + chunkKey );
			return ;
		}
		
		var listObjCache = m_ChunkCache ;
		List<GameObject> allOrgModelList;
		if ( false == listObjCache.TryGetValue(chunkKey, out allOrgModelList))
		{
			Debug.LogError("StartMorphingModel() false == listObjCache.TryGetValue chunkKey=" + chunkKey );
			return; 
		}
		
		var storageModelDataMap = m_ModelMap ;
		Chunk newModelChunkData = null ;
		if ( false == storageModelDataMap.TryGetValue(newModelStr, out newModelChunkData))
		{
			Debug.LogError("StartMorphingModel() false == storageModelDataMap.TryGetValue newModelStr=" + newModelStr );
			return ;
		}
		
		
		// every time start morphing, we clear old game object.
		_MorphingData.morphVec.Clear() ;
		foreach (GameObject o in allOrgModelList) 
		{
			var morphObj = new MorphingObj() ;
			morphObj.GameObj = o ;
			_MorphingData.morphVec.Add( morphObj ) ;
		}
		// Debug.LogWarning("StartMorphingModel() _MorphingData.morphVec.Count=" + _MorphingData.morphVec.Count );
		
		Vector2 gridWidthHeight = newModelChunkData.Size;
		Vector2 newModelScale = newModelChunkData.Scale;
		Vector3 referencePos = attachedChunkData.LocalPos + newModelChunkData.LocalPos;
		int[] gridAttributes = newModelChunkData.Vertex;
		
		Vector3 localScale = root.transform.localScale;
		int _w = (int)gridWidthHeight.x;
		int _h = (int)gridWidthHeight.y;
		int _TotalGridSize = _w * _h;
		
		// first phase we all all possible position.
		List<Vector3> validPositionVec = new List<Vector3>() ;
		List<Color> validColorVec = new List<Color>() ;
		for (int i = 0; i < _TotalGridSize ; ++i)
		{
			int voxel = gridAttributes[i];
			Vector3 targetPos = Vector3.zero ;
			Color targetColor ;
			if (voxel > 0 )
			{
				targetPos = this.CalculatePositionFromRootPosition( root.transform.position 
				                                                   , localScale 
				                                                   , newModelScale 
				                                                   , referencePos , _w , _h , i ) ;
				
				
				validPositionVec.Add( targetPos ) ;
				
				
				targetColor = this.CalculateColorFromRootPosition( voxel ) ;
				// Debug.LogWarning("StartMorphingModel() targetColor=" + targetColor );
				validColorVec.Add( targetColor ) ;
				
			}		
		}
		// Debug.LogWarning("StartMorphingModel() _MorphingData.morphVec.Count=" + _MorphingData.morphVec.Count );
		// Debug.LogWarning("StartMorphingModel() validPositionVec.Count=" + validPositionVec.Count );
		
		// second phase we randomize the vector
		CollectionUtility.List_Vector3Color_Shuffle( validPositionVec , validColorVec ) ;
		
		// third phase we try mapping morph object to those shuffled position.
		int mappingIndex = 0 ;
		for (int i = 0; i < _MorphingData.morphVec.Count && validPositionVec.Count > 0 ; ++i)
		{
			_MorphingData.morphVec[ i ].Target = validPositionVec[ mappingIndex ] ;
			_MorphingData.morphVec[ i ].DestinationColor = validColorVec[ mappingIndex ] ;
			// Debug.Log ("validColorVec[ mappingIndex ]" + validColorVec[ mappingIndex ] );
			if ( i < validPositionVec.Count )// if our morph object more than valid position
			{
				++mappingIndex ;// everty time we used one slot, plus one.
			}
		}
		// Debug.LogWarning("StartMorphingModel() indexValidPosition=" + indexValidPosition );
	}
Beispiel #3
0
    public void StartMorphingModel(string chunkKey
                                   , string newModelStr
                                   , MorphingStruct _MorphingData)
    {
        // Debug.Log("MoveChunkModel chunk=" + chunkKey + " model=" + newModelStr );

        Chunk attachedChunkData = null;

        if (false == m_ChunkMap.TryGetValue(chunkKey, out attachedChunkData))
        {
            Debug.LogError("StartMorphingModel() false == m_ChunkMap.TryGetValue chunkKey=" + chunkKey);
            return;
        }

        var listObjCache = m_ChunkCache;
        List <GameObject> allOrgModelList;

        if (false == listObjCache.TryGetValue(chunkKey, out allOrgModelList))
        {
            Debug.LogError("StartMorphingModel() false == listObjCache.TryGetValue chunkKey=" + chunkKey);
            return;
        }

        var   storageModelDataMap = m_ModelMap;
        Chunk newModelChunkData   = null;

        if (false == storageModelDataMap.TryGetValue(newModelStr, out newModelChunkData))
        {
            Debug.LogError("StartMorphingModel() false == storageModelDataMap.TryGetValue newModelStr=" + newModelStr);
            return;
        }


        // every time start morphing, we clear old game object.
        _MorphingData.morphVec.Clear();
        foreach (GameObject o in allOrgModelList)
        {
            var morphObj = new MorphingObj();
            morphObj.GameObj = o;
            _MorphingData.morphVec.Add(morphObj);
        }
        // Debug.LogWarning("StartMorphingModel() _MorphingData.morphVec.Count=" + _MorphingData.morphVec.Count );

        Vector2 gridWidthHeight = newModelChunkData.Size;
        Vector2 newModelScale   = newModelChunkData.Scale;
        Vector3 referencePos    = attachedChunkData.LocalPos + newModelChunkData.LocalPos;

        int[] gridAttributes = newModelChunkData.Vertex;

        Vector3 localScale     = root.transform.localScale;
        int     _w             = (int)gridWidthHeight.x;
        int     _h             = (int)gridWidthHeight.y;
        int     _TotalGridSize = _w * _h;

        // first phase we all all possible position.
        List <Vector3> validPositionVec = new List <Vector3>();
        List <Color>   validColorVec    = new List <Color>();

        for (int i = 0; i < _TotalGridSize; ++i)
        {
            int     voxel     = gridAttributes[i];
            Vector3 targetPos = Vector3.zero;
            Color   targetColor;
            if (voxel > 0)
            {
                targetPos = this.CalculatePositionFromRootPosition(root.transform.position
                                                                   , localScale
                                                                   , newModelScale
                                                                   , referencePos, _w, _h, i);


                validPositionVec.Add(targetPos);


                targetColor = this.CalculateColorFromRootPosition(voxel);
                // Debug.LogWarning("StartMorphingModel() targetColor=" + targetColor );
                validColorVec.Add(targetColor);
            }
        }
        // Debug.LogWarning("StartMorphingModel() _MorphingData.morphVec.Count=" + _MorphingData.morphVec.Count );
        // Debug.LogWarning("StartMorphingModel() validPositionVec.Count=" + validPositionVec.Count );

        // second phase we randomize the vector
        CollectionUtility.List_Vector3Color_Shuffle(validPositionVec, validColorVec);

        // third phase we try mapping morph object to those shuffled position.
        int mappingIndex = 0;

        for (int i = 0; i < _MorphingData.morphVec.Count && validPositionVec.Count > 0; ++i)
        {
            _MorphingData.morphVec[i].Target           = validPositionVec[mappingIndex];
            _MorphingData.morphVec[i].DestinationColor = validColorVec[mappingIndex];
            // Debug.Log ("validColorVec[ mappingIndex ]" + validColorVec[ mappingIndex ] );
            if (i < validPositionVec.Count)     // if our morph object more than valid position
            {
                ++mappingIndex;                 // everty time we used one slot, plus one.
            }
        }
        // Debug.LogWarning("StartMorphingModel() indexValidPosition=" + indexValidPosition );
    }