It is currently Sat Aug 22, 2020 4:54 am


All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: try 2
PostPosted: Mon Dec 30, 2013 2:13 am 

Joined: Fri Dec 13, 2013 5:00 am
Posts: 11
I thought it would be much easier to just add voxels at another objects position.

I tried this :
Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

using Cubiquity;

public class VoxelEdit : MonoBehaviour
{
   public GameObject otherGameObject;
   private ColoredCubesVolume coloredCubesVolume;
   private float targetx;
   private float targety;
   private float targetz;


   // Use this for initialization
   void Start()
   {
      // We'll store a reference to the colored cubes volume so we can interact with it later.
      coloredCubesVolume = gameObject.GetComponent<ColoredCubesVolume>();
      if(coloredCubesVolume == null)
      {
         Debug.LogError("This 'VoxelEdit' script should be attached to a game object with a ColoredCubesVolume component");
      }
   }
   
   // Update is called once per frame
   void Update()
   {
      targetx = (int) otherGameObject.transform.position.x;
      targety = (int) otherGameObject.transform.position.y;
      targetz = (int) otherGameObject.transform.position.z;
      // Bail out if we're not attached to a terrain.
      if(coloredCubesVolume == null)
      {
         return;
      }
      
   

   if(Input.GetMouseButton(1))
         coloredCubesVolume.data.SetVoxel(targetx, targety, targetz, new QuantizedColor(0,0,0,255));
   

   }



   
}


What i am trying to do is just add a single voxel at the OtherGameObject , X Y and Z.

First Cubiquity complains that they are integer values, then when I change to float, it still complains.

Could you please make an example of how to do this?
Please just a working example. One I can run in unity. I am sure other users will appreciate this too.

Thanks in advance.

EDIT sorry this was to be a reply to the other thread. lol, Time to give up and get some sleep.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: try 2
PostPosted: Mon Dec 30, 2013 9:28 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
It sounds ok in principle. Is the problem that it won't compile, won't run, nothing happens, it crashes, etc?

Writing QuantizedColor(0,0,0,255) should be fine, but you could also try QuantizedColor(255,255,255,255) in case there is a bug somewhere...


Top
Offline Profile  
Reply with quote  
 Post subject: Re: try 2
PostPosted: Mon Dec 30, 2013 4:45 pm 

Joined: Fri Dec 13, 2013 5:00 am
Posts: 11
David Williams wrote:
It sounds ok in principle. Is the problem that it won't compile, won't run, nothing happens, it crashes, etc?

Writing QuantizedColor(0,0,0,255) should be fine, but you could also try QuantizedColor(255,255,255,255) in case there is a bug somewhere...


Hi, the game wont start, it complains about my floats, and then it complains about my integers when I change them from float.

The problem is that I have no working example of how to do this I am afraid. I am not adept at C# yet. My cousin gave me a crash course but I still think in Java for some reason.

I just posted the code in hopes that you guys would see what I am trying to accomplish. Add voxel to another objects X,Y, and Z. My English is not so great.

I can think of quite a few different scenarios where this would be useful. A script we could see working would be nice.

I hope this does not seem like I am trying to con people into making code for me. I can pay for the time.
If someone in the community would like to make some money, I can pay you for a working example too.

* add voxel at a cube’s position
* remove a voxel from a cube position
* re-color existing voxel at cube’s position.

Working C# or Java scripts only please. I will make the scripts free to other users.

I have a feeling I have confused everyone. My English is really bad.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: try 2
PostPosted: Mon Dec 30, 2013 7:17 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Don't worry, your English is fine ;-)

I quickly tried your code and it is a compile error caused by mismatched types. I don't know JavaScript but I think it doesn't have types in the same way as C#, so this can be confusing. You can fix it by changing the type of the target variables to 'int'. Like so:

Code:
private int targetx;
private int targety;
private int targetz;


It should then compile, but I haven't tested if it works.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: try 2
PostPosted: Mon Dec 30, 2013 7:51 pm 

Joined: Fri Dec 13, 2013 5:00 am
Posts: 11
OMG! thank you so much!

I will not have another question ever! it works perfectly!

I have tears in my eyes I am so proud. I was so very close!!

Thank you very much Mr. Williams! You have helped make a dream come true today.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: try 2
PostPosted: Mon Dec 30, 2013 9:33 pm 

Joined: Fri Dec 13, 2013 5:00 am
Posts: 11
OK, as promised here is the complete script for others to learn, hack and slash:

Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

using Cubiquity;

public class VoxelEdit : MonoBehaviour
{
   public GameObject otherGameObject;
   private ColoredCubesVolume coloredCubesVolume;
   private int targetx;
   private int targety;
   private int targetz;


   // Use this for initialization
   void Start()
   {
      // We'll store a reference to the colored cubes volume so we can interact with it later.
      coloredCubesVolume = gameObject.GetComponent<ColoredCubesVolume>();
      if(coloredCubesVolume == null)
      {
         Debug.LogError("This 'VoxelEdit' script should be attached to a game object with a ColoredCubesVolume component");
      }
   }
   
   // Update is called once per frame
   void Update()
   {
      targetx = (int) otherGameObject.transform.position.x;
      targety = (int) otherGameObject.transform.position.y;
      targetz = (int) otherGameObject.transform.position.z;
      // Bail out if we're not attached to a terrain.
      if(coloredCubesVolume == null)
      {
         return;
      }
      
   

   if(Input.GetMouseButton(1))
         coloredCubesVolume.data.SetVoxel(targetx, targety, targetz, new QuantizedColor(0,0,0,255));
   

   }



   
}



Attach it to the ColoredCubesVolume game object.
Then you can add your "cursor" object to the script in the inspector (put where says "otherGameObject").

The "cursor" object is where you want the voxels to draw, it can be a cube,empty, whatever.

I just parented a cube to a default unity FirstPersonController object. Then when player presses mouse button 2 (right click) a black voxel is added.

Hope this helps some one! :)


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net