moethu / SketchUpNET

SketchUp C# API - A C++/CLI API Wrapper for the Trimble(R) SketchUp(R) C API
MIT License
108 stars 34 forks source link

Can this library be used in unity? #23

Closed 13704017891 closed 4 years ago

13704017891 commented 5 years ago

I wanted to compile this library into unity, but now I'm having trouble.ask for help

moethu commented 5 years ago

Hi, sure, you can just import SKP files using the library and translate to unity. Do you want to implement this yourself?

13704017891 commented 5 years ago

I'm doing it on my own, and I've seen some initial results, but now I have two problems. 1.Triangles vertex indices, whether both clockwise and counterclockwise?Because the unity will be removed, so counter-clockwise Triangles will not see, so how to solve 2.How to get map UV?

moethu commented 5 years ago
  1. I'm reading the order directly from sketchup, so however they are in skp - I will return the same order. If you want to make sure they are sorted clockwise you could walk through each triangle, get the centerpoint and make sure the vertices are sorted clockwise around it.
  2. I can look into the UV map and if I can export this.
moethu commented 5 years ago

24

13704017891 commented 5 years ago

That's how I get uv:SUTextureWriterGetFrontFaceUVCoords. But the UV does look like this (-11.4824665805793,-0.431334139639832). This doesn't look like a UV coordinate. It's the way I did it? Can I get your contact information? My problem is urgent?

moethu commented 5 years ago

Those are UV Coordinates, see description of the method: Given an array of vertex positions, retrieves the corresponding UV coordinates of the front face texture of a face object that has been loaded into the given texture writer object. https://en.wikipedia.org/wiki/UV_mapping What exactly are you looking for?

penguin-ku commented 5 years ago

C++/CLI not supported by unity causing to mono. P/invoke is the only way.

moethu commented 4 years ago

@13704017891 any update on this? otherwise I will close this.

thinklikeanarchitect commented 4 years ago

Hi,

I am just trying to import a Sketchup model at runtime in Unity3D. Could you please help me? I have copied the dll's and compiled them and then tried to write a basic script to call the model but couldn't succeed. Any help will be very helpful for me.

This is my script:

using System; using UnityEngine; using System.Runtime.InteropServices; public class API : MonoBehaviour { public string modelFilePath; const string LIB = "SketchUpAPI";

    [DllImport(LIB,EntryPoint = "SUInitialize")]
static extern void SUInitialize();

[DllImport(LIB, EntryPoint = "SUTerminate")]
public static extern void SUTerminate();

[DllImport(LIB, EntryPoint = "SUModelCreateFromFile")]
public static extern  SUResult SUModelCreateFromFile(ref IntPtr model,[MarshalAs(UnmanagedType.LPUTF8Str)]string file_path);

public void Start()
{
    SUInitialize();

    var modelPtr = IntPtr.Zero;

    SUModelCreateFromFile(ref modelPtr, modelFilePath);

    SUTerminate();
}

}

moethu commented 4 years ago

can you share your error you are experiencing? sure the Dll Import Path is correct?

thinklikeanarchitect commented 4 years ago

The error was like SUResult could not be found, are you missing an assembly reference.

Is there a basic workflow or script to import Sketchup Model into Unity at runtime? Thank you for your fast response and support.

moethu commented 4 years ago

@thinklikeanarchitect sorry for getting back so late about this. can you describe your setup in more detail please? OS / versions, etc?

thinklikeanarchitect commented 4 years ago

WinOS-desktop platform, using Unity 2019.2.9f1. I am just trying to import skp model to Unity at runtime, that's it.

moethu commented 4 years ago

but from your code it doesn't look like you are using my library. in your case you'll have to import SUResult as well, because it's going to be a response.