Exemple #1
0
func Export(object export.Exportable) error {
	var err error
	ctx := Context{}

	if ctx.ObjFile, err = os.Create(fmt.Sprintf("%v.obj", object.GetName())); err != nil {
		return err
	}
	defer ctx.ObjFile.Close()

	if ctx.MtlFile, err = os.Create(fmt.Sprintf("%v.mtl", object.GetName())); err != nil {
		return err
	}
	defer ctx.MtlFile.Close()

	fmt.Fprintf(ctx.ObjFile, "mtllib %v.mtl\n", object.GetName())

	for _, model := range object.GetModels() {
		if err := ExportModel(&ctx, model); err != nil {
			return err
		}
	}
	return nil
}
Exemple #2
0
func Export(object export.Exportable) error {
	outFile := fmt.Sprintf("%v.dae", object.GetName())
	ctx := Context{
		Object:   xmlx.New(),
		imageIds: make(map[string]string),
	}

	ctx.Object.Root = xmlx.NewNode(xmlx.NT_ROOT)
	root := ctx.Object.Root

	collada := addChild(root, "COLLADA",
		Attribs{"xmlns": "http://www.collada.org/2005/11/COLLADASchema", "version": "1.4.1"}, "")

	asset := addChild(collada, "asset", nil, "")
	_ = addChild(asset, "unit", Attribs{"meter": "1", "name": "meter"}, "")
	_ = addChild(asset, "up_axis", nil, "Y_UP")

	ctx.libImages = addChild(collada, "library_images", nil, "")
	ctx.libMaterials = addChild(collada, "library_materials", nil, "")
	ctx.libEffects = addChild(collada, "library_effects", nil, "")
	ctx.libGeometries = addChild(collada, "library_geometries", nil, "")

	ctx.libScenes = addChild(collada, "library_visual_scenes", nil, "")
	ctx.scene = addChild(ctx.libScenes, "visual_scene", Attribs{"id": "Scene",
		"name": object.GetName()}, "")

	scenes := addChild(collada, "scene", nil, "")
	_ = addChild(scenes, "instance_visual_scene", Attribs{"url": "#Scene"}, "")

	for _, model := range object.GetModels() {
		var err error
		if err = ExportMaterials(&ctx, model); err != nil {
			return err
		}
		if err = ExportGeometries(&ctx, model); err != nil {
			return err
		}
	}

	if err := ctx.Object.SaveFile(outFile); err != nil {
		return err
	}

	return nil
}