Home Technical Talk

snapshotasmesh into new mesh

polycounter lvl 18
Offline / Send Message
dejawolf polycounter lvl 18
how do i paste a snapshotted mesh into a new object?

Replies

  • SyncViewS
    Offline / Send Message
    SyncViewS polycounter lvl 13
    Hi dejawolf,
    (assuming we're talking about 3ds Max) if you want to create a copy of an object mesh into a new object you can use two methods:
    • SnapShot <node> copy the exact node mesh representation with transforms and create a new Editable Mesh object
    • SnapShotAsMesh <node> copy the node mesh into a variable. To create a new Editable Mesh you need to create a Mesh() object and assign snapshot data to its .mesh property. It's not very clean since that data takes into account current source transform in current coordsys. Therefore if the source isn't in the origin, copied mesh data will result offset. That's why transforms in the following script are left at the end.
    If you need to make a copy of a node can try 'copy' or 'maxOps.CloneNodes'.
    (
        -- create a source Editable Poly
        polySphere = convertToPoly(sphere wireColor:red)
        
        -- copy Mesh with SnapShot
        meshSphere01 = snapShot polySphere
        meshSphere01.position = [0, 0, 0]
        meshSphere01.wireColor = green
    
        -- copy Mesh with SnapShotAsMesh
        meshData = snapShotAsMesh polySphere
        meshSphere02 = Mesh()
        meshSphere02.mesh = meshData
        meshSphere02.wireColor = blue
    
        -- set positions
        polySphere.position = [-35, 35, 0]
        meshSphere01.position = [0, 0, 0]
        meshSphere02.position = [35, -35, 0]
    )
    
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    ok, thanks :D
    i'm trying to fix up an old SMD exporter for 3ds max, and the UVs doesn't export properly, either with meshop.getmapvert, or gettvert. and it doesn't seem like its snapshotasmesh's fault.

    i've tried accessing the vertices with $ and rootnode.children[int]
    but both return a faulty value.
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    hmm, i think i'm onto something by using snapshotasmesh, and having a UVW unwrap modifier at the top, getmapvert returns correct coordinates.
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    I have some draft code somewhere that reads the UV data of snapshotasmesh :Mesh objects without any modifiers. It is a bit tricky but I got it working- will post it later here (when I am at my uni)
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    cool. i think its the skin modifier thats causing the problems.
    this is the script:

    http://www.dejawolf.com/mountblade/MBexporter.rar

    i thought it was going to be a simple fix.. instead its turned out to be a nightmare to fix.
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    can't imagine that - all what SnapShotAsMesh does is creating a world state snapshot as mesh : fully xResetted and ready to export without glitches or errors. I even used it for a vertex animation exported and created this way a snapshot every keyframe to export that particular keyframe state - so no problems with that.

    Or do you need to export specific vertex attributes that are connected with the skin modifier? because in that case of course the function might not copy everything over to that mesh.

    in that case maybe try
    obj = copy selection[1];
    convertToMesh obj;--merge all modifiers down to the bas object and convert it to a mesh
    
    and go on with that obj object till the end of your exported and then delete it
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    well, my main problem is this:

    the nice uvlayout on the right is substituted with the one on the left,
    and i just can't figure out why.
    UVproblems.jpg
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    here is the snippet:
    try(
    	if ( selection.count==1)then
    		theObj = selection[1];--selected object
    	else
    		theObj = pickObject();--pick a scene object with the mouse
    	if superclassof theObj == GeometryClass do --if really picked a valid geometry
    	(
    		print ("write file...");
    		tmesh = 	snapshotasmesh  theObj --snapshot the TriMesh of the object
    		num_verts =	tmesh.numverts; --get the number of vertices
    		num_faces = tmesh.numfaces;
    		num_tverts = tmesh.numTVerts;
    		
    		filename = writeBinary.txt.text;
    		tSize = texSize.text as Number;
    		
    		f = fopen filename "wb";
    		WriteShort f num_verts;		--vertices amaunt
    		WriteShort f num_faces;		--faces amount
    		WriteShort f num_tverts;	--uv vertices amount
    			
    		--WriteByte f texname.count;	--texname.count pathname character length
    		--WriteString f texname;		--map url
    		
    		-------------------
    		/*if (chkAlpha.state as string == "true")then
    			WriteByte f 1;
    		else
    			WriteByte f 0;
    		*/
    		-------------------
    		
    		if (tSize != undefined)then
    			WriteShort f tSize;
    		else(
    			tSize = 512;
    			WriteShort f tSize;
    			texSize.text = tSize as String;
    		)
    		-------------------		
    		
    		for v = 1 to num_verts do
    		(
    			p = getVert tmesh v;
    			x = p.x as Integer;
    			y = p.y as Integer;
    			z = p.z as Integer;
    			if (chkPivot.checked == true) then(
    				x= x-theObj.pos[1];
    				y= y-theObj.pos[2];
    				z= z-theObj.pos[3];
    			)
    			WriteShort f x;
    			WriteShort f y;
    			WriteShort f z;
    		)
    		
    		for v = 1 to num_faces do
    		(
    			p = getFace tmesh v;
    			x = p.x as Integer -1;
    			y = p.y as Integer -1;
    			z = p.z as Integer -1;
    			
    			WriteShort f x;
    			WriteShort f y;
    			WriteShort f z;
    		)
    		--texture vertices
    		for v = 1 to num_tverts do
    		(
    			p = GetTVert tmesh v;
    			x = (p.x)*tSize as Integer;
    			y = -((p.y)*tSize as Integer)+tSize;
    			WriteShort f x;--0 -> 512
    			WriteShort f y;
    		)
    		--texture face ID´s
    		for v = 1 to num_faces do
    		(
    			p = GetTVFace tmesh v;
    			x = p.x as Integer -1;
    			y = p.y as Integer -1;
    			z = p.z as Integer -1;
    			
    			WriteShort f x;
    			WriteShort f y;
    			WriteShort f z;
    		)
    		fclose f;
    		--delete tmesh;
    		/*		output		*/
    		lbl_output.text = "ok:t"+num_faces as String+" fcs, "+num_verts as String+" vrts, "+num_tverts as String+" texVrts";
    		
    	)
    )
    catch(
    	fclose f;
    	print("error writing");
    );
    
    it is from my curing colors project

    when looking at the script you provided - I am almost sure the error you have occoured because the object you selected is perhaps not a mesh? - the script (propably dated, back when editable Mesh was the deal) expects that you export with a mesh and not a editable poly, see:
    nude=$--first, store the editable mesh in the variable "nude". 
    
    faces = nude.numfaces --store the amount of triangles in nude in "faces"
    texname = "Textures/costumes1_skin.dds" --		texname = noode.material[1].name
    m = snapshotasmesh nude --store nude in an external memory location
    for i = 1 to faces do
    	(
     	format "%n" texname to:output_file
     	currface = getface m i 	--get the face definition, containing indices to the 3 vertices defining the face.
     	for num =1 to 3 do	   	--loops through the currently selected face's vertices
    		(
     			vrt=currface[num] --stores the current vertex index into vrt
    			
     			printvert m vrt skeen
     		)
    	
     	)
    
    format "endn" to:output_file
    close output_file
    

    so maybe change it to:
    nude=$--first, store the editable mesh in the variable "nude". 
    texname = "Textures/costumes1_skin.dds";
    m = snapshotasmesh nude --store nude in an external memory location
    faces = m.numfaces --store the amount of triangles in nude in "faces"
    for i = 1 to faces do
    	(
    
    so that it reads out the face count from the mesh isntead of the polygon which of course returns less faces as a mesh since in the mesh object each face is a triangle whereas in the editable poly engons can be a face e.g quads = 1 face.
  • dejawolf
    Offline / Send Message
    dejawolf polycounter lvl 18
    here's the template for the export:

    triangles
    Textures/costumes1_skin.dds
    parentbone posX | posY | posZ | normX | normY | normZ | U | V links bone ID weight
    12 -5.172950 |-0.455960 | 15.065980 | 0.019006 | -0.581393 | 0.813401 | 0.800656 | 0.580071 1 12 1.000000
    12 -5.658830 |-0.441940 | 15.089590 | -0.049136 | -0.443629 | 0.894863 | 0.827351 | 0.580041 1 12 1.000000
    12 -5.944380 |-0.749560 | 14.526430 | -0.150742 | -0.986792 | -0.059318 | 0.827312 | 0.593706 1 12 1.000000
    Textures/costumes1_skin.dds
    12 -5.172950 |-0.455960 | 15.065980 | 0.019006 | -0.581393 | 0.813401 | 0.800656 | 0.580071 1 12 1.000000
    12 -5.658830 |-0.441940 | 15.089590 | -0.049136 | -0.443629 | 0.894863 | 0.827351 | 0.580041 1 12 1.000000
    12 -5.944380 |-0.749560 | 14.526430 | -0.150742 | -0.986792 | -0.059318 | 0.827312 | 0.593706 1 12 1.000000
Sign In or Register to comment.