Example #1
0
        private static void SCModelSave(Stream stream, Stream daeStream)
        {
            ModelData data = ModelContentReader.Read(stream, out bool b);

            stream.Dispose();
            ColladaExporter ex = new ColladaExporter();

            ex.AddModel(data);
            ex.Save(daeStream);
        }
        public void Export_SimpleModel_ValidOutput()
        {
            string path = "temp.dae";
            var e = new ColladaExporter();
            using (var stream = File.Create(path))
            {
                this.ExportSimpleModel(e, stream);
            }

            var result = this.Validate(path);
            Assert.IsNull(result, result);
        }
        protected void ExportSave(ColladaExporter exporter, string file_name)
        {
            exporter.ErrorOccured += new EventHandler <ColladaErrorEventArgs>(ExporterErrorOccured);
            bool success = exporter.BuildColladaInstance();

            exporter.ErrorOccured -= new EventHandler <ColladaErrorEventArgs>(ExporterErrorOccured);

            if (success)
            {
                exporter.SaveDAE(file_name);
            }
        }
Example #4
0
    /**
     * Generate asset.
     */
    public bool GenerateAsset(AssetReference asset, string generateAssetPath)
    {
        var animationClip = AssetDatabase.LoadAssetAtPath <AnimationClip>(asset.importFrom);

        if (animationClip == null)
        {
            return(false);
        }

        string          fullPath = FileUtility.PathCombine(Directory.GetParent(Application.dataPath).ToString(), generateAssetPath);
        ColladaExporter collada  = new ColladaExporter(fullPath, true);

        collada.AddObjectToScene(m_targetPrefab.Object, false);
        collada.AddAnimationClip(animationClip, m_targetPrefab.Object);

        collada.Save();

        Resources.UnloadAsset(animationClip);

        return(true);
    }
Example #5
0
	//-------------------------------------------------------------------------
	bool ExportMeshToFile() {
		
		ColladaExporter colladaWriter = new ColladaExporter();
		ColladaExporter.GeometryNode rootGeometryNode = new ColladaExporter.GeometryNode();
		
		Vector3[] jointVertices = null;
		int[] jointIndices = null;
		JoinVertexGroups(mColliderRegions, out jointVertices, out jointIndices);

		if (jointVertices == null || jointVertices.Length == 0) {
			CreateDummyTriangleToCreateAValidColladaFile(out jointVertices, out jointIndices);
		}
			
		rootGeometryNode.mName = "Collider";
		rootGeometryNode.mAreVerticesLeftHanded = true;
		rootGeometryNode.mVertices = jointVertices;
		rootGeometryNode.mTriangleIndices = jointIndices;
		rootGeometryNode.mGenerateNormals = true;

		float scaleX = GetOutputScaleX(true);
		float scaleY = GetOutputScaleY();
		
		colladaWriter.mVertexScaleAfterInitialRotation.x = scaleX; // the mesh is imported in a way that we end up correct this way.
		colladaWriter.mVertexScaleAfterInitialRotation.y = scaleY;
		colladaWriter.mVertexScaleAfterSecondRotation = Vector3.one;
		
		float atlasFrameRotation = mAtlasFrameRotation;
		if (mRegionIndependentParameters.CustomTex != null) {
			colladaWriter.mVertexScaleAfterInitialRotation.Scale(GetCustomImageScale());
			atlasFrameRotation = 0.0f;
		}
		
		// In order to rotate well, we need to compensate for the gameobject's
		// transform.scale that is applied automatically after all of our transforms.
		Vector3 automaticallyAppliedScale = this.transform.localScale;
		Vector3 rotationCompensationScaleBefore = new Vector3(automaticallyAppliedScale.x, automaticallyAppliedScale.y, 1.0f);
		Vector3 rotationCompensationScaleAfter = new Vector3(1.0f / automaticallyAppliedScale.x, 1.0f / automaticallyAppliedScale.y, 1.0f);
		colladaWriter.mVertexScaleAfterInitialRotation.Scale(rotationCompensationScaleBefore);
		colladaWriter.mVertexScaleAfterSecondRotation.Scale(rotationCompensationScaleAfter);
		
		colladaWriter.mVertexOffset.x = -mOutlineOffset.x -mRegionIndependentParameters.CustomOffset.x;
		colladaWriter.mVertexOffset.y = mOutlineOffset.y + mRegionIndependentParameters.CustomOffset.y;
		colladaWriter.mVertexOffset.z = -mOutlineOffset.z -mRegionIndependentParameters.CustomOffset.z;
		colladaWriter.mVertexTransformationCenter = new Vector3(0, 0, 0);
		colladaWriter.mVertexInitialRotationQuaternion = Quaternion.Euler(0, 0, -atlasFrameRotation);
		colladaWriter.mVertexSecondRotationQuaternion = Quaternion.Euler(0, 0,  -mRegionIndependentParameters.CustomRotation);
		
		System.IO.Directory.CreateDirectory(mColliderMeshDirectory);
		colladaWriter.ExportTriangleMeshToFile(FullColliderMeshPath(), rootGeometryNode);
		return true;
	}